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