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