Search in sources :

Example 6 with SweTextEncoding

use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.

the class SweCommonDecoderV20 method decode.

@Override
public Object decode(Object element) throws DecodingException {
    if (element instanceof DataArrayPropertyType) {
        final DataArrayPropertyType dataArrayPropertyType = (DataArrayPropertyType) element;
        return parseAbstractDataComponent(dataArrayPropertyType.getDataArray1());
    } else if (element instanceof DataRecordPropertyType) {
        final DataRecordPropertyType dataRecordPropertyType = (DataRecordPropertyType) element;
        return parseAbstractDataComponent(dataRecordPropertyType.getDataRecord());
    } else if (element instanceof AbstractDataComponentDocument) {
        return parseAbstractDataComponentDocument((AbstractDataComponentDocument) element);
    } else if (element instanceof AbstractDataComponentType) {
        return parseAbstractDataComponent((AbstractDataComponentType) element);
    } else if (element instanceof Coordinate[]) {
        return parseCoordinates((Coordinate[]) element);
    } else if (element instanceof AnyScalarPropertyType[]) {
        return parseAnyScalarPropertyTypeArray((AnyScalarPropertyType[]) element);
    } else if (element instanceof TextEncodingDocument) {
        final TextEncodingDocument textEncodingDoc = (TextEncodingDocument) element;
        final SweTextEncoding sosTextEncoding = parseTextEncoding(textEncodingDoc.getTextEncoding());
        sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
        return sosTextEncoding;
    } else if (element instanceof TextEncodingType) {
        TextEncodingDocument textEncodingDoc = TextEncodingDocument.Factory.newInstance(getXmlOptions());
        TextEncodingType textEncoding = (TextEncodingType) element;
        textEncodingDoc.setTextEncoding(textEncoding);
        SweTextEncoding sosTextEncoding = parseTextEncoding(textEncoding);
        sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
        return sosTextEncoding;
    } else if (element instanceof TextPropertyType) {
        return parseAbstractDataComponent(((TextPropertyType) element).getText());
    } else if (element instanceof CountPropertyType) {
        return parseAbstractDataComponent(((CountPropertyType) element).getCount());
    } else if (element instanceof BooleanPropertyType) {
        return parseAbstractDataComponent(((BooleanPropertyType) element).getBoolean());
    } else if (element instanceof CategoryPropertyType) {
        return parseAbstractDataComponent(((CategoryPropertyType) element).getCategory());
    } else if (element instanceof QuantityPropertyType) {
        return parseAbstractDataComponent(((QuantityPropertyType) element).getQuantity());
    } else if (element instanceof DataStreamPropertyType) {
        return parseDataStream(((DataStreamPropertyType) element).getDataStream());
    } else if (element instanceof DataStreamType) {
        return parseDataStream((DataStreamType) element);
    } else if (element instanceof DataStreamDocument) {
        return parseDataStream(((DataStreamDocument) element).getDataStream());
    } else if (element instanceof XmlObject) {
        throw new UnsupportedDecoderXmlInputException(this, (XmlObject) element);
    } else {
        throw new UnsupportedDecoderInputException(this, element);
    }
}
Also used : TextEncodingDocument(net.opengis.swe.x20.TextEncodingDocument) DataStreamDocument(net.opengis.swe.x20.DataStreamDocument) AnyScalarPropertyType(net.opengis.swe.x20.AnyScalarPropertyType) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) AbstractDataComponentType(net.opengis.swe.x20.AbstractDataComponentType) TextEncodingType(net.opengis.swe.x20.TextEncodingType) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) Coordinate(net.opengis.swe.x20.VectorType.Coordinate) CountPropertyType(net.opengis.swe.x20.CountPropertyType) DataStreamType(net.opengis.swe.x20.DataStreamType) DataStreamPropertyType(net.opengis.swe.x20.DataStreamPropertyType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) TextPropertyType(net.opengis.swe.x20.TextPropertyType) AbstractDataComponentDocument(net.opengis.swe.x20.AbstractDataComponentDocument) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType)

Example 7 with SweTextEncoding

use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.

the class SweCommonEncoderv20 method createValues.

