Search in sources :

Example 11 with Filter

use of org.n52.shetland.ogc.filter.Filter in project arctic-sea by 52North.

the class AbstractCapabilitiesBaseTypeDecoder method parseAddress.

private OwsAddress parseAddress(AddressType address) {
    if (address == null) {
        return null;
    }
    List<String> deliveryPoint = Optional.ofNullable(address.getDeliveryPointArray()).map(Arrays::stream).orElseGet(Stream::empty).map(Strings::emptyToNull).filter(Objects::nonNull).collect(toList());
    List<String> electronicMailAddress = Optional.ofNullable(address.getElectronicMailAddressArray()).map(Arrays::stream).orElseGet(Stream::empty).map(Strings::emptyToNull).filter(Objects::nonNull).collect(toList());
    String city = address.getCity();
    String administrativeArea = address.getAdministrativeArea();
    String postalCode = address.getPostalCode();
    String country = address.getCountry();
    return new OwsAddress(deliveryPoint, city, administrativeArea, postalCode, country, electronicMailAddress);
}
Also used : OwsAddress(org.n52.shetland.ogc.ows.OwsAddress) LocalizedString(org.n52.janmayen.i18n.LocalizedString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) OwsLanguageString(org.n52.shetland.ogc.ows.OwsLanguageString) Arrays(java.util.Arrays) Strings(com.google.common.base.Strings)

Example 12 with Filter

use of org.n52.shetland.ogc.filter.Filter in project arctic-sea by 52North.

the class SosDecoderv100 method parseGetObservation.

/**
 * parses the XmlBean representing the getObservation request and creates a
 * SoSGetObservation request
 *
 * @param getObsDoc
 *            XmlBean created from the incoming request stream
 * @return Returns SosGetObservationRequest representing the request
 *
 * @throws DecodingException
 *             * If parsing the XmlBean failed
 */
private OwsServiceRequest parseGetObservation(GetObservationDocument getObsDoc) throws DecodingException {
    GetObservationRequest getObsRequest = new GetObservationRequest();
    GetObservation getObs = getObsDoc.getGetObservation();
    getObsRequest.setService(getObs.getService());
    getObsRequest.setVersion(getObs.getVersion());
    getObsRequest.setOfferings(Arrays.asList(getObs.getOffering()));
    getObsRequest.setObservedProperties(Arrays.asList(getObs.getObservedPropertyArray()));
    getObsRequest.setProcedures(Arrays.asList(getObs.getProcedureArray()));
    getObsRequest.setTemporalFilters(parseTemporalFilters4GetObservation(getObs.getEventTimeArray()));
    getObsRequest.setSrsName(getObs.getSrsName());
    if (getObs.isSetFeatureOfInterest()) {
        FeatureOfInterest featureOfInterest = getObs.getFeatureOfInterest();
        if (featureOfInterest.isSetSpatialOps()) {
            Object filter = decodeXmlElement(featureOfInterest.getSpatialOps());
            if (filter instanceof SpatialFilter) {
                getObsRequest.setSpatialFilter((SpatialFilter) filter);
            }
        } else if (featureOfInterest.getObjectIDArray() != null) {
            Set<String> featureIdentifiers = Sets.newHashSet();
            for (String string : featureOfInterest.getObjectIDArray()) {
                featureIdentifiers.add(string);
            }
            getObsRequest.setFeatureIdentifiers(Lists.newArrayList(featureIdentifiers));
        }
    }
    // TODO implement result filtering
    if (getObs.isSetResult()) {
        throw new NotYetSupportedDecodingException("Result filtering");
    }
    // return error message
    if (getObs.isSetResponseFormat()) {
        getObsRequest.setResponseFormat(decodeResponseFormat(getObs.getResponseFormat()));
    } else {
        getObsRequest.setResponseFormat(OmConstants.CONTENT_TYPE_OM.toString());
    }
    if (getObs.isSetResultModel()) {
        getObsRequest.setResultModel(OMHelper.getObservationTypeFor(getObs.getResultModel()));
    }
    return getObsRequest;
}
Also used : GetObservation(net.opengis.sos.x10.GetObservationDocument.GetObservation) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) Set(java.util.Set) GetFeatureOfInterest(net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest) FeatureOfInterest(net.opengis.sos.x10.GetObservationDocument.GetObservation.FeatureOfInterest) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) NotYetSupportedDecodingException(org.n52.svalbard.decode.exception.NotYetSupportedDecodingException)

Example 13 with Filter

use of org.n52.shetland.ogc.filter.Filter in project arctic-sea by 52North.

the class FesDecoderv20 method parsePropertyIsBetweenFilter.

/**
 * Parse XML propertyIsBetween element
 *
 * @param comparisonOpsType
 *            XML propertyIsBetween element
 * @return SOS comparison filter
 * @throws DecodingException
 *             If an error occurs of the filter is not supported
 */
private ComparisonFilter parsePropertyIsBetweenFilter(PropertyIsBetweenType comparisonOpsType) throws DecodingException {
    ComparisonFilter comparisonFilter = new ComparisonFilter();
    comparisonFilter.setOperator(ComparisonOperator.PropertyIsBetween);
    try {
        comparisonFilter.setValueReference(parseValueReference(comparisonOpsType.getExpression()));
    } catch (XmlException xmle) {
        throw valueReferenceParsingException(xmle);
    }
    if (comparisonOpsType.getLowerBoundary().getExpression() instanceof LiteralType) {
        comparisonFilter.setValue(parseLiteralValue((LiteralType) comparisonOpsType.getLowerBoundary().getExpression()));
    }
    if (comparisonOpsType.getUpperBoundary().getExpression() instanceof LiteralType) {
        comparisonFilter.setValueUpper(parseLiteralValue((LiteralType) comparisonOpsType.getUpperBoundary().getExpression()));
    }
    return comparisonFilter;
}
Also used : ComparisonFilter(org.n52.shetland.ogc.filter.ComparisonFilter) XmlException(org.apache.xmlbeans.XmlException) LiteralType(net.opengis.fes.x20.LiteralType)

