Search in sources :

Example 1 with Schema

use of org.geotoolkit.xsd.xml.v2001.Schema in project policies-ui-backend by RedHatInsights.

the class OapiTest method validateOpenApi.

@Test
void validateOpenApi() throws Exception {
    OpenApi3 model = new OpenApi3Parser().parse(url, true);
    System.out.printf("OpenAPI Model at %s\n", url);
    if (!model.isValid()) {
        for (ValidationResults.ValidationItem item : model.getValidationItems()) {
            System.err.println(item);
        }
        fail("OpenAPI spec is not valid");
    }
    // 
    // Now that basic validation is done, we can add some of our own
    // 
    Map<String, Path> paths = model.getPaths();
    Map<String, Schema> schemas = model.getSchemas();
    // The base path filler. See also OASModifier.mangleName
    assertTrue(paths.containsKey("/"));
    // User config is private, so don't show it
    assertFalse(paths.containsKey("/user-config"));
    assertFalse(schemas.containsKey("SettingsValues"));
    // Check that openapi does not (again) collapse parameters
    assertEquals(9, paths.get("/policies").getOperation("get").getParameters().size());
    // Check that all properties are present ( https://github.com/smallrye/smallrye-open-api/issues/437 )
    Map<String, Schema> policyProperties = schemas.get("Policy").getProperties();
    assertEquals(9, policyProperties.size());
    assertTrue(policyProperties.containsKey("ctime"));
    assertTrue(policyProperties.containsKey("mtime"));
    // Now that the OpenAPI file has been validated, save a copy to the filesystem
    // This file is going to be uploaded in a regular CI build to know the API state
    // for a given build.
    InputStream in = url.openStream();
    Files.copy(in, Paths.get(TARGET_OPENAPI), StandardCopyOption.REPLACE_EXISTING);
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) ValidationResults(com.reprezen.kaizen.oasparser.val.ValidationResults) InputStream(java.io.InputStream) Schema(com.reprezen.kaizen.oasparser.model3.Schema) OpenApi3Parser(com.reprezen.kaizen.oasparser.OpenApi3Parser) OpenApi3(com.reprezen.kaizen.oasparser.model3.OpenApi3) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with Schema

use of org.geotoolkit.xsd.xml.v2001.Schema in project efm-integrasjonspunkt by felleslosninger.

the class P360Client method sendEduMelding.

@Override
public PutMessageResponseType sendEduMelding(PutMessageRequestType request) {
    JAXBElement<no.difi.meldingsutveksling.noarkexchange.p360.schema.PutMessageRequestType> p360request = new PutMessageRequestMapper().mapFrom(request);
    final WebServiceTemplate template = templateFactory.createTemplate("no.difi.meldingsutveksling.noarkexchange.p360.schema", PutMessageMarker.markerFrom(new PutMessageRequestWrapper(request)));
    JAXBElement<no.difi.meldingsutveksling.noarkexchange.p360.schema.PutMessageResponseType> response = (JAXBElement<no.difi.meldingsutveksling.noarkexchange.p360.schema.PutMessageResponseType>) template.marshalSendAndReceive(settings.getEndpointUrl(), p360request, new SoapActionCallback(SOAP_ACTION));
    PutMessageResponseType theResponse = new PutMessageResponseType();
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.map(response.getValue(), theResponse);
    setUnmappedValues(response, theResponse);
    if (!isValid(theResponse)) {
        theResponse = new PutMessageResponseType();
        final no.difi.meldingsutveksling.noarkexchange.schema.AppReceiptType appReceiptType = new no.difi.meldingsutveksling.noarkexchange.schema.AppReceiptType();
        theResponse.setResult(appReceiptType);
        appReceiptType.setType("OK");
    }
    return theResponse;
}
Also used : no.difi.meldingsutveksling.noarkexchange.p360.schema(no.difi.meldingsutveksling.noarkexchange.p360.schema) PutMessageResponseType(no.difi.meldingsutveksling.noarkexchange.schema.PutMessageResponseType) JAXBElement(javax.xml.bind.JAXBElement) PutMessageRequestMapper(no.difi.meldingsutveksling.noarkexchange.p360.PutMessageRequestMapper) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) ModelMapper(org.modelmapper.ModelMapper) PutMessageRequestType(no.difi.meldingsutveksling.noarkexchange.schema.PutMessageRequestType) SoapActionCallback(org.springframework.ws.soap.client.core.SoapActionCallback)

Example 3 with Schema

use of org.geotoolkit.xsd.xml.v2001.Schema in project geotoolkit by Geomatys.

the class JAXBFeatureTypeReader method listFeatureTypes.