private XmlString createValues(List<List<String>> values, SweAbstractEncoding encoding) {
    // TODO How to deal with the decimal separator - is it an issue here?
    SweTextEncoding textEncoding = (SweTextEncoding) encoding;
    String valueString = values.stream().map(block -> String.join(textEncoding.getTokenSeparator(), block)).collect(joining(textEncoding.getBlockSeparator()));
    // create XB result object
    XmlString xmlString = XmlString.Factory.newInstance(getXmlOptions());
    xmlString.setStringValue(valueString);
    return xmlString;
}
Also used : OGCConstants(org.n52.shetland.ogc.OGCConstants) SweAllowedValues(org.n52.shetland.ogc.swe.simpleType.SweAllowedValues) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType) CategoryRangeDocument(net.opengis.swe.x20.CategoryRangeDocument) Arrays(java.util.Arrays) VectorType(net.opengis.swe.x20.VectorType) CountPropertyType(net.opengis.swe.x20.CountPropertyType) SosConstants(org.n52.shetland.ogc.sos.SosConstants) CountRangeType(net.opengis.swe.x20.CountRangeType) TimeDocument(net.opengis.swe.x20.TimeDocument) VectorPropertyType(net.opengis.swe.x20.VectorPropertyType) Show(org.n52.shetland.w3c.xlink.Show) Map(java.util.Map) BigInteger(java.math.BigInteger) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) VectorDocument(net.opengis.swe.x20.VectorDocument) SweAllowedTokens(org.n52.shetland.ogc.swe.simpleType.SweAllowedTokens) EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimeRangePropertyType(net.opengis.swe.x20.TimeRangePropertyType) TimeRangeType(net.opengis.swe.x20.TimeRangeType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) Actuate(org.n52.shetland.w3c.xlink.Actuate) Set(java.util.Set) Encoding(net.opengis.swe.x20.DataArrayType.Encoding) Collectors.joining(java.util.stream.Collectors.joining) BooleanDocument(net.opengis.swe.x20.BooleanDocument) SweAllowedTimes(org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes) NcName(org.n52.janmayen.NcName) TextEncodingType(net.opengis.swe.x20.TextEncodingType) SchemaLocation(org.n52.shetland.w3c.SchemaLocation) QuantityRangeDocument(net.opengis.swe.x20.QuantityRangeDocument) CategoryRangePropertyType(net.opengis.swe.x20.CategoryRangePropertyType) TimeType(net.opengis.swe.x20.TimeType) RangeValue(org.n52.shetland.ogc.swe.RangeValue) TimePropertyType(net.opengis.swe.x20.TimePropertyType) SmlPosition(org.n52.shetland.ogc.sensorML.elements.SmlPosition) SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) CountType(net.opengis.swe.x20.CountType) TextDocument(net.opengis.swe.x20.TextDocument) SwesConstants(org.n52.shetland.ogc.swes.SwesConstants) XmlHelper(org.n52.svalbard.util.XmlHelper) ArrayList(java.util.ArrayList) SweCategoryRange(org.n52.shetland.ogc.swe.simpleType.SweCategoryRange) QuantityType(net.opengis.swe.x20.QuantityType) DateTimeHelper(org.n52.shetland.util.DateTimeHelper) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) QuantityRangePropertyType(net.opengis.swe.x20.QuantityRangePropertyType) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) DataChoicePropertyType(net.opengis.swe.x20.DataChoicePropertyType) MatrixDocument(net.opengis.swe.x20.MatrixDocument) QuantityRangeType(net.opengis.swe.x20.QuantityRangeType) MatrixPropertyType(net.opengis.swe.x20.MatrixPropertyType) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) SweDataComponentVisitor(org.n52.shetland.ogc.swe.SweDataComponentVisitor) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) Coordinate(net.opengis.swe.x20.VectorType.Coordinate) UnitReference(net.opengis.swe.x20.UnitReference) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) ShowType(org.w3.x1999.xlink.ShowType) SweField(org.n52.shetland.ogc.swe.SweField) XmlException(org.apache.xmlbeans.XmlException) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) AbstractDataComponentType(net.opengis.swe.x20.AbstractDataComponentType) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) BooleanType(net.opengis.swe.x20.BooleanType) XmlString(org.apache.xmlbeans.XmlString) DataChoiceType(net.opengis.swe.x20.DataChoiceType) AllowedTokensPropertyType(net.opengis.swe.x20.AllowedTokensPropertyType) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) LoggerFactory(org.slf4j.LoggerFactory) DataArrayType(net.opengis.swe.x20.DataArrayType) TextEncodingDocument(net.opengis.swe.x20.TextEncodingDocument) SweAbstractEncoding(org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding) SweVector(org.n52.shetland.ogc.swe.SweVector) DataRecordType(net.opengis.swe.x20.DataRecordType) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) AllowedTimesType(net.opengis.swe.x20.AllowedTimesType) CountRangePropertyType(net.opengis.swe.x20.CountRangePropertyType) ActuateType(org.w3.x1999.xlink.ActuateType) UoM(org.n52.shetland.ogc.UoM) URI(java.net.URI) ConformanceClass(org.n52.svalbard.ConformanceClass) AllowedTokensType(net.opengis.swe.x20.AllowedTokensType) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) CategoryType(net.opengis.swe.x20.CategoryType) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) AllowedValuesType(net.opengis.swe.x20.AllowedValuesType) Collection(java.util.Collection) CategoryRangeType(net.opengis.swe.x20.CategoryRangeType) ConformanceClasses(org.n52.svalbard.ConformanceClasses) List(java.util.List) QualityPropertyType(net.opengis.swe.x20.QualityPropertyType) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) AllowedValuesPropertyType(net.opengis.swe.x20.AllowedValuesPropertyType) SmlFeatureOfInterest(org.n52.shetland.ogc.sensorML.v20.SmlFeatureOfInterest) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) AbstractEncodingType(net.opengis.swe.x20.AbstractEncodingType) DataRecordDocument(net.opengis.swe.x20.DataRecordDocument) QuantityDocument(net.opengis.swe.x20.QuantityDocument) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) Nillable(org.n52.shetland.w3c.Nillable) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) StreamingSweDataArray(org.n52.shetland.ogc.swe.stream.StreamingSweDataArray) SmlDataInterface(org.n52.shetland.ogc.sensorML.v20.SmlDataInterface) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) HashSet(java.util.HashSet) Referenceable(org.n52.shetland.w3c.xlink.Referenceable) AllowedTimesPropertyType(net.opengis.swe.x20.AllowedTimesPropertyType) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) TextPropertyType(net.opengis.swe.x20.TextPropertyType) SweConstants(org.n52.shetland.ogc.swe.SweConstants) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) XmlObject(org.apache.xmlbeans.XmlObject) TextType(net.opengis.swe.x20.TextType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) CountDocument(net.opengis.swe.x20.CountDocument) TimeRangeDocument(net.opengis.swe.x20.TimeRangeDocument) Logger(org.slf4j.Logger) DataChoiceDocument(net.opengis.swe.x20.DataChoiceDocument) DateTime(org.joda.time.DateTime) MatrixType(net.opengis.swe.x20.MatrixType) CategoryDocument(net.opengis.swe.x20.CategoryDocument) CountRangeDocument(net.opengis.swe.x20.CountRangeDocument) AbstractEncodingDocument(net.opengis.swe.x20.AbstractEncodingDocument) CodingHelper(org.n52.svalbard.util.CodingHelper) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Field(net.opengis.swe.x20.DataRecordType.Field) Collections(java.util.Collections) DataArrayDocument(net.opengis.swe.x20.DataArrayDocument) XmlString(org.apache.xmlbeans.XmlString) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) XmlString(org.apache.xmlbeans.XmlString)

