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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations