Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:org.yawlfoundation.yawl.scheduling.SchedulingService.java

License:Open Source License

/**
 * call from JobRUPCheck, sets TO time of running activities to actual time
 * and calculate new DURATION value/*from   www . j  a  va  2s. c o m*/
 */
public void updateRunningRups(String savedBy) throws Exception {
    Date now = new Date();
    List<Document> rups = getActiveRups(now);

    // update rups startzeit und/oder endzeit
    for (Document rup : rups) {
        for (Element activity : (List<Element>) rup.getRootElement().getChildren(XML_ACTIVITY)) {
            String activityName = activity.getChildText(XML_ACTIVITYNAME);
            Element from = activity.getChild(XML_FROM);
            Date fromDate = XMLUtils.getDateValue(from, true);
            Element to = activity.getChild(XML_TO);
            Date toDate = XMLUtils.getDateValue(to, true);
            Element duration = activity.getChild(XML_DURATION);
            String requestType = activity.getChildText(XML_REQUESTTYPE);

            // _log.debug("caseId: "+caseId+", requestType: "+requestType+", from: "+from.getText()+", to: "+to.getText());
            if (requestType.equals(UTILISATION_TYPE_BEGIN) && toDate.before(now)) {
                XMLUtils.setDateValue(to, now);
                XMLUtils.setDurationValue(duration, toDate.getTime() - fromDate.getTime());

                _log.info("update caseId: " + XMLUtils.getCaseId(rup) + ", set " + activityName + ".TO: "
                        + Utils.date2String(now, Utils.DATETIME_PATTERN));

                _scheduler.setTimes(rup, activity, true, true, null);
            }
        }
        optimizeAndSaveRup(rup, savedBy, null, false);
    }
}

From source file:org.yawlfoundation.yawl.scheduling.SchedulingService.java

License:Open Source License

/**
 * get overall time of activities//from  ww  w.  j  a va2 s .  c  o m
 */
private long getOverallTimeInMin(Document rup) {
    long begin = Long.MAX_VALUE, end = 0;
    List<Element> activities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities());
    for (Element activity2 : activities) {
        String activityName2 = activity2.getChildText(XML_ACTIVITYNAME);
        try {
            Element from = activity2.getChild(XML_FROM);
            Date fromDate = XMLUtils.getDateValue(from, true);
            begin = Math.min(begin, fromDate.getTime());

            Element to = activity2.getChild(XML_TO);
            Date toDate = XMLUtils.getDateValue(to, true);
            end = Math.max(end, toDate.getTime());
        } catch (Exception e) {
            _log.error("cannot get times of activity: " + activityName2, e);
        }
    }
    long time = (end - begin) / 1000 / 60;
    _log.debug("overall time = " + time + " min");
    return time;
}

From source file:org.yawlfoundation.yawl.scheduling.servlet.MessageReceiveServlet.java

License:Open Source License

private String handleRSRequest(HttpServletRequest request) {
    String action = null;/*  w  w w . j  a  v  a  2  s  .  c om*/

    try {
        if (!ResourceServiceInterface.getInstance().checkConnection(request.getParameter("sessionHandle"))) {
            throw new SchedulingException("msgSessionTimeout");
        }

        if ((action = request.getParameter("StatusChange")) != null) {
            Element statusChange = Utils.string2Element(action);
            XMLUtils.validate(statusChange);

            String caseId = statusChange.getChildText(XML_CASEID);
            String activityName = statusChange.getChildText(XML_ACTIVITYNAME);
            Long reservationId = XMLUtils.getLongValue(statusChange.getChild(XML_RESERVATIONID), true);
            String statusNew = statusChange.getChildText("NewStatus");

            SchedulingService.getInstance().reservationStatusChange(caseId, activityName, reservationId,
                    statusNew);
        } else {
            throw new IOException("missing action");
        }
        return "<success/>";
    } catch (SchedulingException e) {
        _log.warn("cannot handle action: " + action + ", " + e.getMessage());
        return "<failure>" + e.getMessage() + "</failure>";
    } catch (Exception e) {
        _log.error("cannot handle action: " + action, e);
        return "<failure>" + e.getMessage() + "</failure>";
    }
}

