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);
}
}
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();
}
}
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;
}
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);
}
}
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);
}
Aggregations