private void listFeatureTypes(Schema schema, GenericNameIndex<FeatureType> result) throws MismatchedFeatureException, IllegalNameException {
    // then we look for feature type and groups
    for (OpenAttrs opAtts : schema.getSimpleTypeOrComplexTypeOrGroup()) {
        if (opAtts instanceof TopLevelElement) {
            final TopLevelElement element = (TopLevelElement) opAtts;
            final QName typeName = element.getType();
            if (typeName != null) {
                final ComplexType type = xsdContext.findComplexType(typeName);
                if (type == null && xsdContext.findSimpleType(typeName) == null) {
                    LOGGER.log(Level.WARNING, "Unable to find a the declaration of type {0} in schemas.", typeName.getLocalPart());
                    continue;
                }
                // if (xsdContext.isFeatureType(type)) {
                final BuildStack stack = new BuildStack();
                Object typeObj = getType(typeName.getNamespaceURI(), type, stack, true);
                FeatureType ft = null;
                if (typeObj instanceof FeatureAssociationRole) {
                    ft = ((FeatureAssociationRole) typeObj).getValueType();
                } else if (typeObj instanceof FeatureType) {
                    ft = (FeatureType) typeObj;
                }
                if (ft != null) {
                    addIfMissing(result, ft);
                    // if the type name is not the same as the element name, make a subtype
                    if (!ft.getName().tip().toString().equals(element.getName())) {
                        final GenericName name = NamesExt.create(NamesExt.getNamespace(ft.getName()), element.getName());
                        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
                        ftb.setName(name);
                        ftb.setSuperTypes(ft);
                        final FeatureType renamed = ftb.build();
                        addIfMissing(result, renamed);
                    }
                }
            // }
            } else {
                LOGGER.log(Level.WARNING, "null typeName for element : {0}", element.getName());
            }
        }
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GenericName(org.opengis.util.GenericName) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) QName(javax.xml.namespace.QName) LocalComplexType(org.geotoolkit.xsd.xml.v2001.LocalComplexType) ComplexType(org.geotoolkit.xsd.xml.v2001.ComplexType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole) OpenAttrs(org.geotoolkit.xsd.xml.v2001.OpenAttrs)

Example 4 with Schema

use of org.geotoolkit.xsd.xml.v2001.Schema in project geotoolkit by Geomatys.

the class JAXBFeatureTypeWriter method write.

/**
 * Write an XML representation of the specified featureType into the Writer.
 *
 * @param feature The featureType to marshall.
 */
public void write(FeatureType feature, Writer writer) throws JAXBException {
    final Schema schema = getSchemaFromFeatureType(feature);
    final Marshaller marshaller = POOL.acquireMarshaller();
    marshaller.marshal(schema, writer);
    POOL.recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) Schema(org.geotoolkit.xsd.xml.v2001.Schema)

Example 5 with Schema

use of org.geotoolkit.xsd.xml.v2001.Schema in project geotoolkit by Geomatys.

the class JAXBFeatureTypeWriter method fillSchemaWithFeatureType.

private void fillSchemaWithFeatureType(final FeatureType featureType, final Schema schema, boolean addTopElement, Set<String> alreadyWritten) {
    if (Utils.GML_FEATURE_TYPES.contains(featureType.getName())) {
        // this type is part of the standard GML types
        return;
    }
    // write parent types
    for (FeatureType parent : featureType.getSuperTypes()) {
        fillSchemaWithFeatureType(parent, schema, false, alreadyWritten);
    }
    final String typeNamespace = NamesExt.getNamespace(featureType.getName());
    final String elementName = featureType.getName().tip().toString();
    final String typeName = elementName + "Type";
    if (addTopElement) {
        final TopLevelElement topElement;
        if ("3.2.1".equals(gmlVersion)) {
            topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_321);
        } else {
            topElement = new TopLevelElement(elementName, new QName(typeNamespace, typeName), ABSTRACT_FEATURE_NAME_311);
        }
        schema.addElement(topElement);
    }
    boolean ar = alreadyWritten.add(typeName);
    final ExplicitGroup sequence = new ExplicitGroup();
    final List<Attribute> attributes = new ArrayList<>();
    for (final PropertyType pdesc : featureType.getProperties(false)) {
        if (AttributeConvention.contains(pdesc.getName())) {
            // skip convention properties
            continue;
        }
        writeProperty(pdesc, sequence, schema, attributes, alreadyWritten);
    }
    if (addTopElement && ar) {
        final ComplexContent content = getComplexContent(sequence);
        final TopLevelComplexType tlcType = new TopLevelComplexType(typeName, content);
        tlcType.getAttributeOrAttributeGroup().addAll(attributes);
        schema.addComplexType(1, tlcType);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) TopLevelElement(org.geotoolkit.xsd.xml.v2001.TopLevelElement) Attribute(org.geotoolkit.xsd.xml.v2001.Attribute) TopLevelComplexType(org.geotoolkit.xsd.xml.v2001.TopLevelComplexType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PropertyType(org.opengis.feature.PropertyType) ComplexContent(org.geotoolkit.xsd.xml.v2001.ComplexContent) ExplicitGroup(org.geotoolkit.xsd.xml.v2001.ExplicitGroup)

Aggregations

Test (org.junit.Test)57 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 QName (javax.xml.namespace.QName)21 AbstractMessage (com.google.protobuf.AbstractMessage)16 ByteString (com.google.protobuf.ByteString)16 File (java.io.File)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)14 ProjectName (com.google.pubsub.v1.ProjectName)14 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 IOException (java.io.IOException)13 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 ArrayList (java.util.ArrayList)11 JAXBElement (javax.xml.bind.JAXBElement)10 HashMap (java.util.HashMap)9 List (java.util.List)8