Search in sources :

Example 1 with VerticalMetadataEntity

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

the class ProfileGeneratorSplitter method createProfileLevel.

private List<ProfileLevel> createProfileLevel(ProfileDataEntity entity) throws OwsExceptionReport {
    Map<BigDecimal, ProfileLevel> map = Maps.newTreeMap();
    if (entity.hasValue()) {
        for (DataEntity<?> observation : entity.getValue()) {
            VerticalMetadataEntity verticalMetadata = entity.getDataset().getVerticalMetadata();
            QuantityValue levelStart = observation.hasVerticalFrom() && observation.hasVerticalInterval() ? getLevelStart(observation.getVerticalFrom(), verticalMetadata.getVerticalFromName(), verticalMetadata.getVerticalUnit()) : null;
            QuantityValue levelEnd = observation.hasVerticalTo() ? getLevelEnd(observation.getVerticalTo(), verticalMetadata.getVerticalToName(), verticalMetadata.getVerticalUnit()) : null;
            if (levelStart == null && levelEnd == null && observation.hasParameters()) {
                levelStart = getLevelStart(observation.getParameters());
                levelEnd = getLevelEnd(observation.getParameters());
            }
            if (levelStart != null || levelEnd != null) {
                BigDecimal key = getKey(levelStart, levelEnd);
                Value<?> value = creator.visit(observation);
                if (map.containsKey(key)) {
                    map.get(key).addValue(value);
                } else {
                    ProfileLevel profileLevel = new ProfileLevel();
                    profileLevel.setLevelStart(levelStart);
                    profileLevel.setLevelEnd(levelEnd);
                    if (observation.isSetGeometryEntity()) {
                        profileLevel.setLocation(observation.getGeometryEntity().getGeometry());
                    }
                    profileLevel.addValue(value);
                    map.put(key, profileLevel);
                }
            }
        }
    }
    return (List<ProfileLevel>) Lists.newArrayList(map.values());
}
Also used : VerticalMetadataEntity(org.n52.series.db.beans.VerticalMetadataEntity) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) ProfileLevel(org.n52.shetland.ogc.om.values.ProfileLevel) List(java.util.List) BigDecimal(java.math.BigDecimal)

Example 2 with VerticalMetadataEntity

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

the class ObservationPersister method checkForParameter.

private <T extends DataEntity<?>> T checkForParameter(T observation, ParameterHolder parameterHolder, ObservationContext ctx, Session session) throws OwsExceptionReport {
    if (parameterHolder.isSetParameter()) {
        if (parameterHolder.isSetFromToParameter()) {
            NamedValue<BigDecimal> fromParameter = parameterHolder.getFromParameter();
            NamedValue<BigDecimal> toParameter = parameterHolder.getToParameter();
            if (!(observation instanceof ProfileDataEntity)) {
                observation.setVerticalFrom(fromParameter.getValue().getValue());
                observation.setVerticalTo(toParameter.getValue().getValue());
            }
            // set vertical metadata
            VerticalMetadataEntity verticalMetadata = new VerticalMetadataEntity();
            verticalMetadata.setVerticalFromName(fromParameter.getName().getHref());
            verticalMetadata.setVerticalToName(toParameter.getName().getHref());
            if (fromParameter.getValue().isSetUnit()) {
                verticalMetadata.setVerticalUnit(getUnit(fromParameter.getValue().getUnitObject(), caches.units, session));
            }
            if (parameterHolder.isSetHeightDepthParameter()) {
                if (parameterHolder.isSetDepthParameter() && parameterHolder.isSetHeightParameter()) {
                    verticalMetadata.setOrientation(Integer.valueOf(0).shortValue());
                } else if (parameterHolder.isSetDepthParameter()) {
                    verticalMetadata.setOrientation(Integer.valueOf(-1).shortValue());
                } else {
                    verticalMetadata.setOrientation(Integer.valueOf(1).shortValue());
                }
            }
            ctx.setVertical(verticalMetadata);
            parameterHolder.removeParameter(fromParameter);
            parameterHolder.removeParameter(toParameter);
        } else if (parameterHolder.isSetHeightDepthParameter()) {
            NamedValue<BigDecimal> parameter = parameterHolder.getHeightDepthParameter();
            VerticalMetadataEntity verticalMetadata = new VerticalMetadataEntity();
            if (parameterHolder.isSetDepthParameter()) {
                if (!(observation instanceof ProfileDataEntity)) {
                    observation.setVerticalFrom(parameter.getValue().getValue());
                    observation.setVerticalTo(parameter.getValue().getValue());
                }
                verticalMetadata.setOrientation(Integer.valueOf(-1).shortValue());
            } else {
                if (!(observation instanceof ProfileDataEntity)) {
                    observation.setVerticalFrom(parameter.getValue().getValue());
                    observation.setVerticalTo(parameter.getValue().getValue());
                }
                verticalMetadata.setOrientation(Integer.valueOf(1).shortValue());
            }
            // set vertical metadata
            verticalMetadata.setVerticalFromName(parameter.getName().getHref());
            verticalMetadata.setVerticalToName(parameter.getName().getHref());
            if (parameter.getValue().isSetUnit()) {
                verticalMetadata.setVerticalUnit(getUnit(parameter.getValue().getUnitObject(), caches.units, session));
            }
            ctx.setVertical(verticalMetadata);
            parameterHolder.removeParameter(parameter);
        }
        if (parameterHolder.isSetParameter()) {
            Set<ParameterEntity<?>> insertParameter = daos.parameter().insertParameter(parameterHolder.getParameter(), caches.units, session);
            observation.setParameters(insertParameter);
        }
    }
    return observation;
}
Also used : VerticalMetadataEntity(org.n52.series.db.beans.VerticalMetadataEntity) ParameterEntity(org.n52.series.db.beans.parameter.ParameterEntity) NamedValue(org.n52.shetland.ogc.om.NamedValue) ProfileDataEntity(org.n52.series.db.beans.ProfileDataEntity) BigDecimal(java.math.BigDecimal)

