use of net.opengis.sos.x20.InsertObservationDocument in project arctic-sea by 52North.
the class SosDecoderv20 method parseInsertObservation.
private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
// set namespace for default XML type (e.g. xs:string, xs:integer,
// xs:boolean, ...)
// Fix for problem with XmlBeans: namespace is not set in child elements
// when defined in root of request (SOAP)
final XmlCursor cursor = insertObservationDoc.newCursor();
if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
cursor.prefixForNamespace(W3CConstants.NS_XS);
}
cursor.dispose();
final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
insertObservationRequest.setService(insertObservationType.getService());
insertObservationRequest.setVersion(insertObservationType.getVersion());
if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
}
insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
if (insertObservationType.getObservationArray() != null) {
final int length = insertObservationType.getObservationArray().length;
final Map<String, Time> phenomenonTimes = new HashMap<>(length);
final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
final Map<String, AbstractFeature> features = new HashMap<>(length);
CompositeException exceptions = new CompositeException();
for (final Observation observation : insertObservationType.getObservationArray()) {
final Object decodedObject = decodeXmlElement(observation.getOMObservation());
if (decodedObject instanceof OmObservation) {
final OmObservation sosObservation = (OmObservation) decodedObject;
checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
insertObservationRequest.addObservation(sosObservation);
} else {
exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
}
}
checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
try {
exceptions.throwIfNotEmpty();
} catch (CompositeException ex) {
throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
}
} else {
// TODO MissingMandatoryParameterException?
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
}
return insertObservationRequest;
}
use of net.opengis.sos.x20.InsertObservationDocument in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method shouldEncodeSwesExtensions.
@Test
public void shouldEncodeSwesExtensions() throws InvalidSridException, ParseException, EncodingException, DecodingException {
String definition = Sos2Constants.Extensions.SplitDataArrayIntoObservations.name();
boolean value = true;
SweBoolean sweBoolean = new SweBoolean();
sweBoolean.setValue(value);
sweBoolean.setDefinition(definition);
SwesExtension<SweBoolean> swesExtension = new SwesExtension<>();
swesExtension.setValue(sweBoolean);
InsertObservationRequest request = createInsertObservationRequest();
request.addExtension(swesExtension);
XmlObject encodedRequest = encoder.create(request);
encodedRequest.xmlText();
XmlHelper.validateDocument(encodedRequest);
InsertObservationType insertObservation = ((InsertObservationDocument) encodedRequest).getInsertObservation();
Assert.assertThat(insertObservation.sizeOfExtensionArray(), Is.is(1));
XmlObject xbExtension = insertObservation.getExtensionArray(0);
Assert.assertThat(xbExtension, Matchers.instanceOf(BooleanPropertyType.class));
BooleanType xbBoolean = ((BooleanPropertyType) xbExtension).getBoolean();
Assert.assertThat(xbBoolean.getDefinition(), Is.is(definition));
Assert.assertThat(xbBoolean.getValue(), Is.is(value));
// no check for observation values, because that MUST be part of OmEncoderv20Test
}
use of net.opengis.sos.x20.InsertObservationDocument in project arctic-sea by 52North.
the class InsertObservationRequestEncoder method create.
@Override
protected XmlObject create(InsertObservationRequest request) throws EncodingException {
validateInput(request);
InsertObservationDocument doc = InsertObservationDocument.Factory.newInstance(getXmlOptions());
InsertObservationType insertObservation = doc.addNewInsertObservation();
insertObservation.setService(request.getService());
insertObservation.setVersion(request.getVersion());
addExtensions(request.getExtensions(), insertObservation);
addOfferings(request.getOfferings(), insertObservation);
addObservations(request.getObservations(), insertObservation);
return doc;
}
use of net.opengis.sos.x20.InsertObservationDocument in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method shouldEncodeInsertObservationRequest.
@Test
public void shouldEncodeInsertObservationRequest() throws EncodingException, InvalidSridException, ParseException, DecodingException {
InsertObservationRequest request = createInsertObservationRequest();
XmlObject encodedRequest = encoder.create(request);
XmlHelper.validateDocument(encodedRequest);
Assert.assertThat(encodedRequest, Matchers.notNullValue());
Assert.assertThat(encodedRequest, Matchers.instanceOf(InsertObservationDocument.class));
InsertObservationType insertObservation = ((InsertObservationDocument) encodedRequest).getInsertObservation();
Assert.assertThat(insertObservation.getOfferingArray(), Matchers.notNullValue());
Assert.assertThat(insertObservation.getOfferingArray().length, Is.is(1));
Assert.assertThat(insertObservation.getOfferingArray(0), Is.is(OFFERING_ID));
Assert.assertThat(insertObservation.getObservationArray(), Matchers.notNullValue());
Assert.assertThat(insertObservation.getObservationArray().length, Is.is(1));
// no check for observation values, because that MUST be part of OmEncoderv20Test
}
Aggregations