use of org.n52.series.db.beans.sta.CountObservationEntity in project sensorweb-server-sta by 52North.
the class ObservationService method castToConcreteObservationType.
private ObservationEntity<?> castToConcreteObservationType(ObservationEntity observation, DatasetEntity dataset) throws STACRUDException {
ObservationEntity<?> data = null;
String value = (String) observation.getValue();
switch(dataset.getOmObservationType().getFormat()) {
case OmConstants.OBS_TYPE_MEASUREMENT:
QuantityObservationEntity quantityObservationEntity = new QuantityObservationEntity();
if (observation.hasValue()) {
if (value.equals("NaN") || value.equals("Inf") || value.equals("-Inf")) {
quantityObservationEntity.setValue(null);
} else {
quantityObservationEntity.setValue(BigDecimal.valueOf(Double.parseDouble(value)));
}
}
data = quantityObservationEntity;
break;
case OmConstants.OBS_TYPE_CATEGORY_OBSERVATION:
CategoryObservationEntity categoryObservationEntity = new CategoryObservationEntity();
if (observation.hasValue()) {
categoryObservationEntity.setValue(value);
}
data = categoryObservationEntity;
break;
case OmConstants.OBS_TYPE_COUNT_OBSERVATION:
CountObservationEntity countObservationEntity = new CountObservationEntity();
if (observation.hasValue()) {
countObservationEntity.setValue(Integer.parseInt(value));
}
data = countObservationEntity;
break;
case OmConstants.OBS_TYPE_TEXT_OBSERVATION:
TextObservationEntity textObservationEntity = new TextObservationEntity();
if (observation.hasValue()) {
textObservationEntity.setValue(value);
}
data = textObservationEntity;
break;
case OmConstants.OBS_TYPE_TRUTH_OBSERVATION:
BooleanObservationEntity booleanObservationEntity = new BooleanObservationEntity();
if (observation.hasValue()) {
booleanObservationEntity.setValue(Boolean.parseBoolean(value));
}
data = booleanObservationEntity;
break;
default:
break;
}
if (data != null) {
data.setDataset(dataset);
if (observation.getStaIdentifier() != null) {
if (getRepository().existsByStaIdentifier(observation.getStaIdentifier())) {
throw new STACRUDException("Identifier already exists!", HTTPStatus.CONFLICT);
} else {
data.setIdentifier(observation.getIdentifier());
data.setStaIdentifier(observation.getStaIdentifier());
}
} else {
String uuid = UUID.randomUUID().toString();
data.setIdentifier(uuid);
data.setStaIdentifier(uuid);
}
data.setSamplingTimeStart(observation.getSamplingTimeStart());
data.setSamplingTimeEnd(observation.getSamplingTimeEnd());
data.setResultTime(observation.getResultTime());
data.setValidTimeStart(observation.getValidTimeStart());
data.setValidTimeEnd(observation.getValidTimeEnd());
data.setSamplingGeometry(observation.getSamplingGeometry());
if (observation.getParameters() != null) {
parameterRepository.saveAll(observation.getParameters());
data.setParameters(observation.getParameters());
}
}
return data;
}
Aggregations