001: package org.enhydra.shark.webclient.business;
002:
003: import java.util.Properties;
004:
005: import org.enhydra.shark.api.client.wfmc.wapi.WAPI;
006: import org.enhydra.shark.api.client.wfmc.wapi.WMFilter;
007: import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
008: import org.enhydra.shark.api.client.xpil.XPILHandler;
009: import org.enhydra.shark.api.common.ProcessFilterBuilder;
010: import org.enhydra.shark.client.utilities.SharkInterfaceWrapper;
011: import org.enhydra.shark.utilities.MiscUtilities;
012: import org.enhydra.shark.webclient.spec.utils.ParamConsts;
013: import org.w3c.dom.Node;
014:
015: import com.lutris.util.Config;
016:
017: public class XMLProcessMonitorBuilder extends XMLBuilderImpl {
018:
019: public XMLProcessMonitorBuilder(String username, Config config,
020: String startElement, String sortCriterion, String sortAsc) {
021:
022: this .username = username;
023: this .config = config;
024: this .from_element = startElement;
025: this .sortCriterion = sortCriterion;
026: this .sortAsc = sortAsc;
027:
028: }
029:
030: protected Node fillXMLElements() throws Exception {
031: WAPI wapi = SharkInterfaceWrapper.getShark()
032: .getWAPIConnection();
033: WMSessionHandle shandle = SharkInterfaceWrapper
034: .makeWAPIConnection(wapi, username, null);
035:
036: int itemsPerPage = config.getInt("SharkWebClient."
037: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR
038: + ".max.rows.per.page", 5);
039:
040: int startAt = Integer
041: .parseInt(from_element != null ? from_element : "0");
042:
043: ProcessFilterBuilder fb = SharkInterfaceWrapper.getShark()
044: .getProcessFilterBuilder();
045: WMFilter filter = fb.createEmptyFilter(shandle);
046:
047: int hm = wapi.listProcessInstances(shandle, filter, true)
048: .getCount();
049: if (startAt > hm) {
050: startAt = (hm / itemsPerPage) * itemsPerPage;
051: from_element = Integer.toString(startAt);
052: } else if (startAt == hm && hm > 0) {
053: startAt = startAt - itemsPerPage;
054: from_element = Integer.toString(startAt);
055: }
056: from_element = Integer.toString(startAt);
057: to_element = Integer.toString(startAt + itemsPerPage - 1);
058: total_number = Integer.toString(hm);
059: filter = fb.setLimit(shandle, filter, itemsPerPage);
060: filter = fb.setStartPosition(shandle, filter, startAt);
061:
062: if (this .sortCriterion == null || this .sortCriterion.equals("")) { // search as
063: // declared in
064: // config file
065: String orderByList = config.getString("SharkWebClient."
066: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR
067: + ".fill.xpil.orderbylist", "");
068: String[] obstrs = MiscUtilities.tokenize(orderByList, ";");
069: if (obstrs.length > 0) {
070: for (int i = 0; i < obstrs.length; i++) {
071: String obs = obstrs[i];
072: String[] sortinfo = MiscUtilities
073: .tokenize(obs, ",");
074: if (sortinfo != null && sortinfo.length == 2) {
075: String orderBy = sortinfo[0];
076: boolean asc = new Boolean(sortinfo[1])
077: .booleanValue();
078: if (orderBy.equals("state")) {
079: fb.setOrderByState(shandle, filter, asc);
080: } else if (orderBy.equals("createdtime")) {
081: fb.setOrderByCreatedTime(shandle, filter,
082: asc);
083: } else if (orderBy.equals("id")) {
084: fb.setOrderById(shandle, filter, asc);
085: } else if (orderBy.equals("priority")) {
086: fb.setOrderByPriority(shandle, filter, asc);
087: } else if (orderBy.equals("requester")) {
088: fb.setOrderByResourceRequesterId(shandle,
089: filter, asc);
090: } else if (orderBy.equals("name")) {
091: fb.setOrderByName(shandle, filter, asc);
092: }
093: }
094: }
095: }
096: }
097: // user has chosen search criterion
098: // can search by state, createdTime, priority, requester, name
099: else {
100: if (this .sortCriterion.equalsIgnoreCase("state")) {
101: fb.setOrderByState(shandle, filter, Boolean.valueOf(
102: this .sortAsc).booleanValue());
103: } else if (this .sortCriterion
104: .equalsIgnoreCase("createdtime")) {
105: fb.setOrderByCreatedTime(shandle, filter, Boolean
106: .valueOf(this .sortAsc).booleanValue());
107: } else if (this .sortCriterion.equalsIgnoreCase("priority")) {
108: fb.setOrderByPriority(shandle, filter, Boolean.valueOf(
109: this .sortAsc).booleanValue());
110: } else if (this .sortCriterion.equalsIgnoreCase("requester")) {
111: fb.setOrderByResourceRequesterId(shandle, filter,
112: Boolean.valueOf(this .sortAsc).booleanValue());
113: } else if (this .sortCriterion.equalsIgnoreCase("name")) {
114: fb.setOrderByName(shandle, filter, Boolean.valueOf(
115: this .sortAsc).booleanValue());
116: } else if (this .sortCriterion.equalsIgnoreCase("id")) {
117: fb.setOrderById(shandle, filter, Boolean.valueOf(
118: this .sortAsc).booleanValue());
119: }
120: }
121:
122: Properties props = new Properties();
123:
124: String prop = config.getString("SharkWebClient."
125: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
126: + XPILHandler.FILL_PACKAGE_EXT_ATTRIBS, "false");
127: props.setProperty(XPILHandler.FILL_PACKAGE_EXT_ATTRIBS, prop);
128: prop = config
129: .getString("SharkWebClient."
130: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR
131: + "."
132: + XPILHandler.FILL_PROCESS_FACTORY_EXT_ATTRIBS,
133: "false");
134: props.setProperty(XPILHandler.FILL_PROCESS_FACTORY_EXT_ATTRIBS,
135: prop);
136: prop = config.getString("SharkWebClient."
137: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
138: + XPILHandler.FILL_PROCESS_EXT_ATTRIBS, "false");
139: props.setProperty(XPILHandler.FILL_PROCESS_EXT_ATTRIBS, prop);
140: prop = config.getString("SharkWebClient."
141: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
142: + XPILHandler.FILL_ACTIVITY_EXT_ATTRIBS, "false");
143: props.setProperty(XPILHandler.FILL_ACTIVITY_EXT_ATTRIBS, prop);
144: config.getString("SharkWebClient."
145: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
146: + XPILHandler.FILL_VARIABLE_EXT_ATTRIBS, "false");
147: props.setProperty(XPILHandler.FILL_VARIABLE_EXT_ATTRIBS, prop);
148: prop = config.getString("SharkWebClient."
149: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
150: + XPILHandler.FILL_PROCESS_VARIABLES, "false");
151: props.setProperty(XPILHandler.FILL_PROCESS_VARIABLES, prop);
152: prop = config.getString("SharkWebClient."
153: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
154: + XPILHandler.FILL_ALL_ACTIVITIES, "false");
155: props.setProperty(XPILHandler.FILL_ALL_ACTIVITIES, prop);
156: prop = config.getString("SharkWebClient."
157: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
158: + XPILHandler.FILL_RUNNING_ACTIVITIES, "false");
159: props.setProperty(XPILHandler.FILL_RUNNING_ACTIVITIES, prop);
160: prop = config.getString("SharkWebClient."
161: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
162: + XPILHandler.FILL_ACTIVITY_VARIABLES, "false");
163: props.setProperty(XPILHandler.FILL_ACTIVITY_VARIABLES, prop);
164: prop = config.getString("SharkWebClient."
165: + ParamConsts.PROPERTY_PREFIX_PROCESSMONITOR + "."
166: + XPILHandler.FILL_ACTIVITY_ASSIGNMENTS, "false");
167: props.setProperty(XPILHandler.FILL_ACTIVITY_ASSIGNMENTS, prop);
168:
169: props.setProperty(XPILHandler.FILL_PROCESS_FACTORIES, "false");
170:
171: String nstr = SharkInterfaceWrapper
172: .getShark()
173: .getXPILHandler()
174: .getProcessInstanceList(
175: shandle,
176: username,
177: filter,
178: MiscUtilities
179: .convertPropertiesToNameValueArray(props));
180: wapi.disconnect(shandle);
181: return MiscUtilities.convertStringToNode(nstr);
182: }
183:
184: }
|