Search in sources :

Example 96 with ObjectFactory

use of org.hl7.elm_modelinfo.r1.ObjectFactory in project clinical_quality_language by cqframework.

the class Main method main.

public static void main(String[] args) throws IOException, JAXBException {
    OptionParser parser = new OptionParser();
    OptionSpec<File> schemaOpt = parser.accepts("schema").withRequiredArg().ofType(File.class).required();
    OptionSpec<String> modelOpt = parser.accepts("model").withRequiredArg().ofType(String.class);
    OptionSpec<File> configOpt = parser.accepts("config").withOptionalArg().ofType(File.class);
    OptionSpec<File> outputOpt = parser.accepts("output").withRequiredArg().ofType(File.class);
    OptionSpec<String> normalizePrefixOpt = parser.accepts("normalize-prefix").withRequiredArg().ofType(String.class);
    OptionSpec<ModelImporterOptions.ChoiceTypePolicy> choiceTypeOpt = parser.accepts("choicetype-policy").withRequiredArg().ofType(ModelImporterOptions.ChoiceTypePolicy.class);
    OptionSpec<ModelImporterOptions.SimpleTypeRestrictionPolicy> stRestrictionsOpt = parser.accepts("simpletype-restriction-policy").withRequiredArg().ofType(ModelImporterOptions.SimpleTypeRestrictionPolicy.class);
    OptionSpec<ModelImporterOptions.ElementRedeclarationPolicy> redeclarationsOpt = parser.accepts("element-redeclaration-policy").withRequiredArg().ofType(ModelImporterOptions.ElementRedeclarationPolicy.class);
    OptionSpec<ModelImporterOptions.VersionPolicy> versionPolicyOpt = parser.accepts("version-policy").withRequiredArg().ofType(ModelImporterOptions.VersionPolicy.class);
    OptionSpec<File> optionsFileOpt = parser.accepts("options-file").withRequiredArg().ofType(File.class);
    OptionSet options = parser.parse(args);
    File schemaFile = schemaOpt.value(options);
    InputStream is = new FileInputStream(schemaFile);
    XmlSchemaCollection schemaCol = new XmlSchemaCollection();
    schemaCol.setBaseUri(schemaFile.getParent());
    XmlSchema schema = schemaCol.read(new StreamSource(is));
    ModelImporterOptions importerOptions;
    if (options.has(optionsFileOpt)) {
        importerOptions = ModelImporterOptions.loadFromProperties(optionsFileOpt.value(options));
    } else {
        importerOptions = new ModelImporterOptions();
    }
    if (options.has(modelOpt)) {
        importerOptions.setModel(modelOpt.value(options));
    }
    if (options.has(choiceTypeOpt)) {
        importerOptions.setChoiceTypePolicy(choiceTypeOpt.value(options));
    }
    if (options.has(stRestrictionsOpt)) {
        importerOptions.setSimpleTypeRestrictionPolicy(stRestrictionsOpt.value(options));
    }
    if (options.has(redeclarationsOpt)) {
        importerOptions.setElementRedeclarationPolicy(redeclarationsOpt.value(options));
    }
    if (options.has(versionPolicyOpt)) {
        importerOptions.setVersionPolicy(versionPolicyOpt.value(options));
    }
    if (options.has(normalizePrefixOpt)) {
        importerOptions.setNormalizePrefix(normalizePrefixOpt.value(options));
    }
    ModelInfo config = null;
    if (configOpt != null) {
        File configFile = configOpt.value(options);
        if (configFile != null) {
            config = JAXB.unmarshal(configFile, ModelInfo.class);
        }
    }
    ModelInfo modelInfo = ModelImporter.fromXsd(schema, importerOptions, config);
    JAXBContext jc = JAXBContext.newInstance(ModelInfo.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    File outputfile;
    if (!options.has(outputOpt) || outputOpt.value(options).isDirectory()) {
        // construct output filename using modelinfo
        String name = String.format("%s-modelinfo.xml", modelInfo.getTargetQualifier());
        String basePath = options.has(outputOpt) ? outputOpt.value(options).getAbsolutePath() : schemaFile.getParent();
        outputfile = new File(basePath + File.separator + name);
    } else {
        outputfile = outputOpt.value(options);
    }
    if (outputfile.equals(schemaFile)) {
        throw new IllegalArgumentException("input schema file and output file must be different!");
    }
    OutputStream os = new FileOutputStream(outputfile, false);
    try {
        OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
        marshaller.marshal(new ObjectFactory().createModelInfo(modelInfo), writer);
    } finally {
        os.close();
    }
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) JAXBContext(javax.xml.bind.JAXBContext) OptionParser(joptsimple.OptionParser) ObjectFactory(org.hl7.elm_modelinfo.r1.ObjectFactory) Marshaller(javax.xml.bind.Marshaller) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchema(org.apache.ws.commons.schema.XmlSchema) OptionSet(joptsimple.OptionSet)

Example 97 with ObjectFactory

use of org.hl7.elm_modelinfo.r1.ObjectFactory in project ddf by codice.

the class CswEndpoint method getInsertResultFromResponse.

private InsertResultType getInsertResultFromResponse(CreateResponse createResponse) throws CswException {
    InsertResultType result = new InsertResultType();
    WKTReader reader = new WKTReader();
    for (Metacard metacard : createResponse.getCreatedMetacards()) {
        BoundingBoxType boundingBox = new BoundingBoxType();
        Geometry geometry = null;
        String bbox = null;
        try {
            if (metacard.getAttribute(CswConstants.BBOX_PROP) != null) {
                bbox = metacard.getAttribute(CswConstants.BBOX_PROP).getValue().toString();
                geometry = reader.read(bbox);
            } else if (StringUtils.isNotBlank(metacard.getLocation())) {
                bbox = metacard.getLocation();
                geometry = reader.read(bbox);
            }
        } catch (ParseException e) {
            LOGGER.debug("Unable to parse BoundingBox : {}", bbox, e);
        }
        BriefRecordType briefRecordType = new BriefRecordType();
        if (geometry != null) {
            Envelope bounds = geometry.getEnvelopeInternal();
            if (bounds != null) {
                boundingBox.setCrs(CswConstants.SRS_NAME);
                boundingBox.setLowerCorner(Arrays.asList(bounds.getMinX(), bounds.getMinY()));
                boundingBox.setUpperCorner(Arrays.asList(bounds.getMaxX(), bounds.getMaxY()));
                briefRecordType.getBoundingBox().add(new net.opengis.ows.v_1_0_0.ObjectFactory().createBoundingBox(boundingBox));
            }
        }
        SimpleLiteral identifier = new SimpleLiteral();
        identifier.getContent().add(metacard.getId());
        briefRecordType.getIdentifier().add(new JAXBElement<>(CswConstants.DC_IDENTIFIER_QNAME, SimpleLiteral.class, identifier));
        SimpleLiteral title = new SimpleLiteral();
        title.getContent().add(metacard.getTitle());
        briefRecordType.getTitle().add(new JAXBElement<>(CswConstants.DC_TITLE_QNAME, SimpleLiteral.class, title));
        SimpleLiteral type = new SimpleLiteral();
        type.getContent().add(metacard.getContentTypeName());
        briefRecordType.setType(type);
        result.getBriefRecord().add(briefRecordType);
    }
    return result;
}
Also used : WKTReader(org.locationtech.jts.io.WKTReader) Envelope(org.locationtech.jts.geom.Envelope) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) BoundingBoxType(net.opengis.ows.v_1_0_0.BoundingBoxType) Geometry(org.locationtech.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType)