Example 8 with SweTextEncoding

use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.

the class InsertResultTemplateRequestEncoderTest method setup.

@Before
public void setup() throws InvalidSridException, ParseException {
    SensorML procedure = new SensorML();
    procedure.setIdentifier(procedureIdentifier);
    SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
    featureOfInterest.setIdentifier(featureIdentifier);
    featureOfInterest.setName(new CodeType(featureName));
    featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
    featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT(30 10)", 4326));
    observationTemplate = new OmObservationConstellation();
    observationTemplate.addOffering(offering);
    observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
    observationTemplate.setProcedure(procedure);
    observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
    observationTemplate.setFeatureOfInterest(featureOfInterest);
    SweTextEncoding textEncoding = new SweTextEncoding();
    textEncoding.setBlockSeparator(blockSeparator);
    textEncoding.setTokenSeparator(tokenSeparator);
    SweDataRecord resultStructure = new SweDataRecord();
    SweTime sweTime = new SweTime();
    sweTime.setDefinition(field1Definition);
    sweTime.setUom(field1Uom);
    resultStructure.addField(new SweField(field1Name, sweTime));
    request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
    request.setResultEncoding(new SosResultEncoding(textEncoding));
    request.setResultStructure(new SosResultStructure(resultStructure));
    request.setIdentifier(templateIdentifier);
    request.setObservationTemplate(observationTemplate);
    Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
    encoder = new InsertResultTemplateRequestEncoder();
    encoder.setXmlOptions(xmlOptions);
    OmEncoderv20 omEncoder = new OmEncoderv20();
    omEncoder.setXmlOptions(xmlOptions);
    SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
    samsEncoder.setXmlOptions(xmlOptions);
    GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
    gml32Encoder.setXmlOptions(xmlOptions);
    SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
    sweEncoderv20.setXmlOptions(xmlOptions);
    EncoderRepository encoderRepository = new EncoderRepository();
    encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
    encoderRepository.init();
    encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) XmlOptions(org.apache.xmlbeans.XmlOptions) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SensorML(org.n52.shetland.ogc.sensorML.SensorML) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) CodeType(org.n52.shetland.ogc.gml.CodeType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Before(org.junit.Before)

Example 9 with SweTextEncoding

use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseTextEncoding.

private SweTextEncoding parseTextEncoding(final TextEncodingType textEncoding) {
    final SweTextEncoding sosTextEncoding = new SweTextEncoding();
    sosTextEncoding.setBlockSeparator(textEncoding.getBlockSeparator());
    sosTextEncoding.setTokenSeparator(textEncoding.getTokenSeparator());
    if (textEncoding.isSetDecimalSeparator()) {
        sosTextEncoding.setDecimalSeparator(textEncoding.getDecimalSeparator());
    }
    if (textEncoding.isSetCollapseWhiteSpaces()) {
        sosTextEncoding.setCollapseWhiteSpaces(textEncoding.getCollapseWhiteSpaces());
    }
    return sosTextEncoding;
}
Also used : SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding)