Example 14 with Filter

use of org.n52.shetland.ogc.filter.Filter in project arctic-sea by 52North.

the class FesDecoderv20 method parseSpatialFilterType.

/**
 * Parses the spatial filter of a request.
 *
 * @param xbSpatialOpsType
 *            XmlBean representing the feature of interest parameter of the
 *            request
 * @return Returns SpatialFilter created from the passed foi request
 *         parameter
 *
 * @throws DecodingException
 *             * if creation of the SpatialFilter failed
 */
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    try {
        if (xbSpatialOpsType instanceof BBOXType) {
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
            if (isValueReferenceExpression(xbBBOX.getExpression())) {
                spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
            }
            XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
            if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
                Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
                if (sosGeometry instanceof Geometry) {
                    spatialFilter.setGeometry((Geometry) sosGeometry);
                } else if (sosGeometry instanceof ReferencedEnvelope) {
                    spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
                } else {
                    throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
                }
            } else {
                throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
            }
            geometryCursor.dispose();
        } else {
            throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing spatial filter!", xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) BBOXType(net.opengis.fes.x20.BBOXType) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 15 with Filter

use of org.n52.shetland.ogc.filter.Filter in project arctic-sea by 52North.

the class OgcDecoderv100 method parseTemporalOperatorType.

/**
 * parses a single temporal filter of the requests and returns SOS temporal filter
 *
 * @param xbBinaryTemporalOp XmlObject representing the temporal filter
 *
 * @return Returns SOS representation of temporal filter
 *
 * @throws DecodingException if parsing of the element failed
 */
private Object parseTemporalOperatorType(BinaryTemporalOpType xbBinaryTemporalOp) throws DecodingException {
    TemporalFilter temporalFilter = new TemporalFilter();
    // FIXME local workaround against SOSHelper check value reference
    String valueRef = "phenomenonTime";
    try {
        NodeList nodes = xbBinaryTemporalOp.getDomNode().getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
                // GML decoder will return TimeInstant or TimePriod
                Object timeObject = decodeXmlElement(XmlObject.Factory.parse(nodes.item(i)));
                if (timeObject instanceof PropertyNameType) {
                    PropertyNameType propType = (PropertyNameType) timeObject;
                // TODO here apply logic for ogc property
                // om:samplingTime etc
                // valueRef = propType.getDomNode().getNodeValue();
                }
                if (timeObject instanceof Time) {
                    TimeOperator operator;
                    Time time = (Time) timeObject;
                    String localName = XmlHelper.getLocalName(xbBinaryTemporalOp);
                    // change to SOS 1.0. TMDuring kind of
                    if (localName.equals(TimeOperator.TM_During.name()) && time instanceof TimePeriod) {
                        operator = TimeOperator.TM_During;
                    } else if (localName.equals(TimeOperator.TM_Equals.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_Equals;
                    } else if (localName.equals(TimeOperator.TM_After.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_After;
                    } else if (localName.equals(TimeOperator.TM_Before.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_Before;
                    } else {
                        throw unsupportedTemporalFilterOperand();
                    }
                    temporalFilter.setOperator(operator);
                    temporalFilter.setTime(time);
                    // actually it should be eg om:samplingTime
                    temporalFilter.setValueReference(valueRef);
                    break;
                }
            }
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing temporal filter!", xmle);
    }
    return temporalFilter;
}
Also used : TimeOperator(org.n52.shetland.ogc.filter.FilterConstants.TimeOperator) TemporalFilter(org.n52.shetland.ogc.filter.TemporalFilter) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlException(org.apache.xmlbeans.XmlException) NodeList(org.w3c.dom.NodeList) XmlObject(org.apache.xmlbeans.XmlObject) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) PropertyNameType(net.opengis.ogc.PropertyNameType)

Aggregations

Test (org.junit.Test)10 SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)10 XmlObject (org.apache.xmlbeans.XmlObject)9 ComparisonFilter (org.n52.shetland.ogc.filter.ComparisonFilter)9 XmlException (org.apache.xmlbeans.XmlException)6 DecodingException (org.n52.svalbard.decode.exception.DecodingException)6 URI (java.net.URI)3 Objects (java.util.Objects)3 Set (java.util.Set)3 BinaryTemporalOpType (net.opengis.fes.x20.BinaryTemporalOpType)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 LocalizedString (org.n52.janmayen.i18n.LocalizedString)3 MultilingualString (org.n52.janmayen.i18n.MultilingualString)3 TimeOperator (org.n52.shetland.ogc.filter.FilterConstants.TimeOperator)3 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)3 OwsDomain (org.n52.shetland.ogc.ows.OwsDomain)3 OwsLanguageString (org.n52.shetland.ogc.ows.OwsLanguageString)3 OwsMetadata (org.n52.shetland.ogc.ows.OwsMetadata)3 Strings (com.google.common.base.Strings)2 Arrays (java.util.Arrays)2