Search in sources :

Example 1 with DataArrayDataEntity

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!");
    }
}
Also used : NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) List(java.util.List) LinkedList(java.util.LinkedList) DataArrayDataEntity(org.n52.series.db.beans.DataArrayDataEntity) DataEntity(org.n52.series.db.beans.DataEntity) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) LinkedList(java.util.LinkedList)

Example 2 with DataArrayDataEntity

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;
}
Also used : DataArrayDataEntity(org.n52.series.db.beans.DataArrayDataEntity) ResultTemplateEntity(org.n52.series.db.beans.ResultTemplateEntity) DataEntity(org.n52.series.db.beans.DataEntity) DataArrayDataEntity(org.n52.series.db.beans.DataArrayDataEntity) GeometryDataEntity(org.n52.series.db.beans.GeometryDataEntity) ProfileDataEntity(org.n52.series.db.beans.ProfileDataEntity) ComplexDataEntity(org.n52.series.db.beans.ComplexDataEntity) ReferencedDataEntity(org.n52.series.db.beans.ReferencedDataEntity) InternalInsertResultTemplateRequest(org.n52.sos.request.InternalInsertResultTemplateRequest) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Aggregations

DataArrayDataEntity (org.n52.series.db.beans.DataArrayDataEntity)2 DataEntity (org.n52.series.db.beans.DataEntity)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ComplexDataEntity (org.n52.series.db.beans.ComplexDataEntity)1 GeometryDataEntity (org.n52.series.db.beans.GeometryDataEntity)1 ProfileDataEntity (org.n52.series.db.beans.ProfileDataEntity)1 ReferencedDataEntity (org.n52.series.db.beans.ReferencedDataEntity)1 ResultTemplateEntity (org.n52.series.db.beans.ResultTemplateEntity)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 SosResultEncoding (org.n52.shetland.ogc.sos.SosResultEncoding)1 SosResultStructure (org.n52.shetland.ogc.sos.SosResultStructure)1 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)1 InternalInsertResultTemplateRequest (org.n52.sos.request.InternalInsertResultTemplateRequest)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1