1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.templates;
22
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import org.apache.log4j.Logger;
28
29 import com.ebay.carad.os.vitalsigns.DashboardReport;
30 import com.ebay.carad.os.vitalsigns.IDashboardReportContainer;
31
32 /***
33 * <p>
34 * Provides a way to generate templatized sets of reports based on the output of
35 * a query. This is useful if you want numerous dashboard reports that are
36 * reporting against a possibly changing set of values in the database.
37 * </p>
38 *
39 * <p>
40 * Reports are created at load time, and only re-loaded upon dashboard restart.
41 * </p>
42 *
43 * @author Jeremy Kraybill
44 * @author Jeremy Thomerson
45 * @version $Id$
46 */
47 public class DashboardReportTemplate implements IDashboardReportContainer, Comparable {
48
49 private static final Logger LOGGER = Logger.getLogger(DashboardReportTemplate.class);
50
51 private IDashboardReportContainer mContainer = null;
52 private String mGroupName;
53 private IMultiTemplatizableProvider mDataProvider = null;
54
55 /*** List of generated reports. */
56 private List mReports = null;
57
58 /***
59 * IoC method to allow a report container to be passed in. Note that all
60 * children DashboardReports must implement <code>ITemplatizable</code>
61 *
62 * @param inContainer the container to use as a template
63 */
64 public void setTemplateContainer(IDashboardReportContainer inContainer) {
65 mContainer = inContainer;
66 }
67
68 /***
69 * Generates a set of report objects based on the data provided by the
70 * IMultiTemplatizableProvider and the contained template reports.
71 */
72 public List getReports() {
73 createReports();
74 return mReports;
75 }
76
77 /***
78 * IoC method for initialization; defines where our list of lists comes
79 * from.
80 *
81 * @param provider
82 * the provider of our template data
83 */
84 public void setDataProvider(IMultiTemplatizableProvider provider) {
85 mDataProvider = provider;
86 }
87
88 /***
89 * Generates the list of templatized reports, if they have not been generated yet.
90 */
91 private void createReports() {
92 if (mReports == null) {
93 mReports = new ArrayList(10);
94
95 List data = mDataProvider.getParameterList();
96
97 if (data.size() == 0) {
98 LOGGER.warn("Template generation provider returned zero results.");
99 return;
100 }
101
102 for (Iterator it = mContainer.getReports().iterator(); it.hasNext();) {
103
104
105 DashboardReport template = (DashboardReport) it.next();
106 for (Iterator it2 = data.iterator(); it2.hasNext();) {
107
108 DashboardReport newReport = null;
109 newReport = new DashboardReport(template);
110 newReport.templatize(((List) it2.next()).toArray());
111 mReports.add(newReport);
112 }
113 }
114 }
115 }
116
117 /***
118 * Returns the sort order of the container.
119 */
120 public int getSortOrder() {
121 if (mContainer.getReports().size() > 0) {
122 return mContainer.getSortOrder();
123 }
124
125
126 return 0;
127 }
128
129 public int compareTo(Object obj) {
130 IDashboardReportContainer rc = (IDashboardReportContainer) obj;
131 return getSortOrder() - rc.getSortOrder();
132 }
133
134 /***
135 * @return Returns the groupName.
136 */
137 public String getGroupName() {
138 return mGroupName;
139 }
140
141 /***
142 * @param groupName The groupName to set.
143 */
144 public void setGroupName(String groupName) {
145 mGroupName = groupName;
146 }
147 }