Search in sources :

Example 56 with OwsExceptionReport

use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.

the class OwsExceptionReportDecoder method decode.

private OwsExceptionReport decode(ExceptionReport report) {
    String version = report.getVersion();
    ExceptionType[] exceptionTypes = report.getExceptionArray();
    List<CodedException> exceptions = Streams.stream(exceptionTypes).map(this::decode).collect(toList());
    return new CompositeOwsException(exceptions).setVersion(version);
}
Also used : ExceptionType(net.opengis.ows.x11.ExceptionType) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) CompositeOwsException(org.n52.shetland.ogc.ows.exception.CompositeOwsException)

Example 57 with OwsExceptionReport

use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport 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 58 with OwsExceptionReport

use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.

the class OwsEncoderv110 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    if (element instanceof OwsServiceIdentification) {
        return encodeServiceIdentification((OwsServiceIdentification) element);
    } else if (element instanceof OwsServiceProvider) {
        return encodeServiceProvider((OwsServiceProvider) element);
    } else if (element instanceof OwsOperationsMetadata) {
        return encodeOperationsMetadata((OwsOperationsMetadata) element);
    } else if (element instanceof OwsExceptionReport) {
        if (isEncodeExceptionsOnly(additionalValues) && !((OwsExceptionReport) element).getExceptions().isEmpty()) {
            return encodeOwsException(((OwsExceptionReport) element).getExceptions().get(0));
        }
        return encodeOwsExceptionReport((OwsExceptionReport) element);
    } else if (element instanceof OwsMetadata) {
        MetadataType metadataType = MetadataType.Factory.newInstance(getXmlOptions());
        encodeOwsMetadata((OwsMetadata) element, metadataType);
        return metadataType;
    } else if (element instanceof OwsDomain) {
        DomainType domainType = DomainType.Factory.newInstance(getXmlOptions());
        encodeOwsDomain((OwsDomain) element, domainType);
        return domainType;
    } else if (element instanceof OwsAcceptVersions) {
        return encodeAcceptVersions((OwsAcceptVersions) element);
    } else if (element instanceof OwsSections) {
        return encodeSections((OwsSections) element);
    }
    throw new UnsupportedEncoderInputException(this, element);
}
Also used : OwsDomain(org.n52.shetland.ogc.ows.OwsDomain) DomainType(net.opengis.ows.x11.DomainType) OwsOperationsMetadata(org.n52.shetland.ogc.ows.OwsOperationsMetadata) OwsMetadata(org.n52.shetland.ogc.ows.OwsMetadata) OwsSections(org.n52.shetland.ogc.ows.OwsSections) OwsServiceProvider(org.n52.shetland.ogc.ows.OwsServiceProvider) MetadataType(net.opengis.ows.x11.MetadataType) DomainMetadataType(net.opengis.ows.x11.DomainMetadataType) OwsServiceIdentification(org.n52.shetland.ogc.ows.OwsServiceIdentification) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OwsAcceptVersions(org.n52.shetland.ogc.ows.OwsAcceptVersions) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 59 with OwsExceptionReport

use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.

the class OwsExceptionReportEncoder method encodeJSON.

@Override
public JsonNode encodeJSON(OwsExceptionReport t) throws JSONEncodingException {
    final ObjectNode exceptionReport = Json.nodeFactory().objectNode();
    exceptionReport.put(JSONConstants.VERSION, t.getVersion());
    final ArrayNode exceptions = exceptionReport.putArray(JSONConstants.EXCEPTIONS);
    for (CodedException ce : t.getExceptions()) {
        final ObjectNode exception = exceptions.addObject();
        exception.put(JSONConstants.CODE, ce.getCode() != null ? ce.getCode().toString() : OwsExceptionCode.NoApplicableCode.toString());
        if (ce.getLocator() != null && !ce.getLocator().isEmpty()) {
            exception.put(JSONConstants.LOCATOR, ce.getLocator());
        }
        final String message = getExceptionText(ce);
        if (message != null && !message.isEmpty()) {
            exception.put(JSONConstants.TEXT, message);
        }
        if (log.isDebugEnabled()) {
            exception.set(STACK_TRACE, encodeStackTrace(ce));
        }
    }
    return exceptionReport;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 60 with OwsExceptionReport

use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.

the class GmlV321EncoderTest method isMeasureTypeValidAllSetTest.

@Test
public void isMeasureTypeValidAllSetTest() throws OwsExceptionReport, EncodingException {
    QuantityValue quantity = new QuantityValue(2.2);
    quantity.setUnit("cm");
    XmlObject encode = encoder.encode(quantity);
    assertTrue("Encoded Object is NOT valid", encode.validate());
}
Also used : QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Aggregations

OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)27 EncodingException (org.n52.svalbard.encode.exception.EncodingException)14 Test (org.junit.Test)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)9 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)8 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)8 XmlObject (org.apache.xmlbeans.XmlObject)7 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)7 IOException (java.io.IOException)6 DateTime (org.joda.time.DateTime)6 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)6 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)5 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)5 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)5 LinkedList (java.util.LinkedList)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)4 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3