List of usage examples for org.jdom2 Element getChildText
public String getChildText(final String cname)
From source file:org.yawlfoundation.yawl.resourcing.rsInterface.ResourceMarshaller.java
License:Open Source License
public SpecificationData unmarshallSpecificationData(String xml) { SpecificationData result = null;/*w w w .j av a 2s . c om*/ YSpecificationID specID = null; if (xml != null) { Element specElement = JDOMUtil.stringToElement(xml); String id = specElement.getChildText("id"); String uri = specElement.getChildText("uri"); String name = specElement.getChildText("name"); String doco = specElement.getChildText("documentation"); String status = specElement.getChildText("status"); String version = specElement.getChildText("version"); String rootNetID = specElement.getChildText("rootNetID"); String specVersion = specElement.getChildText("specversion"); String dataGateway = specElement.getChildText("externalDataGateway"); if (id != null && status != null) { specID = new YSpecificationID(id, specVersion, uri); YSchemaVersion schemaVersion = YSchemaVersion.fromString(version); result = new SpecificationData(specID, name, doco, status, schemaVersion); result.setRootNetID(rootNetID); result.setSpecVersion(specVersion); result.setExternalDataGateway(dataGateway); Element inputParams = specElement.getChild("params"); if (inputParams != null) { for (Element paramElem : inputParams.getChildren()) { YParameter param = new YParameter(null, YParameter._INPUT_PARAM_TYPE); YDecompositionParser.parseParameter(paramElem, param, null, false); result.addInputParam(param); } } result.setMetaTitle(specElement.getChildText("metaTitle")); Element authors = specElement.getChild("authors"); if (authors != null) { for (Element authorElem : authors.getChildren()) { result.addAuthor(authorElem.getText()); } } Element specAsXML = specElement.getChild("specAsXML"); if (specAsXML != null) { List<Element> specSet = specAsXML.getChildren(); if (!specSet.isEmpty()) { result.setSpecAsXML(SPEC_HEADER + JDOMUtil.elementToString(specSet.get(0))); } } } } return result; }
From source file:org.yawlfoundation.yawl.resourcing.WorkQueue.java
License:Open Source License
public void fromXML(Element element) { if (element != null) { _queueType = new Integer(element.getChildText("queuetype")); _ownerID = element.getChildText("ownerid"); Element items = element.getChild("workitems"); if (items != null) { for (Element e : items.getChildren()) { WorkItemRecord wir = Marshaller.unmarshalWorkItem(e); _workitems.put(wir.getID(), wir); }//from w ww . j a v a 2s . c om } } }
From source file:org.yawlfoundation.yawl.riskPrediction.OperationalSupport.OperationalSupportServlet.java
License:Open Source License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String xml = request.getParameter("request"); // System.out.println(xml); // String xml = "<request><type>routing</type><workItems><workItem><caseID>384</caseID><taskID>Open_Claim_3</taskID><specificationURI>InsuranceClaim</specificationURI></workItem></workItems><resource>PA-b39db4e2-2e39-4fef-ab78-810d58c12699</resource><data /></request>"; // String xml = "<request><type>execution</type><workItems><workItem><caseID>384</caseID><taskID>Open_Claim_3</taskID><specificationURI>InsuranceClaim</specificationURI></workItem></workItems><resource>PA-c24ff639-2f45-4ffe-b9c5-ffebf11f7087</resource><data><Open_Claim_3><Customer>Customer25</Customer><ClaimType>Comprehensive</ClaimType><DamageType>Windscreen</DamageType><Amount>5000</Amount></Open_Claim_3></data></request>"; // String xml = "<request><type>execution</type><workItems><workItem><caseID>392</caseID><taskID>Open_Claim_3</taskID><specificationURI>InsuranceClaim</specificationURI></workItem></workItems><resource>PA-84b0d53d-5a1d-41b3-9721-b7a05014be62</resource><data><Open_Claim_3><Customer>Customer1</Customer><ClaimType>Compulsory</ClaimType><DamageType>Fire</DamageType><Amount>100</Amount></Open_Claim_3></data></request>"; Element e = JDOMUtil.stringToElement(xml); boolean execution = ("execution".equals(e.getChildText("type"))) ? true : false; Element workItems = e.getChild("workItems"); LinkedList<WorkItemRecord> wks = new LinkedList<WorkItemRecord>(); for (Element workItem : (List<Element>) workItems.getChildren()) { String caseID = workItem.getChildText("caseID"); String taskID = workItem.getChildText("taskID"); String specURI = workItem.getChildText("specificationURI"); wks.add(new WorkItemRecord(caseID, taskID, specURI, null, null)); }/* w ww. ja v a 2 s. c o m*/ String resource = e.getChildText("resource"); String data = null; Map<WorkItemRecord, Long> res = null; if (execution) { data = JDOMUtil.elementToString(e.getChild("data")); res = OperationalSupportService.getInstance().suggestExecutionDecisionPoints(wks.getFirst(), resource, data); } else { InterfaceManager im = new InterfaceManager(InterfaceManager.YAWL, null); resource = ((YAWL_Role) im.getRoleLayer()).getParticipantNameFromUserID(resource); res = OperationalSupportService.getInstance().suggestDecisionPoints(wks.toArray(new WorkItemRecord[0]), resource, System.currentTimeMillis()); } StringBuilder sb = new StringBuilder(); sb.append("<responce>"); sb.append("<coupleWorkItemsPredictions>"); WorkItemRecord key = null; for (Entry<WorkItemRecord, Long> entry : res.entrySet()) { key = entry.getKey(); sb.append("<coupleWorkItemPrediction>"); sb.append("<workItem>"); sb.append("<caseID>" + key.getRootCaseID() + "</caseID>"); sb.append("<taskID>" + key.getTaskID() + "</taskID>"); sb.append("<specificationURI>" + key.getSpecURI() + "</specificationURI>"); sb.append("</workItem>"); sb.append("<prediction>"); sb.append(entry.getValue()); sb.append("</prediction>"); sb.append("</coupleWorkItemPrediction>"); } sb.append("</coupleWorkItemsPredictions>"); sb.append("</responce>"); System.out.println(sb.toString()); response.setContentType("text/xml"); OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); osw.write(sb.toString()); osw.flush(); osw.close(); // String xml = request.getParameter("request"); //// String xml = "<request><type>execution</type><workItems><workItem><caseID>375</caseID><taskID>Arrange_Pickup_Appointment_454</taskID><specificationURI>Carrier_Appointment</specificationURI></workItem></workItems><resource>PA-0b7f1d4c-f3b2-4fd4-8e77-c33f65bb2821</resource><data><Arrange_Pickup_Appointment><PickupInstructions><ShipmentNumber>2</ShipmentNumber><PickupDate>2013-01-07</PickupDate><PickupInstructions /><PickupSpot /></PickupInstructions></Arrange_Pickup_Appointment></data></request>"; // // Element e = JDOMUtil.stringToElement(xml); // // boolean execution = ("execution".equals(e.getChildText("type")))?true:false; // // Element workItems = e.getChild("workItems"); // LinkedList<WorkItemRecord> wks = new LinkedList<WorkItemRecord>(); // // for(Element workItem : (List<Element>) workItems.getChildren()) { // // String caseID = workItem.getChildText("caseID"); // String taskID = workItem.getChildText("taskID"); // String specURI = workItem.getChildText("specificationURI"); // // wks.add(new WorkItemRecord(caseID, taskID, specURI, null, null)); // // } // // String resource = e.getChildText("resource"); // // String data = null; // Map<WorkItemRecord, Long> res = new HashMap<WorkItemRecord, Long>(); // // for(WorkItemRecord wir : wks) { // res.put(wir, 20L); // } // // StringBuilder sb = new StringBuilder(); // // sb.append("<responce>"); // sb.append("<coupleWorkItemsPredictions>"); // // WorkItemRecord key = null; // for(Entry<WorkItemRecord, Long> entry : res.entrySet()) { // // key = entry.getKey(); // // sb.append("<coupleWorkItemPrediction>"); // // sb.append("<workItem>"); // sb.append("<caseID>"+key.getCaseID()+"</caseID>"); // sb.append("<taskID>"+key.getTaskID()+"</taskID>"); // sb.append("<specificationURI>"+key.getSpecURI()+"</specificationURI>"); // sb.append("</workItem>"); // // sb.append("<prediction>"); // double pred = (entry.getValue()); // sb.append(pred/20); // sb.append("</prediction>"); // // sb.append("</coupleWorkItemPrediction>"); // } // // sb.append("</coupleWorkItemsPredictions>"); // sb.append("</responce>"); // // System.out.println(sb.toString()); // response.setContentType("text/xml"); // OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); // // osw.write(sb.toString()); // osw.flush(); // osw.close(); }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
private void outFormPriv() throws Exception { String reschedulingKey = request.getParameter("reschedulingKey"); source = request.getParameter("source"); String itemid = request.getParameter("workitem"); String handle = request.getParameter("handle"); String participantid = request.getParameter("participantid"); try {/* ww w .j av a 2 s . c om*/ Participant participant = rs.getParticipant(participantid); userName = participant.getFullName(); } catch (Exception e) { _log.error("Cannot get username for participant id: " + participantid, e); } if (!rs.isValidUserSession(handle)) { _log.warn("User handle is invalid: " + handle + ", redirecting to start page..."); redirect(source.substring(0, source.lastIndexOf("/"))); } wirElement = Utils.string2Element(rs.getWorkItem(itemid, handle)); String caseId = Utils.extractCaseId(wirElement.getChildText("caseid")); String taskId = wirElement.getChildText("taskid"); String taskName = taskId.substring(0, taskId.lastIndexOf("_")); List<Element> children = wirElement.getChild("updateddata").getChildren(); Element task = (children.isEmpty() ? null : children.get(0)); if (task == null) { children = wirElement.getChild("data").getChildren(); task = (children.isEmpty() ? null : children.get(0)); } boolean complete = request.getParameter("Complete") != null; boolean completeForce = request.getParameter("CompleteForce") != null && !request.getParameter("CompleteForce").isEmpty(); boolean save = reschedulingKey != null || request.getParameter("Save") != null; boolean confirmReservations = request.getParameter("ConfirmReservations") != null; boolean cancel = request.getParameter("Cancel") != null; boolean language = request.getParameter(LANGUAGE_ATTRIBUTE_NAME) != null && !request.getParameter(LANGUAGE_ATTRIBUTE_NAME).isEmpty(); isShortForm = Boolean.parseBoolean(task.getChildText("shortForm")); canConfirmReservations = Boolean.parseBoolean(task.getChildText("canConfirmReservations")); _log.debug("cancel,save,confirmReservations,complete,language,isShortForm,canConfirmReservations=" + cancel + "," + save + "," + confirmReservations + "," + complete + "," + language + "," + isShortForm + "," + canConfirmReservations); if (cancel) { redirect(); } else if (completeForce) { completeWorkitem(taskName, itemid, handle); } else if (complete || save || language || confirmReservations) { Case cas = ss.loadCase(caseId); Document rup = cas.getRUP(); Document rupOriginal = new Document( Utils.string2Element(Utils.element2String(rup.getRootElement(), false))); String msgDB = "customForm"; activities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities()); updateRUPFromRequest(rup); // set times of rup if rescheduling required if (reschedulingRUPAfterEditInCustomForm && reschedulingKey != null && !reschedulingKey.isEmpty()) { String activityName = reschedulingKey.substring((XML_ACTIVITY + "_").length()); activityName = activityName.substring(0, activityName.indexOf("_")); List<Element> activities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities(activityName)); if (!activities.isEmpty()) { scheduler.setTimes(rup, activities.get(0), !isShortForm, false, null); } } // reschedule rup at complete of short custom form if (isShortForm && (complete || save || confirmReservations)) { scheduler.findTimeSlot(rup, !isShortForm); } // full xsd validation only, if explicit datatype validation has not found any errors if (!XMLUtils.hasErrors(rup.getRootElement())) { validateXSD(rup); } if (confirmReservations) { String xpath = XMLUtils.getXPATH_Activities(); List<Element> activities = XMLUtils.getXMLObjects(rup, xpath); for (Element activity : activities) { List<Element> reservations = activity.getChildren(XML_RESERVATION); for (Element reservation : reservations) { if (RESOURCE_STATUS_REQUESTED.equals(reservation.getChildText(XML_STATUSTOBE))) { reservation.getChild(XML_STATUSTOBE).setText(RESOURCE_STATUS_RESERVED); } } } } try { ss.checkRelations(rup); rup = rs.saveReservations(rup, !complete && !confirmReservations, true); } catch (Exception e) { _log.error("Exception", e); XMLUtils.addErrorValue(rup.getRootElement(), !isShortForm, "msgRUPSaveRSError", e.getMessage()); } boolean haveTosave = XMLUtils.different(rupOriginal.getRootElement(), rup.getRootElement()); if (haveTosave && (complete || save || confirmReservations)) { try { ss.saveRupToDatabase(caseId, userName, rup, msgDB); haveTosave = false; } catch (Exception e) { XMLUtils.addErrorValue(rup.getRootElement(), true, "msgRUPSaveDBError", e.getMessage()); } } else { _log.debug("Don't have to save rup"); } if (complete) { ss.startMessageTransfers(caseId, rup); } if (complete && !XMLUtils.hasErrors(rup.getRootElement())) { completeWorkitem(taskName, itemid, handle); } else { activities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities()); buffer.append(getForm(cas, haveTosave)); // show javascript alert to confirm the completing of work item if (complete) { bufferTop.append(" msgCompleteForce=\"").append(config.getLocalizedString("msgCompleteForce")) .append("\";\r\n"); bufferBottom.append(" completeForce();\r\n"); } } } else { // first call Case cas = ss.loadCase(caseId); Document rup = cas.getRUP(); Document rupOriginal = new Document( Utils.string2Element(Utils.element2String(rup.getRootElement(), false))); Set<String> addedActivityNames = new HashSet<String>(); // extend RUP from model specification ss.extendRUPFromYAWLModel(rup, addedActivityNames); // extend RUP with variable from YAWL addedActivityNames.addAll(ss.getDiffActivityNames(rup.getRootElement(), task.getChild(XML_RUP))); if (XMLUtils.mergeElements(rup.getRootElement(), task.getChild(XML_RUP))) { _log.info("extend rup for case " + caseId + " from YAWL variable: " + Utils.document2String(rup, false)); } // extend RUP with historical data ss.completeRupFromHistory(rup, addedActivityNames); boolean haveToSave = XMLUtils.different(rupOriginal.getRootElement(), rup.getRootElement()); validateAllElements(rup.getRootElement()); activities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities()); buffer.append(getForm(cas, haveToSave)); } }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
/** * - remove empty 'dummy' resOrUtils/*from w w w. ja v a 2 s . c o m*/ * - set RequestType to POU, but only if SOU or EOU is not set */ public void updateActivities(Document doc) throws JDOMException { activities = XMLUtils.getXMLObjects(doc, XMLUtils.getXPATH_Activities()); for (Element activity : activities) { String xpath = XMLUtils.getXPATH_ActivityElement(activity.getChildText(XML_ACTIVITYNAME), "*[count(./" + XML_DUMMY + ")>0]", null); List<Element> resOrUtils = XMLUtils.getXMLObjects(doc, xpath); for (Element resOrUtil : resOrUtils) { activity.removeContent(resOrUtil); } Element requestType = activity.getChild(XML_REQUESTTYPE); if (requestType == null) { requestType = new Element(XML_REQUESTTYPE); activity.addContent(requestType); } if (requestType.getText().isEmpty()) { requestType.setText(UTILISATION_TYPE_PLAN); } } }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
/** * parses the ResourceUtilisationPlan and * 1) generates HTML form for input of ResourceUtilisationPlan * 2) generates list with keys for Reservations and UtilisationRelations to check * * @param cas//from ww w .ja va 2 s.c o m * @param haveTosave * @return */ protected StringBuffer getForm(Case cas, boolean haveTosave) throws IOException, JDOMException { Document rup = cas.getRUP(); bufferBottomDebug.append(Utils.element2String(rup.getRootElement(), true)); StringBuffer buffer = new StringBuffer(); bufferTop.append(" window.name = \"").append(config.getLocalizedString("titleSchedulingPage")) .append("\";\r\n"); buffer.append("\r\n\r\n<div style=\"display: none\">"); buffer.append("<table>"); buffer.append(getRow(getTemplate(XML_RESERVATION), XML_RESERVATION + "Template", false)); buffer.append(getRow(getTemplate(XML_UTILISATIONREL), XML_UTILISATIONREL + "Template", false)); buffer.append(getRow(getTemplate(XML_MSGTRANSFER), XML_MSGTRANSFER + "Template", false)); buffer.append("</table>"); buffer.append("</div>"); // create form fields buffer.append("\r\n\r\n<form id=\"bla\" name=\"bla\" method=\"post\">"); // @see CUI/default.jsp buffer.append("\r\n<div id=\"main_content\"><div>"); //<%-- header image on the top right --%> buffer.append( "<img src=\"images/logo_klinik.jpg\" alt=\"Krankenhaus\" style=\"float:right;margin-bottom:1em;\">"); //<%-- the Perikles logo and language selection --%> buffer.append("<img src=\"images/logo-133x20.jpg\" alt=\"Perikles\">"); // localisation for (int i = 0; i < LANGUAGES.length; i++) { String l = LANGUAGES[i]; buffer.append(i > 0 ? " " : ""); if (l.equals(config.getLanguage())) { buffer.append("<img src=\"images/").append(l).append("-32-16.gif\" style=\"margin:1px 0 0 6px;\""); } else { buffer.append("<input type=\"image\" src=\"images/").append(l).append( "-32-16.gif\" style=\"margin:1px 0 0 10px;\" name=\"LocalePic\" id=\"LocalePic\" value=\"") .append(l).append("\""); buffer.append(" onclick=\" document.getElementById('" + LANGUAGE_ATTRIBUTE_NAME + "').value=this.value; return saveTab();\""); buffer.append(" onkeyup=\" document.getElementById('" + LANGUAGE_ATTRIBUTE_NAME + "').value=this.value; return saveTab();\""); } buffer.append("/>"); } buffer.append("<div id=\"userPanel\"><span class=\"ui-widget-header selected\">"); buffer.append("<span>" + userName + "</span>"); buffer.append(config.getLocalizedString("titleSchedulingPage")); buffer.append("</span></div>"); buffer.append("<div class=\"clear\"></div>"); // general warnings and errors if (XMLUtils.hasWarnings(rup.getRootElement())) { buffer.append("<div class=\"warningInput\"><span class=\"ui-corner-all\">"); buffer.append(config.getLocalizedString("msgRUPWarning")); String warning = config.getLocalizedJSONString(XMLUtils.getWarningValue(rup.getRootElement())); if (warning != null) { buffer.append(warning); } buffer.append("</span></div>\r\n"); } if (XMLUtils.hasErrors(rup.getRootElement())) { buffer.append("<div class=\"errorInput\"><span class=\"ui-corner-all\">"); buffer.append(config.getLocalizedString("msgRUPError")); String error = config.getLocalizedJSONString(XMLUtils.getErrorValue(rup.getRootElement())); if (error != null) { buffer.append(error); } buffer.append("</span></div>\r\n"); } // title of custom form buffer.append("<h1 title=\"'" + cas.getCaseId() + "'\">"); buffer.append(config.getLocalizedString("case") + ": "); buffer.append(cas.getCaseId()); buffer.append("</h1>"); buffer.append("<input type=\"hidden\" name=\"" + LANGUAGE_ATTRIBUTE_NAME + "\" id=\"" + LANGUAGE_ATTRIBUTE_NAME + "\" value=\"\"/>\r\n\r\n"); // rescheduling information fields if (!isShortForm) { buffer.append("<input type=\"hidden\" name=\"reschedulingKey\" id=\"reschedulingKey\" value=\"\"/>"); } // prepare tabs buffer.append("<div id=\"tabs\">"); buffer.append("<ul>"); for (Element activity : activities) { String activityName = activity.getChildText(XML_ACTIVITYNAME); String clazz = ""; if (XMLUtils.hasErrors(activity)) { clazz = " class=\"" + CSS_ERRORTEXT + "\""; } else if (XMLUtils.hasWarnings(activity)) { clazz = " class=\"" + CSS_WARNINGTEXT + "\""; } buffer.append("<li><a href=\"#" + activityName + "\"><span" + clazz + ">"); buffer.append(config.getLocalizedString(activityName)); buffer.append("</span></a></li>"); } buffer.append("</ul>"); buffer.append("<input type=\"hidden\" name=\"selectedTab\" id=\"selectedTab\" value=\"\"/>"); String selectedTab = request.getParameter("selectedTab"); bufferBottom.append(" $(\"#tabs\").tabs('select', " + (selectedTab == null ? 0 : selectedTab) + ");\r\n"); // loop over activities for (int i = 0; i < activities.size(); i++) { Element activity = activities.get(i); String activityName = activity.getChildText(XML_ACTIVITYNAME); buffer.append("\r\n\r\n"); buffer.append("<div id=\"" + activityName + "\">"); String key = XML_ACTIVITY + "_" + activityName; buffer.append("<fieldset>"); buffer.append( "<legend style=\"font-weight:bold;\">" + config.getLocalizedString("general") + "</legend>"); buffer.append("<table>"); buffer.append("<tr>"); Element type = activity.getChild(XML_ACTIVITYTYPE); Element duration = activity.getChild(XML_DURATION); Element from = activity.getChild(XML_FROM); Element to = activity.getChild(XML_TO); buffer.append( getInputColumn(type, type.getName(), null, key, XMLUtils.isVisibleFromSchema(type.getName()))); buffer.append(getInputColumn(duration, duration.getName(), to, key, XMLUtils.isVisibleFromSchema(duration.getName()))); if (isShortForm) { // show FROM only at first activity (if i=0) buffer.append(getInputColumn(from, "Date", to, key, i == 0 && XMLUtils.isVisibleFromSchema(from.getName()))); buffer.append("<input type=\"hidden\" name=\"reschedulingKey\" id=\"reschedulingKey\" value=\"" + key + "_" + from.getName() + "\"/>"); } else { buffer.append(getInputColumn(from, from.getName(), to, key, XMLUtils.isVisibleFromSchema(from.getName()))); buffer.append( getInputColumn(to, to.getName(), from, key, XMLUtils.isVisibleFromSchema(to.getName()))); } buffer.append("</tr>"); buffer.append("</table>"); buffer.append("</fieldset>"); buffer.append(getListOf(activity, XML_RESERVATION, true)); buffer.append(getListOf(activity, XML_UTILISATIONREL, !isShortForm)); buffer.append(getListOf(activity, XML_MSGTRANSFER, !isShortForm)); buffer.append("</div>"); } bufferTop.append(" sessionHandle=\"" + ResourceServiceInterface.getInstance().getHandle() + "\";\r\n"); bufferTop.append(" count=" + count + ";\r\n"); bufferTop.append(" msgAjaxError=\"" + config.getLocalizedString("msgAjaxError") + "\";\r\n"); bufferTop .append(" msgCancelWithoutSave=\"" + config.getLocalizedString("msgCancelWithoutSave") + "\";\r\n"); bufferTop.append(" ajaxCache={};\r\n"); // cache reload bei jedem aufruf buffer.append("</div>"); buffer.append("\r\n\r\n<input type=\"submit\" name=\"Cancel\" id=\"Cancel\" value=\"" + config.getLocalizedString("cancelButton") + "\""); buffer.append(" onclick=\"return dontSave(event);\""); buffer.append(" onkeyup=\"return dontSave(event);\""); buffer.append(" title=\"" + config.getLocalizedString("AbortAndReturn") + "\""); buffer.append( " class=\"abort ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left ui-button-text\""); buffer.append("/>"); buffer.append("<input type=\"submit\" name=\"Save\" id=\"Save\" value=\"" + config.getLocalizedString("saveButton") + "\""); buffer.append(haveTosave ? " disabled=false" : " disabled=true"); buffer.append(" onclick=\"return saveTab();\""); buffer.append(" onkeyup=\"return saveTab();\""); buffer.append(" title=\"" + config.getLocalizedString("Save") + "\""); buffer.append(" class=\"ui-button ui-widget ui-state-default ui-button-text-only ui-button-text\""); buffer.append("/>"); bufferBottom.append(" enableButton('Save', " + haveTosave + ");\r\n"); // confirm reservations button if (canConfirmReservations) { buffer.append("<input type=\"submit\" name=\"ConfirmReservations\" id=\"ConfirmReservations\" value=\"" + config.getLocalizedString("confirmReservationsButton") + "\""); buffer.append(" onclick=\"return saveTab();\""); buffer.append(" onkeyup=\"return saveTab();\""); buffer.append(" title=\"" + config.getLocalizedString("confirmReservations") + "\""); buffer.append(" class=\"ui-button ui-widget ui-state-default ui-button-text-only ui-button-text\""); buffer.append("/>"); } buffer.append("<input type=\"submit\" name=\"Complete\" id=\"Complete\" value=\"" + config.getLocalizedString("completeButton") + "\""); buffer.append(" onclick=\"return saveTab();\""); buffer.append(" onkeyup=\"return saveTab();\""); buffer.append(" title=\"" + config.getLocalizedString("CompleteAndReturn") + "\""); buffer.append( " class=\"ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-button-text\""); buffer.append("/>"); buffer.append("<input type=\"hidden\" name=\"CompleteForce\" id=\"CompleteForce\" value=\"\"/>"); buffer.append("</div>"); buffer.append("</div>"); buffer.append("</form>"); return buffer; }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
private StringBuffer getInputHTML(Element field, Element dependingField, String key) { StringBuffer tag1 = new StringBuffer(), tag2 = new StringBuffer(), tag3 = new StringBuffer(); String n = field.getName();/* ww w.j a va 2s . c om*/ String value = field.getText(); String title = "", onclick = "", onchange = "", onpropertychange = "", cssClass = "", style = ""; String dependingFieldKey = null, dependingFieldValue = null; String fromFieldKey = null, durationFieldKey = null; String keyPart = key.substring(0, key.lastIndexOf("_")); boolean readonly = false; boolean disabled = XMLUtils.isReadonlyFromSchema(n); // is field no more editable (if SOU or EOU) Element activity = field.getParentElement(); while (activity != null && !activity.getName().equals(XML_ACTIVITY)) { activity = activity.getParentElement(); } boolean eou = isRequestTypeEOU(activity); boolean sou = eou || isRequestTypeSOU(activity); ArrayList<String> enumerations = new ArrayList<String>(); try { ArrayList<Element> restrictions = new ArrayList<Element>(); cssClass = validateElement(field, restrictions); for (Element restriction : restrictions) { if (restriction.getName().equals("enumeration")) { enumerations.add(restriction.getAttributeValue("value")); } } if (cssClass == null) cssClass = ""; } catch (Exception e) { _log.error("cannot get css class for element: " + n, e); } if (dependingField != null) { durationFieldKey = keyPart + "_" + XML_DURATION; fromFieldKey = keyPart + "_" + XML_FROM; dependingFieldValue = dependingField.getText(); dependingFieldKey = keyPart + "_" + dependingField.getName(); } // set field layout if (!enumerations.isEmpty() || XMLUtils.isEnumerationFromSchema(n)) { tag1.append("<select size=\"1\""); if (XMLUtils.isEnumerationFromSchema(n)) { if (n.equals(XML_OTHERACTIVITYNAME)) { for (Element activityElem : activities) { String name = activityElem.getChildText(XML_ACTIVITYNAME); tag2.append("<option value=\"" + name + "\""); tag2.append(name.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(name) + "</option>"); } } else if (n.equals(XML_ACTIVITYTYPE)) { try { tag2.append("<option value=\"\""); tag2.append("".equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString("<msgNewEntry>") + "</option>"); List<String> activityTypes = ss.getActivityTypes(activity.getChildText(XML_ACTIVITYNAME), value); for (String activityType : activityTypes) { tag2.append("<option value=\"" + activityType + "\""); tag2.append(activityType.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(activityType) + "</option>"); } } catch (Exception e) { XMLUtils.addWarningValue(field, "msgActivityTypesWarning"); } // activate if: // 1. 'new entry' was selected or // 2. 'new entry' was clicked and no more options than 'new entry' exists in selectbox onchange += " comboBox(this,0);"; // onpropertychange += " comboBox(this,0);"; onclick += " comboBox(this,1);"; } else { tag2.append("<script type=\"text/javascript\">"); tag2.append("writeDropDownBox('" + n + "','" + dependingFieldValue + "','" + value + "','" + key + "');"); tag2.append("</script>"); } } else { for (String s : enumerations) { tag2.append("<option value=\"" + s + "\""); tag2.append(s.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(s) + "</option>"); } } tag3.append("</select>"); } else if (cssClass.equals(CSS_DATEINPUT)) { try { Date date = Utils.string2Date(value, Utils.DATETIME_PATTERN_XML); value = Utils.date2String(date, isShortForm ? Utils.DATE_PATTERN : Utils.DATETIME_PATTERN); } catch (ParseException e) { //_log.error("cannot parse " + value); } tag1.append("<input type=\"text\" value=\"" + value + "\""); String showCalendar = " displayCalendar(document.getElementById('" + key + "'),'"; if (isShortForm) { showCalendar += Utils.getJsCalendarFormat(Utils.DATE_PATTERN) + "',this);return false;"; } else { showCalendar += Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "',this,true);return false;"; } readonly = true; onclick += (disabled ? "" : showCalendar); tag3.append("</input>"); } else if (cssClass.equals(CSS_DURATIONINPUT)) { // TODO@tbe: not only minutes, use jquery.slider tag1.append("<input type=\"text\" value=\"" + Utils.stringXMLDuration2stringMinutes(value) + "\""); tag3.append("</input>"); } else { tag1.append("<input type=\"text\" value=\"" + value + "\""); tag3.append("</input>"); } // some javascript functions for convenience if (n.equals(XML_FROM)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + key + "','" + durationFieldKey + "',1,false,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } else { onchange += " setRescheduling('" + key + "');"; } disabled = disabled || sou; } else if (n.equals(XML_TO)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + key + "','" + durationFieldKey + "',-1,false,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } disabled = disabled || eou; } else if (n.equals(XML_ID) || n.equals(XML_ROLE) || n.equals(XML_CAPABILITY) || n.equals(XML_CATEGORY) || n.equals(XML_SUBCATEGORY)) { String statusFieldKey = keyPart.substring(0, keyPart.lastIndexOf("_") + 1) + XML_STATUS; onchange += " document.getElementById('" + statusFieldKey + "').selectedIndex=0;"; // set to "unknown" if (n.equals(XML_CATEGORY)) { onchange += " actualizeDropDownBox('" + XML_CATEGORY + "','" + XML_SUBCATEGORY + "',this.id);"; } disabled = disabled || sou || eou; } else if (n.equals(XML_STATUS) || n.equals(XML_STATUSTOBE)) { disabled = disabled || sou || eou; } else if (n.equals(XML_DURATION)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + fromFieldKey + "','" + durationFieldKey + "',1,true,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } disabled = disabled || sou || eou; } else if (n.equals(XML_WORKLOAD)) { disabled = disabled || sou || eou; } else if (n.equals(XML_OTHERACTIVITYNAME) || n.equals(XML_MIN) || n.equals(XML_MAX) || n.equals(XML_THISUTILISATIONTYPE) || n.equals(XML_OTHERUTILISATIONTYPE)) { onchange += " setRescheduling('" + key + "');"; } // show error and warning messages String error = config.getLocalizedJSONString(XMLUtils.getErrorValue(field)); String warning = config.getLocalizedJSONString(XMLUtils.getWarningValue(field)); if (error != null) { title = error; cssClass += " " + CSS_ERRORINPUT; } else { if (warning != null) { title = warning; cssClass += " " + CSS_WARNINGINPUT; } } if (XMLUtils.isRequiredFromSchema(n) || isShortForm) { cssClass += " " + CSS_REQUIRED; } tag1.append(disabled ? " disabled=\"disabled\"" : ""); tag1.append(readonly ? " readonly=\"readonly\"" : ""); tag1.append(" id=\"" + key + "\" name=\"" + key + "\""); tag1.append(title.isEmpty() ? "" : " title=\"" + title + "\""); tag1.append(cssClass.isEmpty() ? "" : " class=\"" + cssClass + "\""); tag1.append(style.isEmpty() ? "" : " style=\"" + style + "\""); tag1.append(" onchange=\"enableButton('Save', true);" + onchange + "\""); tag1.append(" onpropertychange=\"enableButton('Save', true);" + onpropertychange + "\""); tag1.append(onclick.isEmpty() ? "" : " onclick=\"" + onclick + "\""); tag1.append(">"); return tag1.append(tag2).append(tag3); }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
/** * gets rows for each element of type reservation or utilisationRelation * * @param listElementName//from ww w . ja va 2 s. c o m * @return */ private StringBuffer getListOf(Element activity, String listElementName, boolean visible) { boolean disabledButton = false; if (listElementName.equals(XML_RESERVATION)) { disabledButton = isRequestTypeEOU(activity) || isRequestTypeSOU(activity); } else if (listElementName.equals(XML_UTILISATIONREL)) { disabledButton = true; // TODO@tbe: erstmal nur von einer Relation pro Aktivitt ausgehen } StringBuffer buffer = new StringBuffer(); String templateName = listElementName + "Template"; String insertName = activity.getChildText(XML_ACTIVITYNAME) + "_" + templateName + "_insert"; String key = XML_ACTIVITY + "_" + activity.getChildText(XML_ACTIVITYNAME) + "_" + listElementName + "_#"; buffer.append("\r\n\r\n<fieldset"); buffer.append(visible ? "" : " style=\"display: none\""); buffer.append(">"); buffer.append("<legend style=\"font-weight:bold;\">" + config.getLocalizedString(listElementName + "s") + "</legend>"); buffer.append("<table>"); buffer.append("<tr>"); buffer.append(getAddButton(templateName, key, insertName, disabledButton)); buffer.append("</tr>"); List<Element> elements = (List<Element>) activity.getChildren(listElementName); for (int i = 1; i <= elements.size(); i++) { count++; Element resOrUtil = elements.get(i - 1); buffer.append(getErrorRow(resOrUtil, key + count)); buffer.append(getRow(resOrUtil, key + count, disabledButton)); } buffer.append("\r\n<tr style=\"display: none\" id=\"" + insertName + "\"><td></td></tr>"); buffer.append("</table>"); buffer.append("</fieldset>"); return buffer; }
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
private String getRequestType(Element activity) { return activity == null ? null : activity.getChildText(XML_REQUESTTYPE); }
From source file:org.yawlfoundation.yawl.scheduling.lanes.LaneImporter.java
License:Open Source License
public void updateRUP(String start, String categoryOrRoleId, String resourceId) throws Exception { logger.debug("categoryOrRoleId=" + categoryOrRoleId + ", resourceId=" + resourceId); ResourceServiceInterface rs = ResourceServiceInterface.getInstance(); if (logger.isInfoEnabled()) { // get category/role and resource names for logging only String categoryOrRoleName = null; String resourceName = "virtual"; try {//from w ww .j a v a 2s .com NonHumanCategory category = rs.getNonHumanCategory(categoryOrRoleId); categoryOrRoleName = category.getName(); resourceName = rs.getNonHumanResource(resourceId).getName(); } catch (ResourceGatewayException e) { // NonHumanCategory not found try { Role role = rs.getRole(categoryOrRoleId); categoryOrRoleName = role.getName(); resourceName = rs.getParticipant(resourceId).getFullName(); } catch (ResourceGatewayException e1) { // Role not found } } logger.info("------------------------caseId: " + caseId + ", set new start time=" + start + " and " + categoryOrRoleName + " to " + resourceName); } // set new resourceId String xpath = XMLUtils.getXPATH_ActivityElement(null, XML_RESERVATION, null); List reservations = XMLUtils.getXMLObjects(rup, xpath); boolean reservationFound = false; for (Object o : reservations) { Element resource = ((Element) o).getChild(XML_RESOURCE); String resId = resource.getChildText(XML_ID); String categoryId = resource.getChildText(XML_CATEGORY); String roleId = resource.getChildText(XML_ROLE); if (categoryOrRoleId.equals(categoryId)) { update(resource, XML_CATEGORY, resourceId, categoryOrRoleId); reservationFound = true; continue; } if (categoryOrRoleId.equals(roleId)) { update(resource, XML_ROLE, resourceId, categoryOrRoleId); reservationFound = true; continue; } NonHumanResource nhr = null; try { nhr = rs.getNonHumanResource(resId); } catch (ResourceGatewayException e) { // NonHumanResource not found } if (nhr != null) { categoryId = nhr.getCategory() == null ? null : nhr.getCategory().getID(); if (categoryOrRoleId.equals(categoryId)) { update(resource, XML_CATEGORY, resourceId, categoryOrRoleId); reservationFound = true; continue; } } Participant par = null; try { par = rs.getParticipant(resId); } catch (ResourceGatewayException e) { // Participant not found } if (par != null) { List<Role> roles = rs.getParticipantRoles(resId); if (roles != null) { for (Role r : roles) { if (categoryOrRoleId.equals(r.getID())) { update(resource, XML_ROLE, resourceId, categoryOrRoleId); reservationFound = true; } } } } } if (!reservationFound) { logger.error("resourceId of rup " + caseId + " was not updated, because no matching resource found"); } // set new start time XMLUtils.setDateValue(earliestFrom, Utils.string2Date(start, "yyyy-MM-dd HH:mm:ss")); reload = scheduler.setTimes(rup, earliestFrom.getParentElement(), true, true, null) || reload; errors = ""; Set<String> errorSet = SchedulingService.getInstance().optimizeAndSaveRup(rup, rs.getUserName(sessionHandle), null, reservationFound); logger.debug("save caseId: " + caseId + ", errors: " + Utils.toString(errorSet)); for (String error : errorSet) { errors += config.getLocalizedJSONString(error) + ";"; } if (errors.isEmpty()) { logger.debug("no errors in rup " + caseId + " found"); } else { logger.debug("errors in rup " + caseId + " found: " + errors); errors = caseId + ": " + errors; } hasErrors = !(reservationFound && errors.isEmpty()); }