From source file:org.yawlfoundation.yawl.scheduling.timer.JobTimer.java

License:Open Source License

private static Calendar calcMsgTransferStartTime(Element msgTransfer) {
    Calendar cal = Calendar.getInstance();
    String msgUtilisationType = msgTransfer.getChildText(XML_MSGUTILISATIONTYPE);
    Element activity = msgTransfer.getParentElement();
    if (UTILISATION_TYPE_BEGIN.equals(msgUtilisationType)) {
        cal.setTime(XMLUtils.getDateValue(activity.getChild(XML_FROM), true));
    } else {/*from w w w  .  j  a v  a 2 s . co m*/
        cal.setTime(XMLUtils.getDateValue(activity.getChild(XML_TO), true));
    }
    int min = XMLUtils.getDurationValueInMinutes(msgTransfer.getChild(XML_MSGDURATION), true);
    if (MSGREL_BEFORE.equals(msgTransfer.getChildText(XML_MSGREL))) {
        min = 0 - min;
    }
    cal.add(Calendar.MINUTE, min);
    return cal;
}

From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java

License:Open Source License

/**
 * returns all activity names from element e recursively
 * // w w w .j a  va 2 s .c o  m
 * @param e
 * @return
 */
public static Set<String> getActivityNames(Element e) {
    Set<String> activityNames = new HashSet<String>();
    if (e == null)
        return activityNames;

    if (e.getName().equals(XML_ACTIVITY)) {
        activityNames.add(e.getChildText(XML_ACTIVITYNAME));
    }
    for (Element child : (List<Element>) e.getChildren()) {
        activityNames.addAll(getActivityNames(child));
    }
    return activityNames;
}

From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java

License:Open Source License

/**
 * return true if e1 is equal (in context of perikles) to element e2
 * //from   www. ja  va  2 s  . c  o m
 * @param e1
 * @param e2
 * @return
 */
private static boolean elementsEqual(Element e1, Element e2) {
    String s1 = e1.getName(), s2 = e2.getName();

    if (!s1.equals(s2)) {
        return false;
    } else if (s1.equals(XML_ACTIVITY)) {
        s1 = e1.getChildText(XML_ACTIVITYNAME);
        s2 = e2.getChildText(XML_ACTIVITYNAME);
    } else if (s1.equals(XML_RESERVATION)) {
        try {
            s1 = e1.getChild(XML_RESOURCE).getChildText(XML_ID);
            s2 = e2.getChild(XML_RESOURCE).getChildText(XML_ID);
        } catch (Exception e) {
            s1 = null;
            s2 = null;
        }
    } else if (s1.equals(XML_UTILISATIONREL)) {
        try {
            s1 = e1.getChildText(XML_THISUTILISATIONTYPE) + e1.getChildText(XML_OTHERACTIVITYNAME);
            s1 += e1.getChildText(XML_OTHERUTILISATIONTYPE);
            s2 = e2.getChildText(XML_THISUTILISATIONTYPE) + e2.getChildText(XML_OTHERACTIVITYNAME);
            s2 += e2.getChildText(XML_OTHERUTILISATIONTYPE);
        } catch (Exception e) {
            s1 = null;
            s2 = null;
        }
    }

    if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) { // nicht entscheidbar
        return false;
    } else {
        return s1.equals(s2);
    }
}

From source file:org.yawlfoundation.yawl.smsModule.SMSSender.java

License:Open Source License

/**
 * Checks the work item out of the engine, sends an sms message, and
 * starts the thread that checks for a reply.
 * @param enabledWorkItem//from   w w  w  . j  a  v  a2  s.  co m
 */