Example 98 with ObjectFactory

use of org.hl7.elm_modelinfo.r1.ObjectFactory in project ddf by codice.

the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipCA.

@Test
public void testEvaluateroleuseractionquerycitizenshipCA() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_CA");
    final String country = "CA";
    testSetup();
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_2);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);
    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);
    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(country);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);
    XacmlClient pdp = new XacmlClient(tempDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
    // Verify
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.DENY);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 99 with ObjectFactory

use of org.hl7.elm_modelinfo.r1.ObjectFactory in project ddf by codice.

the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipUS.

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");
    // Setup
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);
        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);
        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);
        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);
        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);
        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);
        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);
        XacmlClient pdp = new XacmlClient(destDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);
        // Cleanup
        LOGGER.debug("Deleting directory: {}", destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: {}", destDir);
    }
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 100 with ObjectFactory

use of org.hl7.elm_modelinfo.r1.ObjectFactory in project cxf by apache.

the class AbstractSequenceTest method testIdentifierEquals.

@Test
public void testIdentifierEquals() {
    Identifier id1 = null;
    Identifier id2 = null;
    assertTrue(AbstractSequence.identifierEquals(id1, id2));
    ObjectFactory factory = new ObjectFactory();
    id1 = factory.createIdentifier();
    id1.setValue("seq1");
    assertFalse(AbstractSequence.identifierEquals(id1, id2));
    id2 = factory.createIdentifier();
    id2.setValue("seq2");
    assertFalse(AbstractSequence.identifierEquals(id1, id2));
    id2.setValue("seq1");
    assertTrue(AbstractSequence.identifierEquals(id1, id2));
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) ObjectFactory(org.apache.cxf.ws.rm.v200702.ObjectFactory) Test(org.junit.Test)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)34 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)26 Marshaller (javax.xml.bind.Marshaller)24 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 StringWriter (java.io.StringWriter)19 JAXBContext (javax.xml.bind.JAXBContext)19 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 ObjectFactory (no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory)16 QName (javax.xml.namespace.QName)15 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)12 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ObjectFactory (slash.navigation.kml.binding22.ObjectFactory)12 BigInteger (java.math.BigInteger)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11