use of org.n52.series.db.beans.FormatEntity in project SOS by 52North.
the class UpdateSensorDescriptionHandler method updateSensorDescription.
@Override
public synchronized UpdateSensorResponse updateSensorDescription(UpdateSensorRequest request) throws OwsExceptionReport {
Session session = null;
Transaction transaction = null;
try {
session = sessionHolder.getSession();
transaction = session.beginTransaction();
UpdateSensorResponse response = new UpdateSensorResponse();
response.setService(request.getService());
response.setVersion(request.getVersion());
for (SosProcedureDescription<?> procedureDescription : request.getProcedureDescriptions()) {
DateTime currentTime = new DateTime(DateTimeZone.UTC);
// TODO: check for all validTimes of descriptions for this
// identifier
// ITime validTime =
// getValidTimeForProcedure(procedureDescription);
ProcedureEntity procedure = daoFactory.getProcedureDAO().getProcedureForIdentifier(request.getProcedureIdentifier(), session);
FormatEntity procedureDescriptionFormat = new DaoFactory().getProcedureDescriptionFormatDAO().getFormatEntityObject(request.getProcedureDescriptionFormat(), session);
Set<ProcedureHistoryEntity> procedureHistories = procedure.getProcedureHistory();
ProcedureHistoryDAO procedureHistroyDAO = daoFactory.getProcedureHistoryDAO();
for (ProcedureHistoryEntity procedureHistroy : procedureHistories) {
if (procedureHistroy.getFormat().getFormat().equals(procedureDescriptionFormat.getFormat()) && procedureHistroy.getEndTime() == null) {
procedureHistroy.setEndTime(currentTime.toDate());
procedureHistroyDAO.update(procedureHistroy, session);
}
}
procedureHistroyDAO.insert(procedure, procedureDescriptionFormat, getSensorDescriptionFromProcedureDescription(procedureDescription), currentTime, session);
}
session.flush();
transaction.commit();
response.setUpdatedProcedure(request.getProcedureIdentifier());
return response;
} catch (HibernateException he) {
if (transaction != null) {
transaction.rollback();
}
throw new NoApplicableCodeException().causedBy(he).withMessage("Error while processing data for UpdateSensorDescription document!");
} finally {
sessionHolder.returnSession(session);
}
}
use of org.n52.series.db.beans.FormatEntity in project sensorweb-server-sta by 52North.
the class ObservationService method checkOffering.
private OfferingEntity checkOffering(DatastreamEntity datastream) throws STACRUDException {
ProcedureEntity procedure = datastream.getProcedure();
synchronized (getLock(procedure.getIdentifier())) {
if (!offeringRepository.existsByIdentifier(procedure.getIdentifier())) {
OfferingEntity offering = new OfferingEntity();
offering.setIdentifier(procedure.getIdentifier());
offering.setStaIdentifier(procedure.getStaIdentifier());
offering.setName(procedure.getName());
offering.setDescription(procedure.getDescription());
if (datastream.hasSamplingTimeStart()) {
offering.setSamplingTimeStart(datastream.getSamplingTimeStart());
}
if (datastream.hasSamplingTimeEnd()) {
offering.setSamplingTimeEnd(datastream.getSamplingTimeEnd());
}
if (datastream.getResultTimeStart() != null) {
offering.setResultTimeStart(datastream.getResultTimeStart());
}
if (datastream.getResultTimeEnd() != null) {
offering.setResultTimeEnd(datastream.getResultTimeEnd());
}
if (datastream.isSetGeometry()) {
offering.setGeometryEntity(datastream.getGeometryEntity());
}
HashSet<FormatEntity> set = new HashSet<>();
set.add(datastream.getObservationType());
offering.setObservationTypes(set);
return offeringRepository.save(offering);
} else {
// TODO expand time and geometry if necessary
return offeringRepository.findByIdentifier(procedure.getIdentifier()).get();
}
}
}
Aggregations