Search in sources :

Example 6 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.

the class ProcessModelParser method parse.

@Override
public ProcessModel parse(Element rootElement) throws ScyllaValidationException {
    Namespace bpmnNamespace = rootElement.getNamespace();
    List<Element> processElements = rootElement.getChildren("process", bpmnNamespace);
    if (processElements.isEmpty()) {
        throw new ScyllaValidationException("No process in file.");
    }
    // pool references to process models
    Map<String, String> processIdToPoolName = new HashMap<String, String>();
    Map<String, MessageFlow> messageFlows = new HashMap<String, MessageFlow>();
    Element collaboration = rootElement.getChild("collaboration", bpmnNamespace);
    if (collaboration != null) {
        for (Element el : collaboration.getChildren()) {
            String elementName = el.getName();
            if (elementName.equals("participant")) {
                if (el.getAttributeValue("processRef") != null) {
                    String participantName = el.getAttributeValue("name");
                    String processId = el.getAttributeValue("processRef");
                    processIdToPoolName.put(processId, participantName);
                }
            } else if (elementName.equals("messageFlow")) {
                String id = el.getAttributeValue("id");
                String sourceRef = el.getAttributeValue("sourceRef");
                String targetRef = el.getAttributeValue("targetRef");
                MessageFlow messageFlow = new MessageFlow(id, sourceRef, targetRef);
                messageFlows.put(id, messageFlow);
            } else {
                DebugLogger.log("Element " + el.getName() + " of collaboration not supported.");
            }
        }
    }
    Map<String, ProcessModel> processModels = new HashMap<String, ProcessModel>();
    for (Element process : processElements) {
        ProcessModel processModel = parseProcess(process, bpmnNamespace, false, commonProcessElements);
        String processId = processModel.getId();
        if (processIdToPoolName.containsKey(processId)) {
            String participant = processIdToPoolName.get(processId);
            processModel.setParticipant(participant);
        }
        processModels.put(processId, processModel);
    }
    if (processModels.size() == 1) {
        return processModels.values().iterator().next();
    } else {
        try {
            Set<ProcessModel> processModelsTriggeredInCollaboration = new HashSet<ProcessModel>();
            ProcessModel processModelTriggeredExternally = null;
            for (String processId : processModels.keySet()) {
                ProcessModel pm = processModels.get(processId);
                int startNodeId = pm.getStartNode();
                String identifierOfStartNode = pm.getIdentifiers().get(startNodeId);
                boolean isTriggeredInCollaboration = false;
                for (MessageFlow mf : messageFlows.values()) {
                    if (mf.getTargetRef().equals(identifierOfStartNode)) {
                        isTriggeredInCollaboration = true;
                        break;
                    }
                }
                if (isTriggeredInCollaboration) {
                    processModelsTriggeredInCollaboration.add(pm);
                } else {
                    if (processModelTriggeredExternally != null) {
                        throw new ScyllaValidationException("BPMN file contains multiple process models that are triggered externally.");
                    }
                    processModelTriggeredExternally = pm;
                }
            }
            processModelTriggeredExternally.setProcessModelsInCollaboration(processModelsTriggeredInCollaboration);
            return processModelTriggeredExternally;
        } catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
            e.printStackTrace();
            throw new ScyllaValidationException(e.getMessage());
        }
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Element(org.jdom2.Element) MessageFlow(de.hpi.bpt.scylla.model.process.node.MessageFlow) MultipleStartNodesException(de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) NoStartNodeException(de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)

Example 7 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.

the class EventArrivalRateSCParserPlugin method parse.

/**
 * Parses all occurences of event arrival rates to be stored as extension attribute.
 */
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
    Map<Integer, TimeDistributionWrapper> arrivalRates = new HashMap<Integer, TimeDistributionWrapper>();
    Namespace simNamespace = sim.getNamespace();
    ProcessModel processModel = simulationInput.getProcessModel();
    for (Element el : sim.getChildren()) {
        String elementName = el.getName();
        if (elementName.equals(EventArrivalRatePluginUtils.ELEMENT_NAME)) {
            String identifier = el.getAttributeValue("id");
            if (identifier == null) {
                DebugLogger.log("Warning: Simulation configuration definition catch event element '" + elementName + "' does not have an identifier, skip.");
                continue;
            }
            Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
            if (nodeId == null) {
                DebugLogger.log("Warning: There is no matching catch event in the process model for " + "simulation configuration definition '" + identifier + ", skip.");
                continue;
            }
            Element elem = el.getChild("arrivalRate", simNamespace);
            if (elem != null) {
                TimeDistributionWrapper distribution = SimulationConfigurationParser.getTimeDistributionWrapper(elem, simNamespace);
                arrivalRates.put(nodeId, distribution);
            }
        }
    }
    Map<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put(EventArrivalRatePluginUtils.ARRIVALRATES_KEY, arrivalRates);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) Element(org.jdom2.Element) TimeDistributionWrapper(de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper) Namespace(org.jdom2.Namespace)

Example 8 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindPartialCodeNoAttribute.

public void testFindPartialCodeNoAttribute() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").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 9 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindFullCodeNoAttribute.

public void testFindFullCodeNoAttribute() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").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 10 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindDefault.

public void testFindDefault() {
    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", "hh", xml).addContent("b"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "a", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Element (org.jdom2.Element)17 Namespace (org.jdom2.Namespace)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)9 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)7 HashMap (java.util.HashMap)7 BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 Map (java.util.Map)3 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)2 CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 MessageFlow (de.hpi.bpt.scylla.model.process.node.MessageFlow)2 SimulationManager (de.hpi.bpt.scylla.SimulationManager)1 DebugLogger (de.hpi.bpt.scylla.logger.DebugLogger)1 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)1 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)1 GlobalConfiguration (de.hpi.bpt.scylla.model.global.GlobalConfiguration)1 DynamicResource (de.hpi.bpt.scylla.model.global.resource.DynamicResource)1 DynamicResourceInstance (de.hpi.bpt.scylla.model.global.resource.DynamicResourceInstance)1