use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class AqdGetObservationResponseXmlStreamWriter method writeFeatureCollectionDoc.
private void writeFeatureCollectionDoc() throws XMLStreamException, EncodingException {
start(GmlConstants.QN_FEATURE_COLLECTION_32);
addNamespaces();
addSchemaLocations();
FeatureCollection featureCollection = getElement();
addGmlId(featureCollection.getGmlId());
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
for (AbstractFeature abstractFeature : featureCollection.getMembers().values()) {
long start = System.currentTimeMillis();
Encoder<XmlObject, AbstractFeature> encoder = getEncoder(abstractFeature);
if (abstractFeature instanceof OmObservation) {
OmObservation observation = (OmObservation) abstractFeature;
if (observation.getValue() instanceof ObservationStream) {
try {
// start the timer task to write blank strings to avoid
// connection closing
startTimer();
ObservationStream mergeObservation = ((ObservationStream) observation.getValue()).merge();
LOGGER.debug("Observation processing requires {} ms", System.currentTimeMillis() - start);
int count = 0;
while (mergeObservation.hasNext()) {
OmObservation omObservation = mergeObservation.next();
if (abstractFeature.isSetGmlID()) {
if (count == 0) {
omObservation.setGmlId(abstractFeature.getGmlId());
} else {
omObservation.setGmlId(abstractFeature.getGmlId() + "_" + count);
}
count++;
}
omObservation.setResultTime(resultTime);
String xmlTextObservation = prepareObservation(omObservation, encoder);
// stop the timer task
stopTimer();
writeMember(xmlTextObservation);
}
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
} else {
if (encoder instanceof XmlStreamWriter) {
encoder.encode(abstractFeature, getContext());
} else {
writeMember(abstractFeature, encoder);
}
}
} else {
writeMember(abstractFeature, encoder);
}
LOGGER.debug("Writing member requires {} ms", System.currentTimeMillis() - start);
}
end(GmlConstants.QN_FEATURE_COLLECTION_32);
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class WmlTVPEncoderv20Test method initObjects.
@Before
public void initObjects() {
encoder = new WmlTVPEncoderv20();
MultiValue<List<TimeValuePair>> value = new TVPValue();
String unit = "test-unit";
value.setUnit(unit);
TimeValuePair tvp1 = new TimeValuePair(new TimeInstant(new Date(UTC_TIMESTAMP)), new QuantityValue(52.1234567890));
List<TimeValuePair> valueList = CollectionHelper.list(tvp1);
value.setValue(valueList);
mv = new MultiObservationValues<>();
mv.setValue(value);
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class EReportingHeaderEncoderTest method testValidity.
@Test
public void testValidity() throws XMLStreamException, OwsExceptionReport, SAXException, MalformedURLException, IOException, URISyntaxException, EncodingException {
EReportingHeader header = new EReportingHeader().setInspireID(new Identifier("id", "namespace").setVersionId(Nillable.missing())).setChange(new EReportingChange("Changed because... you know")).setReportingPeriod(Referenceable.of(Nillable.present(new TimeInstant(DateTime.now())))).setReportingAuthority(new RelatedParty().setIndividualName(Nillable.missing()).setOrganisationName("Organisation").setPositionName("Postionti").addRole(new Reference().setHref(URI.create("http://hallo"))).addRole(Nillable.withheld()).setContact(new Contact().addTelephoneFacsimile("1234").addTelephoneFacsimile(Nillable.missing()).addTelephoneVoice("asdfasdf").setHoursOfService(new PT_FreeText().addTextGroup(new LocalisedCharacterString("asdfasdf"))).setWebsite(Nillable.unknown()).setElectronicMailAddress(Nillable.unknown()).setAddress(new AddressRepresentation().setPostCode("12341234").setAddressFeature(new Reference().setHref(URI.create("http://asdfasdf"))).addLocatorDesignator("localtor").addAddressArea(Nillable.withheld()).addAddressArea(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addAdminUnit(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addPostName(Nillable.withheld()).addPostName(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addThoroughfare(Nillable.withheld()).addThoroughfare(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))))));
validate(header);
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class UVFEncoder method getTemporalBBoxFromObservations.
private TimePeriod getTemporalBBoxFromObservations(List<OmObservation> observationCollection) throws EncodingException {
DateTime start = null;
DateTime end = null;
for (OmObservation observation : observationCollection) {
Time phenomenonTime = observation.getPhenomenonTime();
if (phenomenonTime instanceof TimeInstant) {
final DateTime time = ((TimeInstant) phenomenonTime).getTimePosition().getTime();
if (start == null || time.isBefore(start)) {
start = time;
}
if (end == null || time.isAfter(end)) {
end = time;
}
} else {
final DateTime periodStart = ((TimePeriod) phenomenonTime).getStart();
if (start == null || periodStart.isBefore(start)) {
start = periodStart;
}
final DateTime periodEnd = ((TimePeriod) phenomenonTime).getEnd();
if (end == null || periodEnd.isAfter(end)) {
end = periodEnd;
}
}
}
if (start != null && end != null) {
return new TimePeriod(start, end);
} else {
final String message = "Could not extract centuries from observation collection";
LOGGER.error(message);
throw new EncodingException(message);
}
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class MeasurementDecodingTest method testResultTime.
@Test
public void testResultTime() {
assertThat(observation, is(notNullValue()));
final TimeInstant rt = observation.getResultTime();
assertThat(rt, is(notNullValue()));
assertThat(rt.getValue(), is(equalTo(resultTime)));
}
Aggregations