use of org.n52.series.db.beans.DataEntity in project SOS by 52North.
the class DeleteObservationHelper method checkForFirstLastReference.
default void checkForFirstLastReference(DataEntity<?> observation, Session session) {
DatasetEntity dataset = observation.getDataset();
if (dataset.getFirstObservation() != null && dataset.getFirstObservation().getId() != null && observation.getId() != null && dataset.getFirstObservation().getId().equals(observation.getId())) {
dataset.setFirstObservation(null);
}
if (dataset.getLastObservation() != null && dataset.getLastObservation().getId() != null && observation.getId() != null && dataset.getLastObservation().getId().equals(observation.getId())) {
dataset.setLastObservation(null);
}
session.update(dataset);
session.flush();
}
use of org.n52.series.db.beans.DataEntity 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.DataEntity in project SOS by 52North.
the class GetResultHandler method getResult.
@Override
public GetResultResponse getResult(final GetResultRequest request) throws OwsExceptionReport {
Session session = null;
try {
session = sessionHolder.getSession();
final GetResultResponse response = new GetResultResponse();
response.setService(request.getService());
response.setVersion(request.getVersion());
final Set<String> featureIdentifier = QueryHelper.getFeatures(getDaoFactory().getFeatureQueryHandler(), request, session);
final ResultTemplateEntity resultTemplate = queryResultTemplate(request, featureIdentifier, session);
SosResultEncoding sosResultEncoding = null;
SosResultStructure sosResultStructure = null;
if (resultTemplate != null) {
sosResultEncoding = createSosResultEncoding(resultTemplate.getEncoding());
sosResultStructure = createSosResultStructure(resultTemplate.getStructure());
} else {
sosResultEncoding = createSosResultEncoding();
sosResultStructure = generateSosResultStructure(request.getObservedProperty(), request.getOffering(), featureIdentifier, session);
}
final List<DataEntity<?>> observations;
observations = querySeriesObservation(request, featureIdentifier, session);
response.setResultValues(getResultHandlingHelper().createResultValuesFromObservations(observations, sosResultEncoding, sosResultStructure, getProfileHandler().getActiveProfile().getResponseNoDataPlaceholder(), session));
return response;
} catch (final HibernateException he) {
throw new NoApplicableCodeException().causedBy(he).withMessage("Error while querying result data!").setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
} finally {
sessionHolder.returnSession(session);
}
}
use of org.n52.series.db.beans.DataEntity in project SOS by 52North.
the class ResultHandlingHelper method getSamplingGeometry.
private String getSamplingGeometry(DataEntity<?> observation, String tokenSeparator, SweAbstractDataComponent sweAbstractDataComponent, String noDataPlaceholder) throws OwsExceptionReport {
SweVector vector = getVector(sweAbstractDataComponent);
if (vector != null && vector.isSetCoordinates()) {
final Map<Integer, String> valueOrder = new HashMap<>(0);
addOrderAndVectorDefinitionToMap(vector.getCoordinates(), valueOrder, new IncDecInteger());
final StringBuilder builder = new StringBuilder();
Geometry samplingGeometry = null;
if (observation.isSetGeometryEntity()) {
samplingGeometry = getGeomtryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(observation.getGeometryEntity().getGeometry());
}
for (final Entry<Integer, String> entry : valueOrder.entrySet()) {
final String definition = entry.getValue();
if (samplingGeometry != null && samplingGeometry instanceof Point) {
Coordinate coordinate = samplingGeometry.getCoordinate();
if (helper.hasAltitudeName(definition) && checkCoordinate(coordinate.getZ())) {
builder.append(coordinate.getZ());
} else if (helper.hasNorthingName(definition)) {
if (getGeomtryHandler().isNorthingFirstEpsgCode(samplingGeometry.getSRID())) {
builder.append(coordinate.x);
} else {
builder.append(coordinate.y);
}
} else if (helper.hasEastingName(definition)) {
if (getGeomtryHandler().isNorthingFirstEpsgCode(samplingGeometry.getSRID())) {
builder.append(coordinate.y);
} else {
builder.append(coordinate.x);
}
} else {
builder.append(noDataPlaceholder);
}
} else {
builder.append(noDataPlaceholder);
}
builder.append(tokenSeparator);
}
return builder.delete(builder.lastIndexOf(tokenSeparator), builder.length()).toString();
}
return noDataPlaceholder;
}
use of org.n52.series.db.beans.DataEntity in project SOS by 52North.
the class ResultHandlingHelper method createObservedPropertyField.
private List<SweField> createObservedPropertyField(DataEntity<?> observation) throws OwsExceptionReport {
List<SweField> fields = new LinkedList<>();
PhenomenonEntity phenomenon = observation.getDataset().getPhenomenon();
if (observation.getDataset().getDatasetType().equals(DatasetType.profile) || observation.getDataset().getObservationType().equals(ObservationType.profile)) {
ProfileValue profile = (ProfileValue) new ObservationValueCreator(decoderRepository).visit(observation);
ProfileLevel level = profile.getValue().get(0);
fields.add(createVerticalParameter(level));
if (level.getValue().get(0) instanceof SweAbstractDataComponent) {
if (level.getValue().size() > 1) {
SweDataRecord record = new SweDataRecord();
for (Value<?> v : level.getValue()) {
SweAbstractDataComponent dc = (SweAbstractDataComponent) v;
record.addField(new SweField(NcName.makeValid(dc.getDefinition()), dc));
}
fields.add(new SweField(getNcNameName(phenomenon), record));
return fields;
} else {
SweAbstractDataComponent swe = (SweAbstractDataComponent) level.getValue().get(0).setValue(null);
swe.setDefinition(phenomenon.getIdentifier());
fields.add(new SweField(getNcNameName(phenomenon), swe));
return fields;
}
}
} else {
SweAbstractDataComponent value = new SweAbstractDataComponentCreator(decoderRepository, true).visit(observation);
fields.add(new SweField(getNcNameName(phenomenon), (SweAbstractDataComponent) value));
return fields;
}
throw new NoApplicableCodeException();
}
Aggregations