use of org.n52.series.db.beans.DataArrayDataEntity in project SOS by 52North.
the class AbstractValuedObservationCreator method createSweDataArray.
protected SweDataArray createSweDataArray(DataArrayDataEntity o) throws CodedException {
try {
SweDataArray array = new SweDataArray();
array.setEncoding(getEncoding(o));
array.setElementType(getStructure(o));
if (!isNoValues()) {
if (o.isSetStringValue()) {
array.setXml(null);
List<List<String>> values = new LinkedList<>();
for (String block : o.getStringValue().split(((SweTextEncoding) array.getEncoding()).getBlockSeparator())) {
List<String> v = new LinkedList<>();
for (String value : block.split(((SweTextEncoding) array.getEncoding()).getTokenSeparator())) {
v.add(value);
}
values.add(v);
}
array.setValues(values);
} else if (o.getValue() != null && !o.getValue().isEmpty()) {
int i = ((SweAbstractDataRecord) array.getElementType()).getFieldIndexByIdentifier(o.getDataset().getPhenomenon().getIdentifier()) == 0 ? 1 : 0;
List<List<String>> values = new LinkedList<>();
for (DataEntity<?> v : o.getValue()) {
List<String> value = new LinkedList<>();
if (i == 0) {
value.add(v.getDataset().getPhenomenon().getName());
value.add(JavaHelper.asString(v.getValue()));
} else {
value.add(JavaHelper.asString(v.getValue()));
value.add(v.getDataset().getPhenomenon().getName());
}
values.add(value);
}
array.setValues(values);
}
}
return array;
} catch (DecodingException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("Error while creating SweDataArray from database entity!");
}
}
use of org.n52.series.db.beans.DataArrayDataEntity in project SOS by 52North.
the class ObservationPersister method visit.
@Override
public DataEntity<?> visit(SweDataArrayValue value) throws OwsExceptionReport {
DataArrayDataEntity dataArray = observationFactory.sweDataEntityArray();
// if (value.getValue().getElementType() instanceof
// SweAbstractDataRecord
// && checkFields((SweAbstractDataRecord)
// value.getValue().getElementType())) {
// dataArray = persist(dataArray, new HashSet<DataEntity<?>>());
// persistChildren(value.getValue(), dataArray.getId());
// } else {
dataArray.setStringValue(value.getValue().getValueAsString());
dataArray = (DataArrayDataEntity) persist((DataEntity) dataArray, new HashSet<DataEntity<?>>());
// }
// create result template
InternalInsertResultTemplateRequest insertResultTemplateRequest = new InternalInsertResultTemplateRequest();
insertResultTemplateRequest.setObservationEncoding(new SosResultEncoding(value.getValue().getEncoding(), value.getValue().getEncoding().getXml()));
insertResultTemplateRequest.setObservationStructure(new SosResultStructure(value.getValue().getElementType(), value.getValue().getElementType().getXml()));
insertResultTemplateRequest.setIdentifier("OBS_" + IdGenerator.generate(value.getValue().getElementType().getXml()));
ResultTemplateEntity resultTemplate = daoFactory.getResultTemplateDAO().checkOrInsertResultTemplate(insertResultTemplateRequest, dataArray.getDataset(), session);
dataArray.setResultTemplate(resultTemplate);
session.update(dataArray);
return dataArray;
}
Aggregations