use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class AqdEncoder method encodeGetObservationResponse.
private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
try {
FeatureCollection featureCollection = getFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
OmObservation observation = observationCollection.next();
if (observation.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) observation.getValue();
if (value instanceof StreamingValue) {
value = value.merge();
}
while (value.hasNext()) {
processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
} else {
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
try {
FeatureCollection featureCollection = createFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
return encodeGml(ctx, featureCollection);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method addToFeatureCollectionAndGetTimePeriod.
private TimePeriod addToFeatureCollectionAndGetTimePeriod(FeatureCollection featureCollection, GetObservationResponse response, EReportingHeader eReportingHeader) throws OwsExceptionReport {
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
TimePeriod timePeriod = new TimePeriod();
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
return timePeriod;
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class SensorMLEncoderv101 method addAbstractProcessValues.
// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
if (sosAbstractProcess.isSetGmlID()) {
abstractProcess.setId(sosAbstractProcess.getGmlId());
}
if (sosAbstractProcess.isSetCapabilities()) {
final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
for (final Capabilities element : existing) {
if (element.getName() != null) {
names.add(element.getName());
}
}
for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
final Capabilities c = createCapability(sosCapability);
// replace existing capability with the same name
if (names.contains(c.getName())) {
removeCapability(abstractProcess, c);
}
abstractProcess.addNewCapabilities().set(c);
}
}
// set description
if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
}
if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
// TODO check if override existing names
addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
}
// set identification
if (sosAbstractProcess.isSetIdentifications()) {
abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
}
// set classification
if (sosAbstractProcess.isSetClassifications()) {
abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
}
// set characteristics
if (sosAbstractProcess.isSetCharacteristics()) {
abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
}
// set documentation
if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
}
// process
if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
ContactList contactList = createContactList(sosAbstractProcess.getContact());
if (contactList != null && contactList.getMemberArray().length > 0) {
abstractProcess.addNewContact().setContactList(contactList);
}
}
// set keywords
if (sosAbstractProcess.isSetKeywords()) {
final List<String> keywords = sosAbstractProcess.getKeywords();
final int length = abstractProcess.getKeywordsArray().length;
for (int i = 0; i < length; ++i) {
abstractProcess.removeKeywords(i);
}
abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
}
if (sosAbstractProcess.isSetValidTime()) {
if (abstractProcess.isSetValidTime()) {
// remove existing validTime element
final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
newCursor.removeXml();
newCursor.dispose();
}
final Time time = sosAbstractProcess.getMergedValidTime();
final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
if (time instanceof TimeInstant) {
abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
} else if (time instanceof TimePeriod) {
abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
}
}
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class OmEncoderv20Test method createComplexObservation.
protected OmObservation createComplexObservation() {
DateTime now = new DateTime(DateTimeZone.UTC);
TimeInstant resultTime = new TimeInstant(now);
TimeInstant phenomenonTime = new TimeInstant(now);
TimePeriod validTime = new TimePeriod(now.minusMinutes(5), now.plusMinutes(5));
OmObservation observation = new OmObservation();
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setFeatureOfInterest(new SamplingFeature(new CodeWithAuthority("feature", CODE_SPACE)));
OmCompositePhenomenon observableProperty = new OmCompositePhenomenon(PARENT_OBSERVABLE_PROPERTY);
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_1));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_2));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_3));
observableProperty.addPhenomenonComponent(new OmObservableProperty(CHILD_OBSERVABLE_PROPERTY_4));
observationConstellation.setObservableProperty(observableProperty);
observationConstellation.setObservationType(OmConstants.OBS_TYPE_COMPLEX_OBSERVATION);
observationConstellation.addOffering(OFFERING);
AbstractFeature procedure = new SosProcedureDescriptionUnknownType(PROCEDURE);
// procedure.setIdentifier(new CodeWithAuthority(PROCEDURE, CODE_SPACE));
observationConstellation.setProcedure(procedure);
observation.setObservationConstellation(observationConstellation);
observation.setParameter(null);
observation.setResultTime(resultTime);
observation.setTokenSeparator(TOKEN_SEPERATOR);
observation.setTupleSeparator(TUPLE_SEPERATOR);
observation.setValidTime(validTime);
ComplexValue complexValue = new ComplexValue();
SweDataRecord sweDataRecord = new SweDataRecord();
SweQuantity sweQuantity = new SweQuantity();
sweQuantity.setDefinition(CHILD_OBSERVABLE_PROPERTY_1);
sweQuantity.setUom("unit");
sweQuantity.setValue(42.0);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_1_NAME, sweQuantity));
SweBoolean sweBoolean = new SweBoolean();
sweBoolean.setValue(Boolean.TRUE);
sweBoolean.setDefinition(CHILD_OBSERVABLE_PROPERTY_2);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_2_NAME, sweBoolean));
SweCount sweCount = new SweCount();
sweCount.setDefinition(CHILD_OBSERVABLE_PROPERTY_3);
sweCount.setValue(42);
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_3_NAME, sweCount));
SweText sweText = new SweText();
sweText.setDefinition(CHILD_OBSERVABLE_PROPERTY_4);
sweText.setValue("42");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_4_NAME, sweText));
SweCategory sweCategory = new SweCategory();
sweCategory.setDefinition(CHILD_OBSERVABLE_PROPERTY_5);
sweCategory.setCodeSpace(CODE_SPACE);
sweCategory.setValue("52");
sweDataRecord.addField(new SweField(CHILD_OBSERVABLE_PROPERTY_5_NAME, sweCategory));
complexValue.setValue(sweDataRecord);
observation.setValue(new SingleObservationValue<>(phenomenonTime, complexValue));
return observation;
}
Aggregations