1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.dom;
9
10 import java.util.Date;
11 import java.util.Iterator;
12 import java.util.LinkedList;
13 import java.util.List;
14 import java.util.TreeMap;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.dom4j.Document;
19 import org.dom4j.DocumentHelper;
20 import org.dom4j.Element;
21
22 import com.buckosoft.PicMan.business.PicManFacade;
23 import com.buckosoft.PicMan.domain.Chain;
24 import com.buckosoft.PicMan.domain.ContactParams;
25
26
27
28
29
30
31 public class EngineReportDom {
32 private final static boolean DEBUG = false;
33 protected final static Log logger = LogFactory.getLog(EngineReportDom.class);
34
35
36
37
38 static public Document createDocument(PicManFacade pmf) {
39 Document document = DocumentHelper.createDocument();
40
41 Element root = document.addElement("EngineReport");
42 root.addElement("date").addText(new Date().toString());
43
44 root.addElement("engineRunningText").setText(pmf.engineRunningShortStatus());
45
46 TreeMap<String, SetTodoReport> tm = condenseToDoList(pmf);
47 List<String> otherJobsList = pmf.getBatchManager().getOtherJobsQueued();
48 List<String> mosaicJobsList = pmf.getMosaicMan().getMosaicQueueListString();
49 int jobsToDo = tm.size() + otherJobsList.size() + mosaicJobsList.size();
50 root.addElement("jobsToDo").addText("" + jobsToDo);
51
52 int lastColor = 0;
53 if (!otherJobsList.isEmpty()) {
54 Element otherJobs = root.addElement("OtherJobs");
55 for (String oj : otherJobsList)
56 otherJobs.addElement("oj").addText(oj);
57 }
58 if (!tm.isEmpty()) {
59 Element contactJobs = root.addElement("ContactJobs");
60 for (SetTodoReport str : tm.values()) {
61 Element c = contactJobs.addElement("C");
62 c.addElement("name").addText(str.getSetName());
63 c.addElement("uid").addText(str.getUid());
64 c.addElement("chainShortName").addText(str.getChainShortName());
65 lastColor = str.getBackColor();
66 c.addElement("color").addText("" + lastColor);
67 if (!str.getItems().isEmpty()) {
68 Element items = c.addElement("items");
69 for (Integer i : str.getItems())
70 items.addElement("i").addText("" + i);
71 }
72 }
73 }
74 if (!mosaicJobsList.isEmpty()) {
75 Element mosaicJobs = root.addElement("MosaicJobs");
76 for (String mj : mosaicJobsList) {
77 lastColor++;
78 if (lastColor == 2)
79 lastColor = 0;
80 Element m = mosaicJobs.addElement("m");
81 m.addElement("name").addText(mj);
82 m.addElement("color").addText("" + lastColor);
83 }
84 }
85 return(document);
86 }
87
88 private static TreeMap<String, SetTodoReport> condenseToDoList(PicManFacade pmf) {
89 TreeMap<String, SetTodoReport> tm = new TreeMap<String, SetTodoReport>();
90 LinkedList<ContactParams> contactParamsList = pmf.getBatchManager().getContactManager().determineContactsToMake();
91 ContactParams currentContactParams = pmf.getBatchManager().getContactManager().getContactParamsRunning();
92 Chain chain = null;
93 Iterator<ContactParams> it = contactParamsList.iterator();
94 while (it.hasNext()) {
95 ContactParams cp = it.next();
96 if (DEBUG)
97 logger.info("cToDo: cp cid=" + cp.getCid() + " ss= " + cp.getSetName() + "_" + cp.getSize() + " cn=" + cp.getContactNumber());
98 if (chain == null || cp.getCid() != chain.getCid()) {
99 chain = pmf.getDB().getChain(cp.getCid());
100 if (DEBUG)
101 logger.info("cToDo: got chain:" + chain.getShortName());
102 }
103 String uid = chain.getCid() + cp.getUid();
104 SetTodoReport str = (SetTodoReport)tm.get(uid);
105 if (str == null) {
106 str = new SetTodoReport();
107 str.setUid(cp.getUid());
108 str.setSetName(cp.getSetName());
109 str.setChainShortName(chain.getShortName());
110 str.setCid(chain.getCid());
111 str.setSize(cp.getSize());
112 tm.put(uid, str);
113 if (DEBUG)
114 logger.info("cToDo: putting '" + uid + "' - '" + str + "'");
115 }
116 str.addItem(new Integer(cp.getContactNumber()));
117 }
118 int back = 0;
119 String currentSetName = "";
120 for (SetTodoReport str : tm.values()) {
121 if (!currentSetName.equals(str.getSetName())) {
122 currentSetName = str.getSetName();
123 back ^= 1;
124 }
125 if (currentContactParams != null
126 && currentContactParams.getSetName().equals(str.getSetName())
127 && currentContactParams.getSize() == str.getSize()
128 && currentContactParams.getCid() == str.getCid())
129 str.setBackColor(2);
130 else
131 str.setBackColor(back);
132 }
133 return(tm);
134 }
135
136
137
138
139 private static class SetTodoReport {
140 private String uid;
141 private String setName;
142 private int size;
143 private String chainShortName;
144 private int cid;
145 private LinkedList<Integer> items = new LinkedList<Integer>();
146 private int backColor;
147
148
149
150
151 public String getUid() {
152 return uid;
153 }
154
155
156
157 public void setUid(String uid) {
158 this.uid = uid;
159 }
160 public String getSetName() {
161 return setName;
162 }
163 public void setSetName(String setName) {
164 this.setName = setName;
165 }
166 public int getSize() {
167 return size;
168 }
169 public void setSize(int size) {
170 this.size = size;
171 }
172 public String getChainShortName() {
173 return chainShortName;
174 }
175 public void setChainShortName(String chainShortName) {
176 this.chainShortName = chainShortName;
177 }
178 public int getCid() {
179 return cid;
180 }
181 public void setCid(int cid) {
182 this.cid = cid;
183 }
184 public LinkedList<Integer> getItems() {
185 return items;
186 }
187
188
189
190 public void addItem(Integer i) {
191 this.items.add(i);
192 }
193
194
195
196 public int getBackColor() {
197 return backColor;
198 }
199
200
201
202 public void setBackColor(int backColor) {
203 this.backColor = backColor;
204 }
205
206 }
207 }