Search in sources :

Example 1 with CollectionType

use of io.atlasmap.v2.CollectionType in project atlasmap by atlasmap.

the class SchemaInspector method printParticle.

private void printParticle(XSParticle particle, String rootName, XmlComplexType xmlComplexType) throws Exception {
    XSTerm term = particle.getTerm();
    if (term.isModelGroup()) {
        XSModelGroup group = term.asModelGroup();
        printGroup(group, rootName, xmlComplexType);
    } else if (term.isModelGroupDecl()) {
        printGroupDecl(term.asModelGroupDecl(), rootName, xmlComplexType);
    } else if (term.isElementDecl()) {
        CollectionType collectionType = getCollectionType(particle);
        printElement(term.asElementDecl(), rootName, xmlComplexType, collectionType);
    }
}
Also used : XSTerm(com.sun.xml.xsom.XSTerm) CollectionType(io.atlasmap.v2.CollectionType) XSModelGroup(com.sun.xml.xsom.XSModelGroup)

Example 2 with CollectionType

use of io.atlasmap.v2.CollectionType in project atlasmap by atlasmap.

the class XmlSchemaInspector method printParticle.

private void printParticle(XSParticle particle, XmlComplexType parentXmlComplexType, Set<String> cachedComplexType) throws Exception {
    XSTerm term = particle.getTerm();
    if (term.isModelGroup()) {
        XSModelGroup group = term.asModelGroup();
        printGroup(group, parentXmlComplexType, cachedComplexType);
    } else if (term.isModelGroupDecl()) {
        printGroupDecl(term.asModelGroupDecl(), parentXmlComplexType, cachedComplexType);
    } else if (term.isElementDecl()) {
        CollectionType collectionType = getCollectionType(particle);
        printElement(term.asElementDecl(), parentXmlComplexType, collectionType, cachedComplexType);
    }
}
Also used : XSTerm(com.sun.xml.xsom.XSTerm) CollectionType(io.atlasmap.v2.CollectionType) XSModelGroup(com.sun.xml.xsom.XSModelGroup)

Example 3 with CollectionType

use of io.atlasmap.v2.CollectionType in project arctic-sea by 52North.

the class AbstractWmlEncoderv20 method createWmlGetObservationResponse.

/**
 * Encodes a SOS GetObservationResponse to a single WaterML 2.0 observation
 * or to a WaterML 1.0 ObservationCollection
 *
 * @param getObservationResonse
 *            SOS GetObservationResponse
 * @return Encoded response
 * @throws EncodingException
 *             If an error occurs
 */
protected XmlObject createWmlGetObservationResponse(GetObservationResponse getObservationResonse) throws EncodingException {
    // TODO: set schemaLocation if final
    Map<CodeWithAuthority, String> gmlID4sfIdentifier = Maps.newHashMap();
    int sfIdCounter = 1;
    try {
        if (getObservationResonse.getObservationCollection() != null && !getObservationResonse.getObservationCollection().hasNext()) {
            ObservationStream observations = getObservationResonse.getObservationCollection();
            OmObservation observation = observations.next();
            if (!observations.hasNext()) {
                OMObservationDocument omObservationDoc = OMObservationDocument.Factory.newInstance(getXmlOptions());
                omObservationDoc.setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
                sfIdCounter++;
                return omObservationDoc;
            } else {
                CollectionDocument xmlCollectionDoc = CollectionDocument.Factory.newInstance(getXmlOptions());
                CollectionType wmlCollection = xmlCollectionDoc.addNewCollection();
                wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observation, gmlID4sfIdentifier, sfIdCounter));
                sfIdCounter++;
                while (observations.hasNext()) {
                    wmlCollection.addNewObservationMember().setOMObservation(encodeObservation(observations.next(), gmlID4sfIdentifier, sfIdCounter));
                    sfIdCounter++;
                }
                return xmlCollectionDoc;
            }
        } else {
            // TODO: HydrologieProfile-Exception
            throw new EncodingException("Combination does not exists!");
        }
    } catch (NoSuchElementException | OwsExceptionReport e) {
        throw new EncodingException(e);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) CollectionDocument(net.opengis.waterml.x20.CollectionDocument) OmObservation(org.n52.shetland.ogc.om.OmObservation) OMObservationDocument(net.opengis.om.x20.OMObservationDocument) WmlMonitoringPoint(org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) CollectionType(net.opengis.waterml.x20.CollectionType) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with CollectionType

use of io.atlasmap.v2.CollectionType in project atlasmap by atlasmap.

the class GenerateInspectionsMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (getOutputDir() != null) {
        getOutputDir().mkdirs();
    }
    CollectionType collectionType = CollectionType.NONE;
    if (this.collectionType != null) {
        collectionType = CollectionType.valueOf(this.collectionType);
    }
    if (this.artifacts != null && this.className != null) {
        generateJavaInspection(this.artifacts, Arrays.asList(className), collectionType, collectionClassName);
    }
    if (inspections != null) {
        for (Inspection inspection : inspections) {
            ArrayList<String> classNames = new ArrayList<>();
            if (inspection.classNames != null) {
                classNames.addAll(inspection.classNames);
            } else if (inspection.className != null) {
                classNames.add(inspection.className);
            } else {
                generateFileInspection(inspection);
            }
            collectionType = CollectionType.NONE;
            if (inspection.collectionType != null) {
                collectionType = CollectionType.valueOf(inspection.collectionType);
            }
            generateJavaInspection(inspection.artifacts, classNames, collectionType, inspection.collectionClassName);
        }
    }
}
Also used : CollectionType(io.atlasmap.v2.CollectionType) ArrayList(java.util.ArrayList)

