Search in sources :

Example 26 with Namespace.getNamespace

use of org.jdom2.Namespace.getNamespace 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)

Example 27 with Namespace.getNamespace

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

the class BatchProcessModelParserPlugin method parseElement.

private Optional<BatchActivity> parseElement(Element element, Namespace bpmnNamespace, Integer nodeId) throws ScyllaValidationException {
    Element extensions = element.getChild("extensionElements", bpmnNamespace);
    // Check that only elements with extensions get parsed
    if (extensions == null)
        return Optional.empty();
    String id = element.getAttributeValue("id");
    Namespace camundaNamespace = Namespace.getNamespace("camunda", "http://camunda.org/schema/1.0/bpmn");
    List<Namespace> possibleNamespaces = Arrays.asList(camundaNamespace, bpmnNamespace);
    List<Element> propertyList = possibleNamespaces.stream().map(namespace -> extensions.getChild("properties", namespace)).filter(Objects::nonNull).map(propertiesElement -> propertiesElement.getChildren("property", propertiesElement.getNamespace())).flatMap(List::stream).collect(Collectors.toList());
    if (propertyList.isEmpty())
        return Optional.empty();
    Integer maxBatchSize = null;
    BatchClusterExecutionType executionType = defaultExecutionType();
    ActivationRule activationRule = null;
    List<BatchGroupingCharacteristic> groupingCharacteristic = new ArrayList<BatchGroupingCharacteristic>();
    for (Element property : propertyList) {
        // 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":
                executionType = parseExecutionType(property);
                break;
            // grouping characteristic
            case "groupingCharacteristic":
                groupingCharacteristic.addAll(parseGroupingCharacteristic(property));
                break;
            // threshold capacity (minimum batch size) & timeout of activation rule
            case "activationRule":
                activationRule = parseActivationRule(property);
                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);
    return Optional.of(ba);
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException)

Example 28 with Namespace.getNamespace

use of org.jdom2.Namespace.getNamespace 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 29 with Namespace.getNamespace

use of org.jdom2.Namespace.getNamespace in project jspwiki by apache.

the class WebContainerAuthorizer method initialize.

/**
 * Initializes the authorizer for.
 * @param engine the current wiki engine
 * @param props the wiki engine initialization properties
 */
public void initialize(WikiEngine engine, Properties props) {
    m_engine = engine;
    m_containerAuthorized = false;
    // FIXME: Error handling here is not very verbose
    try {
        m_webxml = getWebXml();
        if (m_webxml != null) {
            // Add the J2EE 2.4 schema namespace
            m_webxml.getRootElement().setNamespace(Namespace.getNamespace(J2EE_SCHEMA_25_NAMESPACE));
            m_containerAuthorized = isConstrained("/Delete.jsp", Role.ALL) && isConstrained("/Login.jsp", Role.ALL);
        }
        if (m_containerAuthorized) {
            m_containerRoles = getRoles(m_webxml);
            log.info("JSPWiki is using container-managed authentication.");
        } else {
            log.info("JSPWiki is using custom authentication.");
        }
    } catch (IOException e) {
        log.error("Initialization failed: ", e);
        throw new InternalWikiException(e.getClass().getName() + ": " + e.getMessage(), e);
    } catch (JDOMException e) {
        log.error("Malformed XML in web.xml", e);
        throw new InternalWikiException(e.getClass().getName() + ": " + e.getMessage(), e);
    }
    if (m_containerRoles.length > 0) {
        String roles = "";
        for (Role containerRole : m_containerRoles) {
            roles = roles + containerRole + " ";
        }
        log.info(" JSPWiki determined the web container manages these roles: " + roles);
    }
    log.info("Authorizer WebContainerAuthorizer initialized successfully.");
}
Also used : IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 30 with Namespace.getNamespace

use of org.jdom2.Namespace.getNamespace in project wildfly-camel by wildfly-extras.

the class StandaloneConfigTest method testUnsupportedNamespaceVersion.

@Test
public void testUnsupportedNamespaceVersion() throws Exception {
    URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);
    doc.getRootElement().getChild("extensions", NS_DOMAIN_130).setNamespace(Namespace.getNamespace("urn:jboss:domain:99.99"));
    File modifiedConfig = new File("target/standalone-modified.xml");
    outputDocumentContent(doc, new FileOutputStream(modifiedConfig));
    jdom = new SAXBuilder();
    doc = jdom.build(modifiedConfig);
    ConfigContext context = ConfigSupport.createContext(null, modifiedConfig.toPath(), doc);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    expectedException.expect(ConfigException.class);
    plugin.applyStandaloneConfigChange(context, true);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom2.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) File(java.io.File) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Aggregations

Element (org.jdom2.Element)73 Namespace (org.jdom2.Namespace)55 Document (org.jdom2.Document)36 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)18 Attribute (org.jdom2.Attribute)17 SAXBuilder (org.jdom2.input.SAXBuilder)13 JDOMException (org.jdom2.JDOMException)12 XMLOutputter (org.jdom2.output.XMLOutputter)11 File (java.io.File)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 List (java.util.List)6 Context (gov.cms.qpp.conversion.Context)5 Node (gov.cms.qpp.conversion.model.Node)5 StringReader (java.io.StringReader)5 Writer (java.io.Writer)5 JaxenException (org.jaxen.JaxenException)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4