Search in sources :

Example 1 with ProcedureHistoryEntity

use of org.n52.series.db.beans.ProcedureHistoryEntity in project SOS by 52North.

the class DescribeSensorDaoImpl method getProcedureDescriptions.

/**
 * @param request
 *            DescribeSensorRequest request
 * @param session
 *            Hibernate session
 * @return Matching procedure descriptions
 * @throws OwsExceptionReport
 *             If an error occurs
 */
private List<SosProcedureDescription<?>> getProcedureDescriptions(DescribeSensorRequest request, Session session) throws OwsExceptionReport {
    Set<String> possibleProcedureDescriptionFormats = getPossibleProcedureDescriptionFormats(request.getProcedureDescriptionFormat());
    final ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(request.getProcedure(), possibleProcedureDescriptionFormats, request.getValidTime(), session);
    List<SosProcedureDescription<?>> list = Lists.newLinkedList();
    if (procedure != null) {
        if (procedure.hasProcedureHistory()) {
            for (ProcedureHistoryEntity validProcedureTime : daoFactory.getProcedureHistoryDAO().get(procedure, possibleProcedureDescriptionFormats, request.getValidTime(), session)) {
                SosProcedureDescription<?> sosProcedureDescription = procedureConverter.createSosProcedureDescriptionFromValidProcedureTime(procedure, request.getProcedureDescriptionFormat(), validProcedureTime, request.getVersion(), getRequestedLocale(request), session);
                list.add(convertProcedureDescription(sosProcedureDescription, request));
            }
        }
    } else {
        SosProcedureDescription<?> procedureDescription = getProcedureDescription(request, session);
        if (procedureDescription != null) {
            list.add(procedureDescription);
        } else {
            if (!request.isSetValidTime()) {
                throw new NoApplicableCodeException().causedBy(new IllegalArgumentException(LOG_PARAMETER_PROCEDURE_NOT_NULL)).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
            }
        }
    }
    return list;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription)

Example 2 with ProcedureHistoryEntity

use of org.n52.series.db.beans.ProcedureHistoryEntity in project SOS by 52North.

the class HibernateObservationBuilder method getValidProcedureTime.

protected ProcedureHistoryEntity getValidProcedureTime() {
    ProcedureHistoryEntity validProcedureTime = (ProcedureHistoryEntity) session.createCriteria(ProcedureHistoryEntity.class).add(Restrictions.eq(ProcedureHistoryEntity.PROCEDURE, getProcedure())).uniqueResult();
    if (validProcedureTime == null) {
        validProcedureTime = new ProcedureHistoryEntity();
        validProcedureTime.setXml(XML_TOKEN);
        validProcedureTime.setEndTime(null);
        validProcedureTime.setStartTime(new Date());
        validProcedureTime.setProcedure(getProcedure());
        validProcedureTime.setFormat(getProcedureDescriptionFormat());
        session.save(validProcedureTime);
        session.flush();
    }
    return validProcedureTime;
}
Also used : ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) Date(java.util.Date)

Example 3 with ProcedureHistoryEntity

use of org.n52.series.db.beans.ProcedureHistoryEntity in project SOS by 52North.

the class ProcedureHistoryDAO method setEndTime.

/**
 * Set valid end time to valid procedure time object for procedure
 * identifier
 *
 * @param procedureIdentifier
 *            Procedure identifier
 * @param session
 *            Hibernate session
 * @throws UnsupportedOperatorException If an error occurs
 * @throws UnsupportedValueReferenceException If an error occurs
 * @throws UnsupportedTimeException If an error occurs
 */
public void setEndTime(String procedureIdentifier, String procedureDescriptionFormat, Session session) throws UnsupportedTimeException, UnsupportedValueReferenceException, UnsupportedOperatorException {
    ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(procedureIdentifier, procedureDescriptionFormat, null, session);
    Set<ProcedureHistoryEntity> validProcedureTimes = procedure.getProcedureHistory();
    for (ProcedureHistoryEntity validProcedureTime : validProcedureTimes) {
        if (validProcedureTime.getEndTime() == null) {
            validProcedureTime.setEndTime(new DateTime(DateTimeZone.UTC).toDate());
        }
    }
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) DateTime(org.joda.time.DateTime)

Example 4 with ProcedureHistoryEntity

use of org.n52.series.db.beans.ProcedureHistoryEntity in project sensorweb-server-sta by 52North.

the class JSONSensor method handleEncodingType.

protected void handleEncodingType() {
    if (encodingType.equalsIgnoreCase(STA_SENSORML_2)) {
        self.setFormat(new FormatEntity().setFormat(SENSORML_2));
        ProcedureHistoryEntity procedureHistoryEntity = new ProcedureHistoryEntity();
        procedureHistoryEntity.setProcedure(self);
        procedureHistoryEntity.setFormat(self.getFormat());
        procedureHistoryEntity.setStartTime(DateTime.now().toDate());
        procedureHistoryEntity.setXml(metadata);
        Set<ProcedureHistoryEntity> set = new LinkedHashSet<>();
        set.add(procedureHistoryEntity);
        self.setProcedureHistory(set);
    } else if (encodingType.equalsIgnoreCase(PDF)) {
        self.setFormat(new FormatEntity().setFormat(PDF));
        self.setDescriptionFile(metadata);
    } else {
        Assert.notNull(null, INALID_ENCODING_TYPE);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) FormatEntity(org.n52.series.db.beans.FormatEntity)

Example 5 with ProcedureHistoryEntity

use of org.n52.series.db.beans.ProcedureHistoryEntity in project SOS by 52North.

the class ProcedureHistoryDAO method insert.

/**
 * Insert valid procedure time for procedrue
 *
 * @param procedure
 *            Procedure object
 * @param xmlDescription
 *            Procedure XML description
 * @param validStartTime
 *            Valid start time
 * @param session
 *            Hibernate session
 * @return The inserted {@link ProcedureHistoryEntity}
 */
public ProcedureHistoryEntity insert(ProcedureEntity procedure, FormatEntity procedureDescriptionFormat, String xmlDescription, DateTime validStartTime, Session session) {
    ProcedureHistoryEntity vpd = new ProcedureHistoryEntity();
    vpd.setProcedure(procedure);
    vpd.setFormat(procedureDescriptionFormat);
    vpd.setXml(xmlDescription);
    vpd.setStartTime(validStartTime.toDate());
    session.save(vpd);
    session.flush();
    session.refresh(vpd);
    return vpd;
}
Also used : ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity)

Aggregations

ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)7 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)3 DateTime (org.joda.time.DateTime)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)1 UpdateSensorResponse (org.n52.shetland.ogc.sos.response.UpdateSensorResponse)1 DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)1 ProcedureHistoryDAO (org.n52.sos.ds.hibernate.dao.ProcedureHistoryDAO)1