use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method createInsertObservationRequest.
private InsertObservationRequest createInsertObservationRequest() throws InvalidSridException, ParseException {
SamplingFeature samplingFeature = new SamplingFeature(new CodeWithAuthority("test-feature-uri"));
samplingFeature.setName(new CodeType("test-feature-name"));
samplingFeature.setSampledFeatures(Arrays.asList(new SamplingFeature(new CodeWithAuthority("test-parent-feature-uri"))));
samplingFeature.setGeometry(JTSHelper.createGeometryFromWKT("POINT(52.0 42.0)", 4326));
PhysicalSystem procedure = new PhysicalSystem();
procedure.setIdentifier("test-procedure");
OmObservationConstellation observationConstellation = new OmObservationConstellation();
observationConstellation.setGmlId("o1");
observationConstellation.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationConstellation.setObservableProperty(new OmObservableProperty("test-property"));
observationConstellation.setFeatureOfInterest(samplingFeature);
observationConstellation.setProcedure(procedure);
TimeInstant time = new TimeInstant(new Date(0));
QuantityValue quantity = new QuantityValue(23.0, "test-uom");
ObservationValue<?> value = new SingleObservationValue<>(time, quantity);
OmObservation omObservation = new OmObservation();
omObservation.setObservationConstellation(observationConstellation);
omObservation.setResultTime(time);
omObservation.setValue(value);
InsertObservationRequest request = new InsertObservationRequest("SOS", "2.0.0");
request.setOfferings(Arrays.asList(OFFERING_ID));
request.addObservation(omObservation);
return request;
}
use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.
the class InspireEncoderTest method getMinimalInspireExtendedCapabilities.
/*
* xmlns:xsd="http://www.w3.org/2001/XMLSchema"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
* "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"
*/
//
// @BeforeClass
// public static void init() {
// Map<String, String> prefixes = new HashMap<String, String>();
// prefixes.put(InspireConstants.NS_INSPIRE_COMMON, InspireConstants.NS_INSPIRE_COMMON_PREFIX);
// prefixes.put(InspireConstants.NS_INSPIRE_DLS, InspireConstants.NS_INSPIRE_DLS_PREFIX);
// xmlOptions.setSaveSuggestedPrefixes(prefixes);
// xmlOptions.setSaveImplicitNamespaces(prefixes);
// xmlOptions.setSaveAggressiveNamespaces();
// xmlOptions.setSavePrettyPrint();
// xmlOptions.setSaveNamespacesFirst();
// xmlOptions.setCharacterEncoding("UTF-8");
// }
//
// @Test
// public void enocodeMinimalInspireExtendedCapabilities() throws UnsupportedEncoderInputException,
// OwsExceptionReport, SAXException, IOException {
// InspireXmlEncoder inspireEncoder = new InspireXmlEncoder();
// validate(inspireEncoder.encode(getMinimalInspireExtendedCapabilities()));
// }
//
// @Test
// public void enocodeFullIsnpireExtendedCapabilities() throws UnsupportedEncoderInputException, OwsExceptionReport,
// SAXException, IOException {
// InspireXmlEncoder inspireEncoder = new InspireXmlEncoder();
// validate(inspireEncoder.encode(getFullInspireExtendedCapabilities()));
// }
//
// @Test
// public void valid_iso8601() {
// // date
// String datePattern = "\\d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])";
// String date = "2013-09-26";
// Assert.assertThat(Pattern.matches(datePattern, date), Matchers.is(true));
// // time
// String timePattern = "(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?)?";
// String time_HH_MM_SS_S = "T12:49:41.740";
// Assert.assertThat(Pattern.matches(timePattern, time_HH_MM_SS_S), Matchers.is(true));
// String time_HH_MM_SS = "T12:49:41";
// Assert.assertThat(Pattern.matches(timePattern, time_HH_MM_SS), Matchers.is(true));
// // offset
// String offsetPattern = "(Z|[+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]))?";
// String offset_PLUS_HH_MM = "+02:00";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_PLUS_HH_MM), Matchers.is(true));
// String offset_MINUS_HH_MM = "-02:00";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_MINUS_HH_MM), Matchers.is(true));
// String offset_Z = "Z";
// Assert.assertThat(Pattern.matches(offsetPattern, offset_Z), Matchers.is(true));
// // date time
// String dtPattern = datePattern + timePattern;
// Assert.assertThat(Pattern.matches(dtPattern, date + time_HH_MM_SS_S), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtPattern, date + time_HH_MM_SS), Matchers.is(true));
// // date time offset
// String dtoPattern = dtPattern + offsetPattern;
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_PLUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_MINUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS_S + offset_Z), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_PLUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_MINUS_HH_MM), Matchers.is(true));
// Assert.assertThat(Pattern.matches(dtoPattern, date + time_HH_MM_SS + offset_Z), Matchers.is(true));
// // valid patter for schema: \d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?)?(Z|[+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]))?
//
// // String pattern =
// // "\\d{4}-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?)?(Z|([+|-](2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9])?)?)?";
// // Assert.assertThat(Pattern.matches(pattern, "2013-09-26T12:49:41.740+02:00"), Matchers.is(true));
// }
private MinimalInspireExtendedCapabilities getMinimalInspireExtendedCapabilities() {
// --------------------
InspireResourceLocator resourceLocator = new InspireResourceLocator("http://min.test.org/sos");
resourceLocator.addMediaType(MediaTypes.APPLICATION_SOAP_XML);
// --------------------
InspireSupportedLanguages inspireSupportedLanguages = new InspireSupportedLanguages(InspireLanguageISO6392B.ENG);
// --------------------
InspireLanguageISO6392B responseLanguage = InspireLanguageISO6392B.ENG;
// --------------------
Set<InspireUniqueResourceIdentifier> spatialDataSetIdentifier = Sets.newHashSet();
InspireUniqueResourceIdentifier iuri = new InspireUniqueResourceIdentifier("test");
iuri.setNamespace("http://test.org");
spatialDataSetIdentifier.add(iuri);
// --------------------
return new MinimalInspireExtendedCapabilities(resourceLocator, inspireSupportedLanguages, responseLanguage, spatialDataSetIdentifier, new InspireSupportedCRS("4326"));
}
use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeObservation.
/**
* Write {@link OmObservation} XML encoded to stream
*
* @param observation the observation
*
* @throws XMLStreamException If an error occurs when writing to stream
* @throws EncodingException If an error occurs when creating elements to be written If an error occurs when
* creating elements to be written
*/
protected void writeObservation(OmObservation observation) throws XMLStreamException, EncodingException {
start(getDocumentName());
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(W3CConstants.NS_XSI_PREFIX, W3CConstants.NS_XSI);
namespace(OmConstants.NS_OM_PREFIX, OmConstants.NS_OM_2);
namespace(GmlConstants.NS_GML_PREFIX, GmlConstants.NS_GML_32);
writeAddtitionalNamespaces();
String observationID = addGmlId(observation);
checkAndWriteIdentifier();
checkAndWriteName();
checkAndWriteDescription();
if (observation.getObservationConstellation().isSetObservationType()) {
writeObservationType(observation.getObservationConstellation().getObservationType());
}
if (observation.isSetMetaDataProperty()) {
writeMetaDataProperty(observation.getMetaDataProperty());
}
Time phenomenonTime = observation.getPhenomenonTime();
if (phenomenonTime.getGmlId() == null) {
phenomenonTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
}
writePhenomenonTime(phenomenonTime);
writeResultTime();
if (observation.isSetValidTime()) {
writeValidTime(observation.getValidTime());
}
writeProcedure();
if (observation.isSetParameter()) {
writeParameter();
}
writeObservableProperty();
writeFeatureOfIntererst();
writeResult();
end(getDocumentName());
}
use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.
the class AbstractOmV20XmlStreamWriter method writeResultTime.
/**
* Write om:resultTime to stream
*
* @throws XMLStreamException
* If an error occurs when writing to stream
* @throws EncodingException
* If an error occurs when creating elements to be written
*/
protected void writeResultTime() throws XMLStreamException, EncodingException {
OmObservation observation = getElement();
TimeInstant resultTime = observation.getResultTime();
Time phenomenonTime = observation.getPhenomenonTime();
// get result time from SOS result time
if (observation.getResultTime() != null) {
if (resultTime.equals(phenomenonTime)) {
empty(OmConstants.QN_OM_20_RESULT_TIME);
addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
} else {
addResultTime(resultTime);
}
} else if (phenomenonTime instanceof TimeInstant) {
// if result time is not set, get result time from phenomenon time
empty(OmConstants.QN_OM_20_RESULT_TIME);
addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId()));
} else if (phenomenonTime instanceof TimePeriod) {
TimeInstant rsTime = new TimeInstant(((TimePeriod) observation.getPhenomenonTime()).getEnd());
addResultTime(rsTime);
}
}
use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.
the class InspireXmlStreamWriter method writeTemporalReference.
/**
* Write {@link InspireTemporalReference} to stream
*
* @param temporalReference
* {@link InspireTemporalReference} to write to stream
* @throws XMLStreamException
* If an error occurs when writing the object to stream
*/
private void writeTemporalReference(InspireTemporalReference temporalReference) throws XMLStreamException {
if (!temporalReference.isSetDateOfCreation() && !temporalReference.isSetDateOfLastRevision() && !temporalReference.isSetDatesOfPublication() && !temporalReference.isSetTemporalExtents()) {
empty(QN_TEMPORAL_REFERENCE);
} else {
start(QN_TEMPORAL_REFERENCE);
if (temporalReference.isSetDateOfCreation()) {
writeDateOfCreation(temporalReference.getDateOfCreation());
}
if (temporalReference.isSetDateOfLastRevision()) {
writeDateOfLastRevision(temporalReference.getDateOfLastRevision());
}
if (temporalReference.isSetDatesOfPublication()) {
for (InspireDateOfPublication dateOfPublication : temporalReference.getDatesOfPublication()) {
writeDateOfPublication(dateOfPublication);
}
}
if (temporalReference.isSetTemporalExtents()) {
for (Time temporalExtent : temporalReference.getTemporalExtents()) {
writeTemporalExtent(temporalExtent);
}
}
end(QN_TEMPORAL_REFERENCE);
}
}
Aggregations