Search in sources :

Example 16 with FormatEntity

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

the class ProcedureDAO method getOrInsertProcedure.

/**
 * Insert and get procedure object
 *
 * @param identifier
 *            Procedure identifier
 * @param procedureDescriptionFormat
 *            Procedure description format object
 * @param procedureDescription
 *            {@link SosProcedureDescription} to insert
 * @param isType
 *            flag if it is a type
 * @param session
 *            Hibernate session
 * @return ProcedureEntity object
 */
public ProcedureEntity getOrInsertProcedure(String identifier, FormatEntity procedureDescriptionFormat, SosProcedureDescription<?> procedureDescription, boolean isType, Session session) {
    ProcedureEntity procedure = getProcedureForIdentifierIncludeDeleted(identifier, session);
    if (procedure == null) {
        procedure = new ProcedureEntity();
        procedure.setFormat(procedureDescriptionFormat);
        procedure.setIdentifier(identifier, getDaoFactory().isStaSupportsUrls());
        AbstractFeature af = procedureDescription.getProcedureDescription();
        if (af.isSetName()) {
            procedure.setName(af.getFirstName().getValue());
        }
        if (af.isSetDescription()) {
            procedure.setDescription(af.getDescription());
        }
        if (procedureDescription.isSetParentProcedure()) {
            ProcedureEntity parent = getProcedureForIdentifier(procedureDescription.getParentProcedure().getHref(), session);
            if (parent != null) {
                procedure.setParents(Sets.newHashSet(parent));
            }
        }
        if (procedureDescription.getTypeOf() != null && !procedure.isSetTypeOf()) {
            ProcedureEntity typeOfProc = getProcedureForIdentifier(procedureDescription.getTypeOf().getTitle(), session);
            if (typeOfProc != null) {
                procedure.setTypeOf(typeOfProc);
            }
        }
        procedure.setType(isType);
        procedure.setAggregation(procedureDescription.isAggregation());
        procedure.setReference(procedureDescription.isReference());
    }
    session.saveOrUpdate(procedure);
    session.flush();
    session.refresh(procedure);
    return procedure;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 17 with FormatEntity

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

the class OfferingDAO method getAllowedFeatureOfInterestTypes.

/**
 * Query allowed FeatureOfInterestTypes for offering
 *
 * @param offeringIdentifier
 *            Offering identifier
 * @param session
 *            Hibernate session
 * @return Allowed FeatureOfInterestTypes
 */
public List<String> getAllowedFeatureOfInterestTypes(String offeringIdentifier, Session session) {
    if (HibernateHelper.isEntitySupported(OfferingEntity.class)) {
        Criteria criteria = getDefaultTransactionalCriteria(session).add(Restrictions.eq(OfferingEntity.IDENTIFIER, offeringIdentifier));
        LOGGER.debug("QUERY getAllowedFeatureOfInterestTypes(offering): {}", HibernateHelper.getSqlString(criteria));
        OfferingEntity offering = (OfferingEntity) criteria.uniqueResult();
        if (offering != null) {
            List<String> list = Lists.newArrayList();
            for (FormatEntity featureOfInterestType : offering.getFeatureTypes()) {
                list.add(featureOfInterestType.getFormat());
            }
            return list;
        }
    }
    return Lists.newArrayList();
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) OfferingEntity(org.n52.series.db.beans.OfferingEntity)

Example 18 with FormatEntity

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

the class OfferingDAO method getAndUpdateOrInsert.

/**
 * Insert or update and get offering
 *
 * @param assignedOffering
 *            SosOffering to insert, update or get
 * @param relatedFeatures
 *            Related feature objects
 * @param observationTypes
 *            Allowed observation type objects
 * @param featureOfInterestTypes
 *            Allowed featureOfInterest type objects
 * @param session
 *            Hibernate session
 * @return Offering object
 */
public OfferingEntity getAndUpdateOrInsert(SosOffering assignedOffering, Collection<RelatedFeatureEntity> relatedFeatures, Collection<FormatEntity> observationTypes, Collection<FormatEntity> featureOfInterestTypes, Session session) {
    OfferingEntity offering = getTOfferingForIdentifier(assignedOffering.getIdentifier(), session);
    if (offering == null) {
        offering = new OfferingEntity();
        offering.setIdentifier(assignedOffering.getIdentifier(), getDaoFactory().isStaSupportsUrls());
        if (assignedOffering.isSetName()) {
            offering.setName(assignedOffering.getFirstName().getValue());
        } else {
            offering.setName("Offering for the procedure " + assignedOffering.getIdentifier());
        }
        if (assignedOffering.isSetDescription()) {
            offering.setDescription(assignedOffering.getDescription());
        }
    }
    if (!relatedFeatures.isEmpty()) {
        offering.setRelatedFeatures(new HashSet<>(relatedFeatures));
    } else {
        offering.setRelatedFeatures(new HashSet<RelatedFeatureEntity>(0));
    }
    if (!observationTypes.isEmpty()) {
        offering.setObservationTypes(new HashSet<>(observationTypes));
    } else {
        offering.setObservationTypes(new HashSet<FormatEntity>(0));
    }
    if (!featureOfInterestTypes.isEmpty()) {
        offering.setFeatureTypes(new HashSet<>(featureOfInterestTypes));
    } else {
        offering.setFeatureTypes(new HashSet<FormatEntity>(0));
    }
    session.saveOrUpdate(offering);
    session.flush();
    session.refresh(offering);
    return offering;
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) RelatedFeatureEntity(org.n52.series.db.beans.RelatedFeatureEntity)

Example 19 with FormatEntity

use of org.n52.series.db.beans.FormatEntity 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)

Example 20 with FormatEntity

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

the class FormatDAO method getFormatEntityObject.

/**
 * Get procedure description format object
 *
 * @param format
 *            Procedure description format
 * @param session
 *            Hibernate session
 * @return Procedure description format object
 */
public FormatEntity getFormatEntityObject(String format, Session session) {
    Criteria criteria = session.createCriteria(FormatEntity.class).add(Restrictions.eq(FormatEntity.FORMAT, format));
    LOGGER.trace("QUERY getFormatEntityObject(format): {}", HibernateHelper.getSqlString(criteria));
    return (FormatEntity) criteria.uniqueResult();
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity) Criteria(org.hibernate.Criteria)

Aggregations

FormatEntity (org.n52.series.db.beans.FormatEntity)24 Session (org.hibernate.Session)7 OfferingEntity (org.n52.series.db.beans.OfferingEntity)7 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)7 Transaction (org.hibernate.Transaction)6 Criteria (org.hibernate.Criteria)5 HibernateException (org.hibernate.HibernateException)5 UnitEntity (org.n52.series.db.beans.UnitEntity)5 DatasetEntity (org.n52.series.db.beans.DatasetEntity)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)4 DateTime (org.joda.time.DateTime)3 ParseException (org.locationtech.jts.io.ParseException)3 GeoJsonReader (org.locationtech.jts.io.geojson.GeoJsonReader)3 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)3 CategoryEntity (org.n52.series.db.beans.CategoryEntity)3 FeatureEntity (org.n52.series.db.beans.FeatureEntity)3 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 HashSet (java.util.HashSet)2