Search in sources :

Example 1 with UpdateSensorResponse

use of org.n52.shetland.ogc.sos.response.UpdateSensorResponse in project arctic-sea by 52North.

the class UpdateSensorResponseEncoderTest method should_encode_UpdateSensor_response.

@Test
public void should_encode_UpdateSensor_response() throws EncodingException {
    final UpdateSensorResponse response = new UpdateSensorResponse();
    final String updatedProcedure = "updatedProcedure";
    response.setUpdatedProcedure(updatedProcedure);
    final XmlObject encodedResponse = encoder.encode(response);
    assertThat(encodedResponse, is(instanceOf(UpdateSensorDescriptionResponseDocument.class)));
    final UpdateSensorDescriptionResponseDocument doc = (UpdateSensorDescriptionResponseDocument) encodedResponse;
    assertThat(doc.isNil(), is(FALSE));
    assertThat(doc.getUpdateSensorDescriptionResponse().getUpdatedProcedure(), is(updatedProcedure));
    assertThat(doc.validate(), is(TRUE));
}
Also used : UpdateSensorDescriptionResponseDocument(net.opengis.swes.x20.UpdateSensorDescriptionResponseDocument) XmlObject(org.apache.xmlbeans.XmlObject) UpdateSensorResponse(org.n52.shetland.ogc.sos.response.UpdateSensorResponse) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateSensorResponse

use of org.n52.shetland.ogc.sos.response.UpdateSensorResponse in project SOS by 52North.

the class SosUpdateSensorDescriptionOperatorV20 method receive.

@Override
public UpdateSensorResponse receive(UpdateSensorRequest request) throws OwsExceptionReport {
    UpdateSensorResponse response = getOperationHandler().updateSensorDescription(request);
    getServiceEventBus().submit(new SensorModification(request, response));
    return response;
}
Also used : SensorModification(org.n52.sos.event.events.SensorModification) UpdateSensorResponse(org.n52.shetland.ogc.sos.response.UpdateSensorResponse)

Example 3 with UpdateSensorResponse

use of org.n52.shetland.ogc.sos.response.UpdateSensorResponse 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);
    }
}
Also used : ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) HibernateException(org.hibernate.HibernateException) FormatEntity(org.n52.series.db.beans.FormatEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DateTime(org.joda.time.DateTime) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Transaction(org.hibernate.Transaction) UpdateSensorResponse(org.n52.shetland.ogc.sos.response.UpdateSensorResponse) ProcedureHistoryDAO(org.n52.sos.ds.hibernate.dao.ProcedureHistoryDAO) Session(org.hibernate.Session)

Aggregations

UpdateSensorResponse (org.n52.shetland.ogc.sos.response.UpdateSensorResponse)3 UpdateSensorDescriptionResponseDocument (net.opengis.swes.x20.UpdateSensorDescriptionResponseDocument)1 XmlObject (org.apache.xmlbeans.XmlObject)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 FormatEntity (org.n52.series.db.beans.FormatEntity)1 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)1 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)1 ProcedureHistoryDAO (org.n52.sos.ds.hibernate.dao.ProcedureHistoryDAO)1 SensorModification (org.n52.sos.event.events.SensorModification)1