Search in sources :

Example 6 with Namespace

use of org.jdom2.Namespace in project webservices-axiom by apache.

the class CalculatorEndpoint method add.

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "AddRequest")
@ResponsePayload
public Element add(@RequestPayload Element addRequest) throws Exception {
    log.debug("Endpoint invoked");
    double sum = 0d;
    for (Element operand : operandExpression.evaluate(addRequest)) {
        sum += Double.parseDouble(operand.getTextNormalize());
    }
    Element response = new Element("AddResponse", NAMESPACE);
    response.setText(String.valueOf(sum));
    return response;
}
Also used : Element(org.jdom2.Element) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 7 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class JDomTestClass method createEmpty.

public static void createEmpty() {
    FileWriter writer;
    // Namespace nsp = Namespace.getNamespace("bsim","http://bsim.hpi.uni-potsdam.de/scylla/simModel");
    // 
    // Element root = new Element("globalConfiguration",nsp);
    // Document d = new Document(root);
    // root.setAttribute("targetNamespace", "http://www.hpi.de");
    // Element rAO = new Element("resourceAssignmentOrder",nsp);
    // rAO.setText("priority,simulationTime,");
    // root.addContent(rAO);
    GlobalConfigurationCreator c = new GlobalConfigurationCreator();
    c.setId("This is an ID");
    c.addReferencedResourceAssignmentOrder("priority");
    c.addReferencedResourceAssignmentOrder("simulationTime");
    c.removeReferencedResourceAssignmentOrder("simulationTime");
    c.setSeed(1337);
    c.setTimeOffset(ZoneOffset.ofHoursMinutesSeconds(13, 37, 42));
    c.createTimetable("Hero");
    Timetable lazy = c.createTimetable("Lazy");
    c.deleteTimetable("Hero");
    c.deleteTimetable("Hero");
    TimetableItem item = lazy.addItem(DayOfWeek.MONDAY, DayOfWeek.FRIDAY, LocalTime.parse("13:37"), LocalTime.parse("20:35:37"));
    item.setFrom(DayOfWeek.THURSDAY);
    c.addResourceType("Student");
    c.addResourceType("Professor");
    // Nothing should happen
    c.addResourceType("Student");
    c.removeResourceType("Student");
    ResourceType student = c.addResourceType("Student");
    student.setName("True Hero");
    student.setDefaultTimeUnit(TimeUnit.MINUTES);
    student.setDefaultQuantity(100);
    student.setDefaultCost(12.50);
    student.addInstance("Anton");
    student.addInstance("Bert");
    student.getInstance("Anton").setCost(50);
    student.removeInstance("Bert");
    ResourceType prof = c.getResourceType("Professor");
    prof.setDefaultQuantity(1);
    prof.setDefaultCost(41.14);
    prof.setDefaultTimeUnit(TimeUnit.HOURS);
    c.validate();
    // 
    try {
        writer = new FileWriter("testFile.xml");
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(c.getDoc(), writer);
        outputter.output(c.getDoc(), System.out);
    // writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Element r = null;
    try {
        Document doc;
        SAXBuilder builder = new SAXBuilder();
        doc = builder.build("./samples/p2_normal.bpmn");
        r = doc.getRootElement();
    } catch (JDOMException | IOException e1) {
        e1.printStackTrace();
    }
    SimulationConfigurationCreator s = new SimulationConfigurationCreator();
    s.setId("This is the id");
    // s.setProcessRef("Process_2");
    s.setProcessInstances(10);
    s.setStartDateTime(ZonedDateTime.parse("2017-07-06T09:00:00.000+02:00"));
    s.setEndDateTime(ZonedDateTime.parse("2017-07-12T09:00:00.000+02:00"));
    s.setRandomSeed(1337);
    try {
        s.setModel(r, false);
    } catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
        e1.printStackTrace();
    }
    Distribution testDistribution = Distribution.create(DistributionType.BINOMIAL);
    testDistribution.setAttribute("amount", 5);
    testDistribution.setAttribute(0, 0.2);
    s.getStartEvent().setArrivalRateDistribution(testDistribution);
    Task t = (Task) s.getElement("Task_1tvvo6w");
    t.setDurationDistribution(Distribution.create(DistributionType.CONSTANT));
    t.getDurationDistribution().setAttribute("constantValue", 100);
    t.assignResource(student).setAmount(5);
    t.assignResource(prof).setAmount(5);
    t.getResource("Student").setAmount(13);
    t.deassignResource(prof.getId());
    t.getResource(student.getId()).setAssignmentPriority(5);
    t.assignResource(prof).setAmount(5);
    t.getResource("Professor").setAssignmentPriority(0);
    t.getResource(prof.getId()).removeAssignmentDefinition();
    t.deassignResource(prof.getId());
    for (ElementLink element : s.getElements()) {
        if (!(element instanceof Task))
            continue;
        Task task = (Task) element;
        Distribution d = Distribution.create(DistributionType.TRIANGULAR);
        d.setAttribute(0, 11);
        d.setAttribute(2, 33);
        d.setAttribute("peak", 22);
        task.setDurationDistribution(d);
        task.assignResource(prof).setAmount(3);
    }
    ExclusiveGateway g = null;
    for (ElementLink element : s.getElements()) {
        if (element instanceof ExclusiveGateway) {
            g = (ExclusiveGateway) element;
            break;
        }
    }
    g.setBranchingProbability("SequenceFlow_1237oxj", 1);
    for (String branch : g.getBranches()) {
        System.err.println(s.getFlowTarget(branch).el.getAttributeValue("name"));
    }
    try {
        writer = new FileWriter("testFile2.xml");
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(s.getDoc(), writer);
        outputter.output(s.getDoc(), System.out);
    // writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Timetable(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.Timetable) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) Task(de.hpi.bpt.scylla.creation.SimulationConfiguration.Task) FileWriter(java.io.FileWriter) Element(org.jdom2.Element) SimulationConfigurationCreator(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator) ResourceType(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.ResourceType) GlobalConfigurationCreator(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) NoProcessSpecifiedException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NoProcessSpecifiedException) ExclusiveGateway(de.hpi.bpt.scylla.creation.SimulationConfiguration.ExclusiveGateway) NotAuthorizedToOverrideException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAuthorizedToOverrideException) Distribution(de.hpi.bpt.scylla.creation.SimulationConfiguration.Distribution) TimetableItem(de.hpi.bpt.scylla.creation.GlobalConfiguration.GlobalConfigurationCreator.Timetable.TimetableItem)

Example 8 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class SimulationConfigurationCreator method createModelElement.

/**
 * Parses a process model element to a new sc element with wrapper object
 * @param child : Process model element to be parsed (e.g. Task)
 * @param addTo : Context for the new sc element to be added to (normally sc root or a subprocess)
 */
private void createModelElement(Element child, ElementLink addTo) {
    String id = child.getAttributeValue("id");
    // Don't add elements that are already parsed (e.g when loading an existing, incomplete SC)
    if (id != null && !id.isEmpty() && elements.containsKey(id))
        return;
    String name = child.getName();
    switch(name) {
        case "startEvent":
            // ignore subProcess startEvents
            if (!addTo.equals(this))
                break;
            setStartEvent(new StartEvent(id));
            getStartEvent().addTo(addTo);
            elements.put(getStartEvent().getId(), getStartEvent());
            break;
        case "subProcess":
            SubProcess s = new SubProcess(id, child.getAttributeValue("name"));
            s.addTo(addTo);
            elements.put(s.getId(), s);
            addProcessModelElements(child, s);
            break;
        case "exclusiveGateway":
            // Note: getChildren("outgoing",Nsp); not possible as there is no single unique namespace
            List<Element> branches = child.getChildren();
            List<String> branchids = new ArrayList<String>();
            for (Element b : branches) {
                if (b.getName().equals("outgoing"))
                    branchids.add(b.getValue());
            }
            if (branchids.size() <= 1) {
                elements.put(id, new ElementLink(child) {
                });
                // No branching probabilities for a join gateway - no definition needed
                break;
            }
            ExclusiveGateway eg = new ExclusiveGateway(id, branchids);
            elements.put(eg.getId(), eg);
            eg.addTo(addTo);
            break;
        case "sequenceFlow":
            flows.put(id, new String[] { child.getAttributeValue("sourceRef"), child.getAttributeValue("targetRef") });
            break;
        default:
            if (name.equals("task") || name.endsWith("Task")) {
                Task t = new Task(id, child.getAttributeValue("name"));
                t.addTo(addTo);
                elements.put(t.getId(), t);
            } else if (name.endsWith("Event")) {
                elements.put(id, new ElementLink(child) {
                });
            }
            break;
    }
}
Also used : Element(org.jdom2.Element) ElementLink(de.hpi.bpt.scylla.creation.ElementLink) ArrayList(java.util.ArrayList)

Example 9 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class CommonProcessElementsParser method parse.

@Override
public CommonProcessElements parse(Element rootElement) throws ScyllaValidationException {
    String definitionsId = rootElement.getAttributeValue("id");
    Namespace bpmnNamespace = rootElement.getNamespace();
    Map<String, GlobalTaskType> globalTasks = new HashMap<String, GlobalTaskType>();
    Map<String, Element> globalTaskElements = new HashMap<String, Element>();
    Map<String, Map<String, String>> resources = new HashMap<String, Map<String, String>>();
    Map<String, Map<String, String>> messages = new HashMap<String, Map<String, String>>();
    Map<String, Map<String, String>> errors = new HashMap<String, Map<String, String>>();
    Map<String, Map<String, String>> escalations = new HashMap<String, Map<String, String>>();
    // global tasks called by call activities
    for (GlobalTaskType gtt : GlobalTaskType.values()) {
        List<Element> gte = rootElement.getChildren(gtt.toString(), bpmnNamespace);
        for (Element el : gte) {
            String elementId = el.getAttributeValue("id");
            globalTasks.put(elementId, gtt);
            globalTaskElements.put(elementId, el);
        }
    }
    // common elements: chapter 8.4 in BPMN 2.0.2 definition
    List<Element> resourceElements = rootElement.getChildren("resource", bpmnNamespace);
    for (Element el : resourceElements) {
        Map<String, String> resource = new HashMap<String, String>();
        String elementId = el.getAttributeValue("id");
        String name = el.getAttributeValue("name");
        if (name != null) {
            resource.put("name", name);
        }
        resources.put(elementId, resource);
    }
    List<Element> messageElements = rootElement.getChildren("message", bpmnNamespace);
    for (Element el : messageElements) {
        Map<String, String> message = new HashMap<String, String>();
        String elementId = el.getAttributeValue("id");
        String name = el.getAttributeValue("name");
        if (name != null) {
            message.put("name", name);
        }
        messages.put(elementId, message);
    }
    List<Element> errorElements = rootElement.getChildren("error", bpmnNamespace);
    for (Element el : errorElements) {
        Map<String, String> error = new HashMap<String, String>();
        String elementId = el.getAttributeValue("id");
        String name = el.getAttributeValue("name");
        if (name != null) {
            error.put("name", name);
        }
        String errorCode = el.getAttributeValue("errorCode");
        if (errorCode != null) {
            error.put("errorCode", errorCode);
        }
        errors.put(elementId, error);
    }
    List<Element> escalationElements = rootElement.getChildren("escalation", bpmnNamespace);
    for (Element el : escalationElements) {
        Map<String, String> escalation = new HashMap<String, String>();
        String elementId = el.getAttributeValue("id");
        String name = el.getAttributeValue("name");
        if (name != null) {
            escalation.put("name", name);
        }
        String escalationCode = el.getAttributeValue("escalationCode");
        if (escalationCode != null) {
            escalation.put("escalationCode", escalationCode);
        }
        escalations.put(elementId, escalation);
    }
    CommonProcessElements commonProcessElements = new CommonProcessElements(definitionsId, globalTasks, globalTaskElements, resources, messages, errors, escalations);
    return commonProcessElements;
}
Also used : CommonProcessElements(de.hpi.bpt.scylla.model.process.CommonProcessElements) GlobalTaskType(de.hpi.bpt.scylla.model.process.node.GlobalTaskType) HashMap(java.util.HashMap) Element(org.jdom2.Element) Map(java.util.Map) HashMap(java.util.HashMap) Namespace(org.jdom2.Namespace)

Example 10 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class ProcessModelParser method parseExtensions.

private Map<Integer, BatchActivity> parseExtensions(Element el, Namespace bpmnNamespace, Integer nodeId, Map<Integer, BatchActivity> batchActivities) throws ScyllaValidationException {
    // Check that only elements with extensions get parsed
    if (el.getChild("extensionElements", bpmnNamespace) == null)
        return batchActivities;
    String id = el.getAttributeValue("id");
    Namespace camundaNamespace = Namespace.getNamespace("camunda", "http://camunda.org/schema/1.0/bpmn");
    List<Namespace> namespaces = Arrays.asList(camundaNamespace, bpmnNamespace);
    Predicate<Namespace> isOneOfUsedNamespaces = namespace -> el.getChild("extensionElements", bpmnNamespace).getChild("properties", namespace) == null;
    if (namespaces.stream().allMatch(isOneOfUsedNamespaces))
        return batchActivities;
    Integer maxBatchSize = null;
    BatchClusterExecutionType executionType = BatchClusterExecutionType.PARALLEL;
    ActivationRule activationRule = null;
    List<String> groupingCharacteristic = new ArrayList<String>();
    for (Namespace namespace : namespaces) {
        if (el.getChild("extensionElements", bpmnNamespace).getChild("properties", namespace) == null)
            continue;
        List<Element> propertiesList = el.getChild("extensionElements", bpmnNamespace).getChild("properties", namespace).getChildren("property", namespace);
        for (Element property : propertiesList) {
            // maximum batch size
            switch(property.getAttributeValue("name")) {
                case "maxBatchSize":
                    maxBatchSize = Integer.parseInt(property.getAttributeValue("value"));
                    break;
                // execution type. if none is defined, take parallel as default
                case "executionType":
                    String tmpExecutionType = property.getAttributeValue("value");
                    /*if (!(tmpExecutionType.equals("parallel") || tmpExecutionType.equals("sequential-taskbased") || tmpExecutionType.equals("sequential-casebased"))){
                            throw new ScyllaValidationException("Execution type " + tmpExecutionType + " not supported. Pleause us either parallel or sequential (either task or case-based)");
                        }
                        BatchClusterExecutionType bce = BatchClusterExecutionType.PARALLEL;
                        executionType = property.getAttributeValue("value");*/
                    switch(property.getAttributeValue("value")) {
                        case "parallel":
                            executionType = BatchClusterExecutionType.PARALLEL;
                        case "sequential-taskbased":
                            executionType = BatchClusterExecutionType.SEQUENTIAL_TASKBASED;
                        case "sequential-casebased":
                            executionType = BatchClusterExecutionType.SEQUENTIAL_CASEBASED;
                    }
                    break;
                // grouping characteristic
                case "groupingCharacteristic":
                    List<Element> groupings = property.getChildren("property", namespace);
                    for (Element grouping : groupings) {
                        if (grouping.getAttributeValue("name").equals("processVariable")) {
                            groupingCharacteristic.add(grouping.getAttributeValue("value"));
                        }
                    }
                    break;
                // threshold capacity (minimum batch size) & timeout of activation rule
                case "activationRule":
                    List<Element> ruleElements = property.getChildren("property", namespace);
                    if (ruleElements.size() != 1) {
                        throw new ScyllaValidationException("There must be exactly one activation rule for batch activity " + id + ", but there are " + ruleElements.size() + ".");
                    }
                    Element ruleElement = property.getChild("property", namespace);
                    String ruleElementName = ruleElement.getName();
                    switch(ruleElement.getAttributeValue("name")) {
                        case "thresholdRule":
                            // parsing threshold, if it is defined
                            int threshold = 0;
                            String thresholdString = ruleElement.getAttributeValue("threshold");
                            if (thresholdString != null && !thresholdString.isEmpty()) {
                                threshold = Integer.parseInt(thresholdString);
                            }
                            // parsing timeout, if it is defined
                            Duration timeout = null;
                            String timeoutString = ruleElement.getAttributeValue("timeout");
                            if (timeoutString != null) {
                                timeout = Duration.parse(timeoutString);
                            }
                            // parsing dueDate, if it is defined
                            String dueDate = ruleElement.getAttributeValue("duedate");
                            // either timeout or dueDate should not be null --> two different Constructors for the ThresholdRule
                            if (timeout != null) {
                                activationRule = new ThresholdRule(threshold, timeout);
                            } else if (dueDate != null) {
                                activationRule = new ThresholdRule(threshold, dueDate);
                            } else {
                                throw new ScyllaValidationException("A threshold rule was selected for" + ruleElementName + " then either timeout or duedate must be specified.");
                            }
                            break;
                        case "minMaxRule":
                            int minInstances = Integer.parseInt(ruleElement.getAttributeValue("minInstances"));
                            Duration minTimeout = Duration.parse(ruleElement.getAttributeValue("minTimeout"));
                            int maxInstances = Integer.parseInt(ruleElement.getAttributeValue("maxInstances"));
                            Duration maxTimeout = Duration.parse(ruleElement.getAttributeValue("maxTimeout"));
                            activationRule = new MinMaxRule(minInstances, minTimeout, maxInstances, maxTimeout);
                            break;
                        default:
                            throw new ScyllaValidationException("Activation rule type" + ruleElementName + " for batch activity " + id + " not supported.");
                    }
                    break;
            }
        }
    }
    if (maxBatchSize == null) {
        throw new ScyllaValidationException("You have to specify a maxBatchSize at " + id + " .");
    }
    /*if (groupingCharacteristic.isEmpty()){
                        throw new ScyllaValidationException("You have to specify at least one groupingCharacteristic at "+ id +" .");
                    }*/
    BatchActivity ba = new BatchActivity(nodeId, maxBatchSize, executionType, activationRule, groupingCharacteristic);
    batchActivities.put(nodeId, ba);
    return batchActivities;
/*System.out.println(maxBatchSize);
        System.out.println(groupingCharacteristic);
        System.out.println(activationRule);*/
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) java.util(java.util) MessageFlow(de.hpi.bpt.scylla.model.process.node.MessageFlow) Name(javax.xml.soap.Name) Predicate(java.util.function.Predicate) SimulationManager(de.hpi.bpt.scylla.SimulationManager) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) NoStartNodeException(de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException) de.hpi.bpt.scylla.plugin.batch(de.hpi.bpt.scylla.plugin.batch) MultipleStartNodesException(de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException) DataObjectType(de.hpi.bpt.scylla.model.process.node.DataObjectType) CommonProcessElements(de.hpi.bpt.scylla.model.process.CommonProcessElements) TaskType(de.hpi.bpt.scylla.model.process.node.TaskType) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) Attribute(org.jdom2.Attribute) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) Graph(de.hpi.bpt.scylla.model.process.graph.Graph) EventType(de.hpi.bpt.scylla.model.process.node.EventType) Duration(java.time.Duration) DebugLogger(de.hpi.bpt.scylla.logger.DebugLogger) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) Namespace(org.jdom2.Namespace) Element(org.jdom2.Element) Element(org.jdom2.Element) Duration(java.time.Duration) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException)

Aggregations

Element (org.jdom2.Element)31 Namespace (org.jdom2.Namespace)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)11 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 HashMap (java.util.HashMap)9 JDOMException (org.jdom2.JDOMException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)3 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)2 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)2 Resource (de.hpi.bpt.scylla.model.global.resource.Resource)2 CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 Graph (de.hpi.bpt.scylla.model.process.graph.Graph)2 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 DataObjectType (de.hpi.bpt.scylla.model.process.node.DataObjectType)2