Search in sources :

Example 1 with Namespace

use of org.osate.aadl2.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindPartialCode.

public void testFindPartialCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("c")).addContent(new Element("temp").setAttribute("lang", "kl_AA", xml).addContent("d"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 2 with Namespace

use of org.osate.aadl2.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindFullCode.

public void testFindFullCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl_KL", xml).addContent("c"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 3 with Namespace

use of org.osate.aadl2.Namespace in project JMRI by JMRI.

the class RevHistoryXml method loadRevision.

static void loadRevision(RevHistory r, Element e) {
    Element s;
    Namespace n = Namespace.getNamespace(NAMESPACE);
    int revnumber = 0;
    s = e.getChild("revnumber", n);
    if (s != null) {
        String c = s.getText();
        revnumber = Integer.parseInt(c);
    }
    String date = null;
    s = e.getChild("date", n);
    if (s != null) {
        date = s.getText();
    }
    String authorinitials = null;
    s = e.getChild("authorinitials", n);
    if (s != null) {
        authorinitials = s.getText();
    }
    String revremark = null;
    s = e.getChild("revremark", n);
    if (s != null) {
        revremark = s.getText();
    }
    r.addRevision(revnumber, date, authorinitials, revremark);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 4 with Namespace

use of org.osate.aadl2.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)

Example 5 with Namespace

use of org.osate.aadl2.Namespace in project qpp-conversion-tool by CMSgov.

the class AciMeasurePerformedRnRDecoderTest method internalDecodeReturnsTreeContinue.

@Test
void internalDecodeReturnsTreeContinue() {
    // set-up
    AciMeasurePerformedRnRDecoder objectUnderTest = new AciMeasurePerformedRnRDecoder(new Context());
    Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3");
    Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    Element element = new Element("organizer", rootns);
    Element templateIdElement = new Element("templateId", rootns).setAttribute("root", "2.16.840.1.113883.10.20.27.3.28");
    Element referenceElement = new Element("reference", rootns);
    Element externalDocumentElement = new Element("externalDocument", rootns);
    Element idElement = new Element("id", rootns).setAttribute("extension", MEASURE_ID);
    externalDocumentElement.addContent(idElement);
    referenceElement.addContent(externalDocumentElement);
    element.addContent(templateIdElement);
    element.addContent(referenceElement);
    element.addNamespaceDeclaration(ns);
    Node aciMeasurePerformedNode = new Node();
    objectUnderTest.setNamespace(element.getNamespace());
    // execute
    DecodeResult decodeResult = objectUnderTest.decode(element, aciMeasurePerformedNode);
    // assert
    assertThat(decodeResult).isEqualTo(DecodeResult.TREE_CONTINUE);
    String actualMeasureId = aciMeasurePerformedNode.getValue("measureId");
    assertThat(actualMeasureId).isEqualTo(MEASURE_ID);
}
Also used : Context(gov.cms.qpp.conversion.Context) Element(org.jdom2.Element) Node(gov.cms.qpp.conversion.model.Node) Namespace(org.jdom2.Namespace) Test(org.junit.jupiter.api.Test)

Aggregations

Namespace (org.jdom2.Namespace)145 Element (org.jdom2.Element)122 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)23 List (java.util.List)21 Document (org.jdom2.Document)20 XConfiguration (org.apache.oozie.util.XConfiguration)19 HashMap (java.util.HashMap)18 Attribute (org.jdom2.Attribute)17 Configuration (org.apache.hadoop.conf.Configuration)15 StringReader (java.io.StringReader)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 Namespace.getNamespace (org.jdom2.Namespace.getNamespace)14 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)12 SAXBuilder (org.jdom2.input.SAXBuilder)10 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)9 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)9