Search in sources :

Example 36 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class UpdateSensorRequestDecoder method parseProcedureDesciption.

private SosProcedureDescription<?> parseProcedureDesciption(String xml, String pdf) throws DecodingException {
    try {
        final XmlObject xb = XmlObject.Factory.parse(xml);
        Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(pdf, xb.getClass()));
        if (decoder == null) {
            throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
        }
        Object decode = decoder.decode(xb);
        if (decode instanceof SosProcedureDescription<?>) {
            return (SosProcedureDescription<?>) decode;
        } else if (decode instanceof AbstractFeature) {
            return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
        } else {
            throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
}
Also used : XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 37 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class JSONDecoder method decodeJsonToObjectList.

protected <T> List<T> decodeJsonToObjectList(JsonNode node, Class<T> type) throws DecodingException {
    Decoder<T, JsonNode> decoder = getDecoder(type);
    if (node.isArray()) {
        CompositeException exceptions = new CompositeException();
        List<T> list = Streams.stream(node).filter(JsonNode::isObject).map(exceptions.wrapFunction(decoder::decode)).filter(Optional::isPresent).map(Optional::get).collect(toList());
        exceptions.throwIfNotEmpty(DecodingException::new);
        return list;
    } else if (node.isObject()) {
        return Collections.singletonList(decoder.decode(node));
    } else {
        return Collections.emptyList();
    }
}
Also used : Optional(java.util.Optional) CompositeException(org.n52.janmayen.exception.CompositeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 38 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class JSONDecoder method getDecoder.

private <T> Decoder<T, JsonNode> getDecoder(Class<T> type) throws DecodingException {
    JsonDecoderKey key = new JsonDecoderKey(type);
    Decoder<T, JsonNode> decoder = getDecoder(key);
    if (decoder == null) {
        throw new NoDecoderForKeyException(key);
    }
    return decoder;
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) JsonDecoderKey(org.n52.svalbard.decode.JsonDecoderKey) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 39 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class AbstractStatisticsServiceEventListener method handle.

@Override
public void handle(Event serviceEvent) {
    LOG.debug("Event received: {}", serviceEvent);
    if (!dataHandler.isLoggingEnabled()) {
        return;
    }
    try {
        if (serviceEvent instanceof AbstractFlowEvent) {
            List<AbstractFlowEvent> eventList;
            AbstractFlowEvent evt = (AbstractFlowEvent) serviceEvent;
            // empty the list on the first event of the given group id
            if (serviceEvent instanceof RequestEvent) {
                eventList = new ArrayList<>(EVENTS_ARR_SIZE);
                eventsCache.put(evt.getMessageGroupId(), eventList);
            }
            // fall back
            if (eventsCache.get(evt.getMessageGroupId()) == null) {
                eventList = new ArrayList<>(EVENTS_ARR_SIZE);
                eventsCache.put(evt.getMessageGroupId(), eventList);
            }
            eventsCache.get(evt.getMessageGroupId()).add(evt);
            // received last event process eventsResolvers on a new thread
            if (serviceEvent instanceof OutgoingResponseEvent) {
                BatchResolver resolvers = new BatchResolver(dataHandler);
                eventsCache.get(evt.getMessageGroupId()).stream().forEach(l -> addEventToResolver(resolvers, l));
                executorService.execute(resolvers);
            }
        } else {
            LOG.trace("Unssupported type of event: {}", serviceEvent.getClass());
            BatchResolver singleOp = new BatchResolver(dataHandler);
            addEventToResolver(singleOp, serviceEvent);
            executorService.execute(singleOp);
        }
    } catch (Throwable e) {
        LOG.error("Can't handle event for statistics logging: {}", serviceEvent, e);
    }
}
Also used : RequestEvent(org.n52.iceland.event.events.RequestEvent) AbstractFlowEvent(org.n52.iceland.event.events.AbstractFlowEvent) OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Example 40 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class JsonSettingsDao method createSettingValue.

protected SettingValue<?> createSettingValue(String key, JsonNode node) {
    SettingType type = SettingType.fromString(node.path(JSONSettingConstants.TYPE_KEY).asText(null));
    Object value = decodeValue(type, node.path(JSONSettingConstants.VALUE_KEY));
    return new JsonSettingValue<>(type, key, value);
}
Also used : SettingType(org.n52.faroe.SettingType)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)27 DecodingException (org.n52.svalbard.decode.exception.DecodingException)15 Actuate (org.n52.shetland.w3c.xlink.Actuate)14 Reference (org.n52.shetland.w3c.xlink.Reference)14 Show (org.n52.shetland.w3c.xlink.Show)14 Type (org.n52.shetland.w3c.xlink.Type)14 ActuateType (org.w3.x1999.xlink.ActuateType)14 ShowType (org.w3.x1999.xlink.ShowType)14 TypeType (org.w3.x1999.xlink.TypeType)14 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)13 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)10 CodeType (net.opengis.gml.x32.CodeType)10 EXExtentType (org.isotc211.x2005.gmd.EXExtentType)10 Test (org.junit.Test)10 XmlException (org.apache.xmlbeans.XmlException)9 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)9 CIResponsiblePartyPropertyType (org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType)8 CIResponsiblePartyType (org.isotc211.x2005.gmd.CIResponsiblePartyType)8 BaseUnitType (net.opengis.gml.x32.BaseUnitType)6 SupportedType (org.n52.shetland.ogc.SupportedType)6