use of org.n52.series.db.beans.CategoryEntity in project SOS by 52North.
the class CategoryDAO method getOrInsertCategory.
public CategoryEntity getOrInsertCategory(String value, String name, String description, Session session) {
CategoryEntity category = getCategoryForIdentifier(value, session);
if (category == null) {
category = new CategoryEntity();
addIdentifier(category, value, session);
addName(category, name, session);
addDescription(category, description);
session.save(category);
session.flush();
session.refresh(category);
}
return category;
}
use of org.n52.series.db.beans.CategoryEntity in project SOS by 52North.
the class CategoryDAO method getOrInsertCategory.
public CategoryEntity getOrInsertCategory(PhenomenonEntity obsProp, Session session) {
CategoryEntity category = getCategoryForIdentifier(obsProp.getIdentifier(), session);
if (category == null) {
category = new CategoryEntity();
category.setIdentifier(obsProp.getIdentifier(), getDaoFactory().isStaSupportsUrls());
category.setIdentifierCodespace(obsProp.getIdentifierCodespace());
category.setName(obsProp.getName());
category.setNameCodespace(obsProp.getNameCodespace());
category.setDescription(obsProp.getDescription());
session.save(category);
session.flush();
session.refresh(category);
}
return category;
}
use of org.n52.series.db.beans.CategoryEntity in project SOS by 52North.
the class CategoryDAO method getCategoryForIdentifier.
public CategoryEntity getCategoryForIdentifier(String identifier, Session session) {
Criteria criteria = session.createCriteria(CategoryEntity.class).add(Restrictions.eq(CategoryEntity.IDENTIFIER, identifier));
LOGGER.trace("QUERY getCategoryForIdentifier(identifier): {}", HibernateHelper.getSqlString(criteria));
return (CategoryEntity) criteria.uniqueResult();
}
use of org.n52.series.db.beans.CategoryEntity in project SOS by 52North.
the class InsertSensorHandler method insertSensor.
@Override
public synchronized InsertSensorResponse insertSensor(final InsertSensorRequest request) throws OwsExceptionReport {
final InsertSensorResponse response = new InsertSensorResponse();
response.setService(request.getService());
response.setVersion(request.getVersion());
final String assignedProcedureID = request.getAssignedProcedureIdentifier();
// we use only the first offering for the response because swes 2.0
// specifies only one single element
final SosOffering firstAssignedOffering = request.getFirstAssignedOffering();
Session session = null;
Transaction transaction = null;
try {
session = getHibernateSessionHolder().getSession();
transaction = session.beginTransaction();
FormatDAO formatDAO = new FormatDAO();
final FormatEntity procedureDescriptionFormat = formatDAO.getOrInsertFormatEntity(request.getProcedureDescriptionFormat(), session);
if (procedureDescriptionFormat != null) {
final ProcedureEntity hProcedure = new ProcedureDAO(getDaoFactory()).getOrInsertProcedure(assignedProcedureID, procedureDescriptionFormat, request.getProcedureDescription(), request.isType(), session);
// TODO: set correct validTime,
new ProcedureHistoryDAO(getDaoFactory()).insert(hProcedure, procedureDescriptionFormat, getSensorDescriptionFromProcedureDescription(request.getProcedureDescription()), new DateTime(DateTimeZone.UTC), session);
if (!request.isType()) {
final List<FormatEntity> observationTypes = formatDAO.getOrInsertFormatEntitys(request.getMetadata().getObservationTypes(), session);
final List<FormatEntity> featureOfInterestTypes = formatDAO.getOrInsertFormatEntitys(request.getMetadata().getFeatureOfInterestTypes(), session);
if (observationTypes != null && featureOfInterestTypes != null) {
final List<PhenomenonEntity> hObservableProperties = getOrInsertNewObservableProperties(request.getObservableProperty(), request.getProcedureDescription(), session);
Map<String, UnitEntity> hUnits = getOrInsertNewUnits(hObservableProperties, request.getProcedureDescription(), session);
final AbstractSeriesDAO seriesDAO = getDaoFactory().getSeriesDAO();
final OfferingDAO offeringDAO = getDaoFactory().getOfferingDAO();
Set<String> allParentOfferings = getAllParentOfferings(hProcedure);
Set<String> parentOfferings = getParentOfferings(hProcedure);
for (final SosOffering assignedOffering : request.getAssignedOfferings()) {
final List<RelatedFeatureEntity> hRelatedFeatures = new LinkedList<RelatedFeatureEntity>();
if (request.getRelatedFeatures() != null && !request.getRelatedFeatures().isEmpty()) {
final RelatedFeatureDAO relatedFeatureDAO = getDaoFactory().getRelatedFeatureDAO();
for (final SwesFeatureRelationship relatedFeature : request.getRelatedFeatures()) {
hRelatedFeatures.addAll(relatedFeatureDAO.getOrInsertRelatedFeature(relatedFeature.getFeature(), relatedFeature.getRole(), session));
}
}
final OfferingEntity hOffering = offeringDAO.getAndUpdateOrInsert(new SosOffering(assignedOffering.getIdentifier(), assignedOffering.getOfferingName()), hRelatedFeatures, observationTypes, featureOfInterestTypes, session);
// is a child/component
if (!parentOfferings.isEmpty() && !allParentOfferings.isEmpty() && hProcedure.hasParents() && !allParentOfferings.contains(assignedOffering.getIdentifier()) && !parentOfferings.contains(assignedOffering.getIdentifier())) {
offeringDAO.updateParentOfferings(parentOfferings, hOffering, session);
}
for (final PhenomenonEntity hObservableProperty : hObservableProperties) {
CategoryEntity hCategory = getCategory(hObservableProperty, request, session);
ObservationContext ctx = new ObservationContext().setCategory(hCategory).setOffering(hOffering).setPhenomenon(hObservableProperty).setProcedure(hProcedure).setPublish(false).setHiddenChild(!assignedOffering.isParentOffering());
checkForMobileInsituFlags(ctx, request.getProcedureDescription().getProcedureDescription());
if (hUnits.containsKey(hObservableProperty.getIdentifier())) {
ctx.setUnit(hUnits.get(hObservableProperty.getIdentifier()));
}
if (request.getProcedureDescription().isSetFeaturesOfInterestMap()) {
boolean inserted = false;
for (AbstractFeature feature : request.getProcedureDescription().getFeaturesOfInterestMap().values()) {
if (feature instanceof FeatureWithGeometry && ((FeatureWithGeometry) feature).isSetGeometry()) {
ctx.setFeatureOfInterest(getDaoFactory().getFeatureOfInterestDAO().checkOrInsert(feature, session));
inserted = true;
seriesDAO.getOrInsert(ctx, session);
}
}
if (!inserted) {
seriesDAO.getOrInsert(ctx, session);
}
} else {
seriesDAO.getOrInsert(ctx, session);
}
if (checkPreconditionsOfStaticReferenceValues(request)) {
addStaticReferenceValues(request, session, procedureDescriptionFormat, hProcedure, observationTypes, featureOfInterestTypes, hRelatedFeatures, hOffering, hObservableProperty, seriesDAO);
}
}
}
// TODO: parent and child procedures
} else {
throw new NoApplicableCodeException().withMessage("Error while inserting InsertSensor into database!");
}
}
response.setAssignedProcedure(assignedProcedureID);
response.setAssignedOffering(firstAssignedOffering.getIdentifier());
} else {
throw new InvalidParameterValueException(Sos2Constants.InsertSensorParams.procedureDescriptionFormat, request.getProcedureDescriptionFormat());
}
session.flush();
transaction.commit();
} catch (final HibernateException he) {
if (transaction != null) {
transaction.rollback();
}
throw new NoApplicableCodeException().causedBy(he).withMessage("Error while inserting sensor data into database!");
} finally {
getHibernateSessionHolder().returnSession(session);
}
return response;
}
use of org.n52.series.db.beans.CategoryEntity in project sensorweb-server-sta by 52North.
the class ObservationService method checkCategory.
private CategoryEntity checkCategory() throws STACRUDException {
synchronized (getLock(STA)) {
if (!categoryRepository.existsByIdentifier(STA)) {
CategoryEntity category = new CategoryEntity();
category.setIdentifier(STA);
category.setName(STA);
category.setDescription("Default SOS category");
return categoryRepository.save(category);
} else {
return categoryRepository.findByIdentifier(STA).get();
}
}
}
Aggregations