Example 10 with SweTextEncoding

use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseValues.

private List<List<String>> parseValues(final SweCount elementCount, final SweAbstractDataComponent elementType, final SweAbstractEncoding encoding, final EncodedValuesPropertyType encodedValuesPropertyType) throws DecodingException {
    if (checkParameterTypes(elementType, encoding)) {
        // Get swe values String via cursor as String
        String values;
        // TODO replace XmlCursor
        /*
             * if (encodedValuesPropertyType.schemaType() == XmlString.type) {
             * XmlString xbString
             */
        // @see SosDecoderv20#parseResultValues
        XmlCursor xbCursor = encodedValuesPropertyType.newCursor();
        xbCursor.toFirstContentToken();
        if (xbCursor.isText()) {
            values = xbCursor.getTextValue().trim();
            xbCursor.dispose();
            if (values != null && !values.isEmpty()) {
                SweTextEncoding textEncoding = (SweTextEncoding) encoding;
                String[] blocks = values.split(textEncoding.getBlockSeparator());
                List<List<String>> resultValues = new ArrayList<>(blocks.length);
                for (String block : blocks) {
                    String[] tokens = block.split(textEncoding.getTokenSeparator());
                    List<String> tokenList = Arrays.asList(tokens);
                    resultValues.add(tokenList);
                }
                return resultValues;
            }
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) List(java.util.List) ArrayList(java.util.ArrayList) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

SweTextEncoding (org.n52.shetland.ogc.swe.encoding.SweTextEncoding)13 XmlObject (org.apache.xmlbeans.XmlObject)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Lists (com.google.common.collect.Lists)2 BigInteger (java.math.BigInteger)2 URI (java.net.URI)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors.joining (java.util.stream.Collectors.joining)2 AbstractDataComponentType (net.opengis.swe.x20.AbstractDataComponentType)2 BooleanPropertyType (net.opengis.swe.x20.BooleanPropertyType)2 CategoryPropertyType (net.opengis.swe.x20.CategoryPropertyType)2 CountPropertyType (net.opengis.swe.x20.CountPropertyType)2 DataArrayPropertyType (net.opengis.swe.x20.DataArrayPropertyType)2 DataRecordPropertyType (net.opengis.swe.x20.DataRecordPropertyType)2 QuantityPropertyType (net.opengis.swe.x20.QuantityPropertyType)2 TextEncodingDocument (net.opengis.swe.x20.TextEncodingDocument)2