Example 5 with CollectionType

use of io.atlasmap.v2.CollectionType in project atlasmap by atlasmap.

the class KafkaConnectInspector method populateFields.

private List<KafkaConnectField> populateFields(List<org.apache.kafka.connect.data.Field> kcFields, AtlasPath parentPath) {
    List<KafkaConnectField> answer = new ArrayList<>();
    for (org.apache.kafka.connect.data.Field connectField : kcFields) {
        KafkaConnectField field;
        AtlasPath path = parentPath.clone();
        CollectionType collectionType = CollectionType.NONE;
        Schema connectSchema = connectField.schema();
        if (Type.ARRAY == connectSchema.type()) {
            path.appendField(connectField.name() + AtlasPath.PATH_LIST_SUFFIX);
            collectionType = CollectionType.LIST;
            connectSchema = connectSchema.valueSchema();
        } else if (Type.MAP == connectSchema.type()) {
            path.appendField(connectField.name() + AtlasPath.PATH_MAP_SUFFIX);
            collectionType = CollectionType.MAP;
            connectSchema = connectSchema.valueSchema();
        } else {
            path.appendField(connectField.name());
        }
        if (connectSchema.parameters() != null) {
            KafkaConnectComplexType complex = AtlasKafkaConnectModelFactory.createKafkaConnectComplexType();
            complex.setKafkaConnectEnumFields(new KafkaConnectEnumFields());
            complex.setEnumeration(true);
            List<KafkaConnectEnumField> symbols = complex.getKafkaConnectEnumFields().getKafkaConnectEnumField();
            boolean first = true;
            for (Entry<String, String> entry : connectSchema.parameters().entrySet()) {
                // FIXME dirty hack - it seems the first entry is for some control, the others are the actual values
                if (first) {
                    first = false;
                    continue;
                }
                KafkaConnectEnumField f = new KafkaConnectEnumField();
                f.setName(entry.getValue());
                symbols.add(f);
            }
            field = complex;
        } else if (connectSchema.type().isPrimitive()) {
            field = AtlasKafkaConnectModelFactory.createKafkaConnectField();
            field.setFieldType(KafkaConnectUtil.getFieldType(connectSchema.type()));
        } else {
            KafkaConnectComplexType complex = AtlasKafkaConnectModelFactory.createKafkaConnectComplexType();
            List<KafkaConnectField> children = populateFields(connectSchema.fields(), path);
            if ("io.confluent.connect.avro.Union".equals(connectSchema.name())) {
                // We don't support union until it's built into Kafka Connect Schema
                complex.setStatus(FieldStatus.UNSUPPORTED);
            }
            complex.getKafkaConnectFields().getKafkaConnectField().addAll(children);
            field = complex;
        }
        field.setName(connectField.name());
        field.setPath(path.toString());
        field.setCollectionType(collectionType);
        answer.add(field);
    }
    return answer;
}
Also used : KafkaConnectComplexType(io.atlasmap.kafkaconnect.v2.KafkaConnectComplexType) KafkaConnectEnumFields(io.atlasmap.kafkaconnect.v2.KafkaConnectEnumFields) Schema(org.apache.kafka.connect.data.Schema) ArrayList(java.util.ArrayList) CollectionType(io.atlasmap.v2.CollectionType) AtlasPath(io.atlasmap.core.AtlasPath) KafkaConnectEnumField(io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField) ArrayList(java.util.ArrayList) List(java.util.List) KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField)

Aggregations

CollectionType (io.atlasmap.v2.CollectionType)7 AtlasException (io.atlasmap.api.AtlasException)3 ArrayList (java.util.ArrayList)3 XSModelGroup (com.sun.xml.xsom.XSModelGroup)2 XSTerm (com.sun.xml.xsom.XSTerm)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2 ActionProcessor (io.atlasmap.spi.ActionProcessor)2 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)2 AtlasFieldAction (io.atlasmap.spi.AtlasFieldAction)2 Action (io.atlasmap.v2.Action)2 ActionDetail (io.atlasmap.v2.ActionDetail)2 CustomAction (io.atlasmap.v2.CustomAction)2 List (java.util.List)2 AtlasPath (io.atlasmap.core.AtlasPath)1 JavaFieldWriter (io.atlasmap.java.core.JavaFieldWriter)1 KafkaConnectComplexType (io.atlasmap.kafkaconnect.v2.KafkaConnectComplexType)1 KafkaConnectEnumField (io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField)1 KafkaConnectEnumFields (io.atlasmap.kafkaconnect.v2.KafkaConnectEnumFields)1 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)1 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1