use of org.n52.series.db.beans.QuantityDataEntity in project SOS by 52North.
the class DeleteObservationHelper method checkSeriesForFirstLatest.
/**
* Check if {@link Dataset} should be updated
*
* @param serieses
* Deleted observation
* @param session
* Hibernate session
* @throws OwsExceptionReport
* If an error occurs
*/
default void checkSeriesForFirstLatest(Collection<Long> serieses, Session session) throws OwsExceptionReport {
if (!serieses.isEmpty()) {
AbstractSeriesObservationDAO observationDAO = getDaoFactory().getObservationDAO();
Map<Long, SeriesTimeExtrema> minMaxTimes = observationDAO.getMinMaxSeriesTimesById(serieses instanceof Set ? (Set<Long>) serieses : new LinkedHashSet<>(serieses), session);
for (Long id : serieses) {
DatasetEntity series = session.get(DatasetEntity.class, id);
boolean update = false;
if (minMaxTimes.containsKey(series.getId())) {
SeriesTimeExtrema extrema = minMaxTimes.get(series.getId());
if (!series.isSetFirstValueAt() || series.isSetFirstValueAt() && !DateTimeHelper.makeDateTime(series.getFirstValueAt()).equals(extrema.getMinPhenomenonTime())) {
series.setFirstValueAt(extrema.getMinPhenomenonTime().toDate());
DataEntity<?> o = unproxy(observationDAO.getMinObservation(series, extrema.getMinPhenomenonTime(), session), session);
series.setFirstObservation(o);
if (series.getValueType().equals(ValueType.quantity)) {
series.setFirstQuantityValue(((QuantityDataEntity) o).getValue());
}
update = true;
}
if (!series.isSetLastValueAt() || series.isSetLastValueAt() && !DateTimeHelper.makeDateTime(series.getLastValueAt()).equals(extrema.getMaxPhenomenonTime())) {
series.setLastValueAt(extrema.getMaxPhenomenonTime().toDate());
DataEntity<?> o = unproxy(observationDAO.getMaxObservation(series, extrema.getMaxPhenomenonTime(), session), session);
series.setLastObservation(o);
if (series.getValueType().equals(ValueType.quantity)) {
series.setLastQuantityValue(((QuantityDataEntity) o).getValue());
}
update = true;
}
} else {
series.setFirstValueAt(null);
series.setFirstQuantityValue(null);
series.setFirstObservation(null);
series.setLastValueAt(null);
series.setLastQuantityValue(null);
series.setLastObservation(null);
update = true;
}
if (update) {
session.saveOrUpdate(series);
session.flush();
}
}
}
}
use of org.n52.series.db.beans.QuantityDataEntity in project SOS by 52North.
the class HibernateObservationUtilitiesTest method createSubObservationOfSweArrayObservationViaGetObservationById.
@Test
public // present
void createSubObservationOfSweArrayObservationViaGetObservationById() throws OwsExceptionReport, ConnectionProviderException, ConverterException {
// PREPARE
Session session = getSession();
try {
Transaction transaction = session.beginTransaction();
GetObservationByIdRequest request = new GetObservationByIdRequest();
request.setVersion(Sos2Constants.SERVICEVERSION);
FormatEntity hProcedureDescriptionFormat = new FormatEntity();
FormatEntity hFeatureOfInterestType = new FormatEntity();
FeatureEntity hFeatureOfInterest = new FeatureEntity();
PhenomenonEntity hObservableProperty = new PhenomenonEntity();
CategoryEntity hCategory = new CategoryEntity();
PlatformEntity hPlatform = new PlatformEntity();
FormatEntity hObservationType = new FormatEntity();
OfferingEntity hOffering = new OfferingEntity();
DatasetEntity hObservationConstellation = new DatasetEntity();
CodespaceEntity hCodespace = new CodespaceEntity();
ProcedureEntity hProcedure = new ProcedureEntity();
QuantityDataEntity hObservation = new QuantityDataEntity();
ResultTemplateEntity hResultTemplateEntity = new ResultTemplateEntity();
hProcedureDescriptionFormat.setFormat(PROCEDURE_DESCRIPTION_FORMAT);
hCodespace.setName(CODESPACE);
hProcedure.setIdentifier(PROCEDURE);
hProcedure.setFormat(hProcedureDescriptionFormat);
hFeatureOfInterestType.setFormat(FEATURE_OF_INTEREST_TYPE);
hFeatureOfInterest.setIdentifier(FEATURE);
hFeatureOfInterest.setFeatureType(hFeatureOfInterestType);
hFeatureOfInterest.setIdentifierCodespace(hCodespace);
hPlatform.setIdentifier(FEATURE);
hObservableProperty.setIdentifier(OBSERVABLE_PROPERTY);
hCategory.setIdentifier(OBSERVABLE_PROPERTY);
hObservationType.setFormat(OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION);
hOffering.setIdentifier(OFFERING);
hObservationConstellation.setProcedure(hProcedure);
hObservationConstellation.setOffering(hOffering);
hObservationConstellation.setObservableProperty(hObservableProperty);
hObservationConstellation.setOmObservationType(hObservationType);
hObservationConstellation.setFeature(hFeatureOfInterest);
hObservationConstellation.setDeleted(false);
hObservationConstellation.setHidden(false);
hObservationConstellation.setCategory(hCategory);
hObservationConstellation.setPlatform(hPlatform);
hResultTemplateEntity.setFeature(hFeatureOfInterest);
hResultTemplateEntity.setOffering(hOffering);
hResultTemplateEntity.setPhenomenon(hObservableProperty);
hResultTemplateEntity.setProcedure(hProcedure);
hResultTemplateEntity.setIdentifier("test-rt-1");
hResultTemplateEntity.setEncoding("<swe:TextEncoding xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" " + "xmlns:sml=\"http://www.opengis.net/sensorML/1.0.1\" " + "xmlns:sf=\"http://www.opengis.net/sampling/2.0\" " + "xmlns:swes=\"http://www.opengis.net/swes/2.0\" " + "xmlns:sos=\"http://www.opengis.net/sos/2.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:om=\"http://www.opengis.net/om/2.0\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "tokenSeparator=\"#\" blockSeparator=\"@\"/>");
hResultTemplateEntity.setStructure("\"<swe:DataRecord xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" " + "xmlns:sml=\"http://www.opengis.net/sensorML/1.0.1\" " + "xmlns:sf=\"http://www.opengis.net/sampling/2.0\" " + "xmlns:swes=\"http://www.opengis.net/swes/2.0\" " + "xmlns:sos=\"http://www.opengis.net/sos/2.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:om=\"http://www.opengis.net/om/2.0\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n" + " <swe:field name=\"phenomenonTime\">\r\n" + " <swe:Time definition=\"http://www.opengis.net/def/property/OGC/0/PhenomenonTime\">\r\n" + " <swe:uom xlink:href=\"http://www.opengis.net/def/uom/ISO-8601/0/Gregorian\"/>\r\n" + " </swe:Time>\r\n" + " </swe:field>\r\n" + " <swe:field name=\"Discharge\">\r\n" + " <swe:Quantity definition=\"http://sweet.jpl.nasa.gov/2.0/hydroSurface.owl#Discharge\">\r\n" + " <swe:uom code=\"m3\"/>\r\n" + " </swe:Quantity>\r\n" + " </swe:field>\r\n" + "</swe:DataRecord>\"");
session.save(hProcedureDescriptionFormat);
session.save(hProcedure);
session.save(hCodespace);
session.save(hOffering);
session.save(hFeatureOfInterestType);
session.save(hFeatureOfInterest);
session.save(hPlatform);
session.save(hObservableProperty);
session.save(hCategory);
session.save(hObservationType);
session.save(hObservationConstellation);
session.save(hResultTemplateEntity);
session.flush();
hObservation.setValue(BigDecimal.valueOf(1.0));
hObservation.setSamplingTimeStart(DateTime.now().toDate());
hObservation.setSamplingTimeEnd(hObservation.getSamplingTimeStart());
hObservation.setResultTime(hObservation.getSamplingTimeStart());
hObservation.setDataset(hObservationConstellation);
hObservation.setStaIdentifier("123");
hObservation.setDeleted(false);
session.save(hObservation);
transaction.commit();
ArrayList<DataEntity<?>> observationsFromDataBase = new ArrayList<>();
observationsFromDataBase.add(hObservation);
SosHelper sosHelper = new SosHelper();
sosHelper.setServiceURL(URI.create("http://test.org/"));
DaoFactory daoFactory = new DaoFactory();
daoFactory.setSosHelper(sosHelper);
// CALL
OmObservationCreatorContext ctx = new OmObservationCreatorContext(null, null, daoFactory, new ProfileHanlderMock(), Mockito.mock(AdditionalObservationCreatorRepository.class), null, new FeatureQueryHandlerMock(), null, null, null, null, null, Mockito.mock(BindingRepository.class));
ObservationStream resultList = HibernateObservationUtilities.createSosObservationsFromObservations(observationsFromDataBase, request, Locale.ENGLISH, null, ctx, session);
// TEST RESULTS
assertThat(resultList, is(notNullValue()));
assertThat(resultList.hasNext(), is(true));
Object value = resultList.next().getValue().getValue();
assertThat(resultList.hasNext(), is(false));
assertThat(value, is(instanceOf(QuantityValue.class)));
Double val = ((QuantityValue) value).getValue().doubleValue();
// assertThat(value, is(instanceOf(SweDataArray.class)));
// Double val = Double.parseDouble(((SweDataArray) value).getValues().get(0).get(1));
assertThat(val, is(closeTo(1.0, 0.00001)));
} finally {
returnSession(session);
}
}
use of org.n52.series.db.beans.QuantityDataEntity in project SOS by 52North.
the class AbstractObservationDAOTest method add_phenomenonTime_instant_timeIndeterminatePosition_missing.
@Test(expected = MissingParameterValueException.class)
public void add_phenomenonTime_instant_timeIndeterminatePosition_missing() throws OwsExceptionReport {
DataEntity<?> observation = new QuantityDataEntity();
TimeInstant phenomenonTime = new TimeInstant();
dao.addPhenomenonTimeToObservation(observation, phenomenonTime);
}
use of org.n52.series.db.beans.QuantityDataEntity in project SOS by 52North.
the class AbstractObservationDAOTest method add_phenomenonTime_instant_value.
/*
* PhenomenonTime with TimeInstant
*/
@Test
public void add_phenomenonTime_instant_value() throws OwsExceptionReport {
DataEntity<?> observation = new QuantityDataEntity();
TimeInstant phenomenonTime = new TimeInstant(new DateTime());
dao.addPhenomenonTimeToObservation(observation, phenomenonTime);
Assert.assertTrue(observation.getSamplingTimeStart() != null);
Assert.assertTrue(observation.getSamplingTimeEnd() != null);
}
use of org.n52.series.db.beans.QuantityDataEntity in project SOS by 52North.
the class AbstractObservationDAOTest method add_resultTime_from_phenomenonTime_timeIndeterminatePosition_missing.
@Test(expected = NoApplicableCodeException.class)
public void add_resultTime_from_phenomenonTime_timeIndeterminatePosition_missing() throws CodedException {
DataEntity<?> observation = new QuantityDataEntity();
TimeInstant resultTime = new TimeInstant();
resultTime.setGmlId(PHENOMENON_TIME);
TimeInstant phenomeonTime = new TimeInstant();
dao.addResultTimeToObservation(observation, resultTime, phenomeonTime);
}
Aggregations