public void handleEnabledWorkItemEvent(WorkItemRecord enabledWorkItem) {
    try {
        if (!checkConnection(_sessionHandle)) {
            _sessionHandle = connect(engineLogonName, engineLogonPassword);
        }
        if (successful(_sessionHandle)) {
            List executingChildren = checkOutAllInstancesOfThisTask(enabledWorkItem, _sessionHandle);
            String resultsFromService = "";
            for (int i = 0; i < executingChildren.size(); i++) {
                WorkItemRecord itemRecord = (WorkItemRecord) executingChildren.get(i);

                Element caseDataBoundForEngine = prepareReplyRootElement(enabledWorkItem, _sessionHandle);

                //                    first of all do a connection with the SMS Service
                //                    String smsConnectionID = performSMSConnection(_smsUsername, _smsPassword);

                //next get the parameters for message sending.
                Element paramsData = itemRecord.getDataList();
                String message = paramsData.getChildText(SMS_MESSAGE_PARAMNAME);
                String toPhone = paramsData.getChildText(SMS_PHONENO_PARAMNAME);
                //                    String msgCorrelationID = itemRecord.getID().substring(0, 12);

                //                    resultsFromService += performSMSSend(message, toPhone, smsConnectionID, msgCorrelationID);

                String jobID = performSMSSend(message, toPhone);

                //an outstanding interaction is an object that records the
                //details of a reply that needs to be polled for.
                Interaction inter = new Interaction();
                inter._smsJobID = jobID;
                inter._archivable = false;
                inter._timeOfSend = new Date();
                inter._workItemRecord = itemRecord;
                inter._caseDataBoundForEngine = caseDataBoundForEngine;
                _outStandingInteractions.add(inter);
            }

            System.out.println("\n\nSMSSender " + "\nResults of engine interactions : " + _report
                    + "\nResults of SMS invocations : " + resultsFromService);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (!_running) {
        //this thread polls for a reply while running
        Thread replyPoller = new Thread(this, "ReplyPoller");
        replyPoller.start();
    }
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private YCondition parseCondition(YNet aNet, Element conditionElem) {
    String conditionType = conditionElem.getName();
    String id = conditionElem.getAttributeValue("id");
    YCondition condition = null;//from   w  w  w.  ja v a2s .  c o m
    if ("condition".equals(conditionType)) {
        String label = conditionElem.getChildText("label");
        if (label != null) {
            condition = new YCondition(id, label, aNet);
        } else {
            condition = new YCondition(id, aNet);
        }
    } else if ("inputCondition".equals(conditionType)) {
        String name = conditionElem.getChildText("name");
        if (name != null) {
            condition = new YInputCondition(id, name, aNet);
        } else {
            condition = new YInputCondition(id, aNet);
        }
    } else if ("outputCondition".equals(conditionType)) {
        String name = conditionElem.getChildText("name");
        if (name != null) {
            condition = new YOutputCondition(id, name, aNet);
        } else {
            condition = new YOutputCondition(id, aNet);
        }
    } else
        condition = new YCondition(id, aNet); // should never hit this

    parseNameAndDocumentation(condition, conditionElem);
    _postsetIDs.add(condition.getID(), parsePostset(conditionElem));
    return condition;
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

/**
 * Adds parameter specific information to the YParameter argument (in &amp; out var).
 * @param paramElem the XML data// w w w .j a va2  s  . c  o m
 * @param parameter the in &amp; out var.
 */
public static void parseParameter(Element paramElem, YParameter parameter, Namespace ns, boolean version2) {
    parseLocalVariable(paramElem, parameter, ns, version2);

    String orderStr = paramElem.getChildText("ordering");
    if ((orderStr != null) && (StringUtil.isIntegerString(orderStr)))
        parameter.setOrdering(Integer.parseInt(orderStr));

    boolean isCutThroughParam = paramElem.getChild("isCutThroughParam", ns) != null;
    if (isCutThroughParam) {
        parameter.setIsCutThroughParam(isCutThroughParam);
    }

    String defaultValue = JDOMUtil.decodeEscapes(paramElem.getChildText("defaultValue", ns));
    if (defaultValue != null)
        parameter.setDefaultValue(defaultValue);

    parameter.setLogPredicate(parseLogPredicate(paramElem, ns));
}

From source file:org.yawlfoundation.yawl.worklet.rdr.RdrConclusion.java

License:Open Source License

private void rationaliseSteps(Map<Integer, Element> sortedMap) {
    _primitives = new ArrayList<RdrPrimitive>();
    int i = 1;//from   ww  w . ja v a 2  s . c  o  m
    for (Element step : sortedMap.values()) {
        String action = step.getChildText("action");
        String target = step.getChildText("target");
        _primitives.add(new RdrPrimitive(i++, action, target));
    }
}