Example 3 with VerticalMetadataEntity

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

the class VerticalMetadataDAO method getOrInsertVerticalMetadata.

public VerticalMetadataEntity getOrInsertVerticalMetadata(VerticalMetadataEntity entity, Session session) {
    VerticalMetadataEntity verticalMetadata = getVerticalMetadataFor(entity, session);
    if (verticalMetadata == null) {
        session.save(entity);
        session.flush();
        session.refresh(entity);
        return entity;
    }
    return verticalMetadata;
}
Also used : VerticalMetadataEntity(org.n52.series.db.beans.VerticalMetadataEntity)

Example 4 with VerticalMetadataEntity

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

the class VerticalMetadataDAO method getVerticalMetadataFor.

private VerticalMetadataEntity getVerticalMetadataFor(VerticalMetadataEntity verticalMetadata, Session session) {
    Criteria criteria = session.createCriteria(VerticalMetadataEntity.class).add(Restrictions.eq(VerticalMetadataEntity.PROPERTY_VERTICAL_UNIT, verticalMetadata.getVerticalUnit()));
    if (verticalMetadata.isSetOrientation()) {
        criteria.add(Restrictions.eq(VerticalMetadataEntity.PROPERTY_VERTICAL_ORIENTATION, verticalMetadata.getOrientation()));
    }
    if (verticalMetadata.isSetVerticalOriginName()) {
        criteria.add(Restrictions.eq(VerticalMetadataEntity.PROPERTY_VERTICAL_ORIGIN_NAME, verticalMetadata.getVerticalOriginName()));
    }
    if (verticalMetadata.isSetVerticalFromName()) {
        criteria.add(Restrictions.eq(VerticalMetadataEntity.PROPERTY_VERTICAL_FROM_NAME, verticalMetadata.getVerticalFromName()));
    }
    if (verticalMetadata.isSetVerticalToName()) {
        criteria.add(Restrictions.eq(VerticalMetadataEntity.PROPERTY_VERTICAL_TO_NAME, verticalMetadata.getVerticalToName()));
    }
    LOG.trace("QUERY getCategoryForIdentifier(identifier): {}", HibernateHelper.getSqlString(criteria));
    return (VerticalMetadataEntity) criteria.uniqueResult();
}
Also used : VerticalMetadataEntity(org.n52.series.db.beans.VerticalMetadataEntity) Criteria(org.hibernate.Criteria)

Example 5 with VerticalMetadataEntity

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

the class ResultHandlingHelper method getParameters.

private String getParameters(DataEntity<?> observation, String tokenSeparator, SweAbstractDataComponent resultStructure, VerticalMetadataEntity vertical) {
    SweDataRecord record = null;
    if (resultStructure instanceof SweDataArray && ((SweDataArray) resultStructure).getElementType() instanceof SweDataRecord) {
        final SweDataArray dataArray = (SweDataArray) resultStructure;
        record = (SweDataRecord) dataArray.getElementType();
    } else if (resultStructure instanceof SweDataRecord) {
        record = (SweDataRecord) resultStructure;
    } else {
        return "";
    }
    Map<Integer, String> valueOrder = getParameterDataRecord(record.getFields());
    StringBuilder builder = new StringBuilder();
    if (valueOrder != null) {
        for (Entry<Integer, String> order : valueOrder.entrySet()) {
            if (observation.hasParameters() && hasParameter(observation.getParameters(), order.getValue())) {
                builder.append(getParameterValue(observation.getParameters(), order.getValue())).append(tokenSeparator);
            } else if (vertical != null && (vertical.getVerticalFromName().equals(order.getValue()) || vertical.getVerticalToName().equals(order.getValue()))) {
                if (vertical.areVerticalNamesEqual()) {
                    builder.append(observation.getVerticalTo().toPlainString()).append(tokenSeparator);
                } else {
                    if (vertical.getVerticalFromName().equals(order.getValue())) {
                        builder.append(observation.getVerticalFrom().toPlainString()).append(tokenSeparator);
                    } else if (vertical.getVerticalToName().equals(order.getValue())) {
                        builder.append(observation.getVerticalTo().toPlainString()).append(tokenSeparator);
                    }
                }
            } else {
                builder.append("").append(tokenSeparator);
            }
        }
        return builder.delete(builder.lastIndexOf(tokenSeparator), builder.length()).toString();
    }
    return "";
}
Also used : IncDecInteger(org.n52.sos.util.IncDecInteger) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray)

Aggregations

VerticalMetadataEntity (org.n52.series.db.beans.VerticalMetadataEntity)5 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 ProfileDataEntity (org.n52.series.db.beans.ProfileDataEntity)1 ParameterEntity (org.n52.series.db.beans.parameter.ParameterEntity)1 CodeType (org.n52.shetland.ogc.gml.CodeType)1 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)1 NamedValue (org.n52.shetland.ogc.om.NamedValue)1 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)1 ProfileLevel (org.n52.shetland.ogc.om.values.ProfileLevel)1 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 ObservationValueCreator (org.n52.sos.ds.hibernate.util.observation.ObservationValueCreator)1 IncDecInteger (org.n52.sos.util.IncDecInteger)1