Skip to content

Commit

Permalink
Merge pull request #823 from 52North/feature/result_template_generate
Browse files Browse the repository at this point in the history
Feature - generate result template if not defined or transactional operations are not supported
  • Loading branch information
CarstenHollmann authored May 20, 2020
2 parents 6933b27 + d142926 commit 3253d97
Show file tree
Hide file tree
Showing 23 changed files with 1,306 additions and 457 deletions.
3 changes: 0 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ This project includes:
org.apache.xmlgraphics:batik-transcoder under The Apache Software License, Version 2.0
org.apache.xmlgraphics:batik-util under The Apache Software License, Version 2.0
org.apache.xmlgraphics:batik-xml under The Apache Software License, Version 2.0
org.eclipse.emf.common under The Eclipse Public License Version 1.0
org.eclipse.emf.ecore under The Eclipse Public License Version 1.0
org.eclipse.emf.ecore.xmi under The Eclipse Public License Version 1.0
org.locationtech.jts:jts-core under Eclipse Publish License, Version 1.0 or Eclipse Distribution License - v 1.0
parent-join under The Apache Software License, Version 2.0
Portele Schape Change schema (spec. v3.0) under The Apache Software License, Version 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,10 +1104,10 @@ private Criteria createCriteriaFor(String observedProperty, String offering, Col
if (CollectionHelper.isNotEmpty(features)) {
addFeatureOfInterestToCriteria(c, features);
}
if (Strings.isNullOrEmpty(observedProperty)) {
if (!Strings.isNullOrEmpty(observedProperty)) {
addObservablePropertyToCriteria(c, observedProperty);
}
if (Strings.isNullOrEmpty(offering)) {
if (!Strings.isNullOrEmpty(offering)) {
addOfferingToCriteria(c, offering);
}
return c;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2012-2020 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If the program is linked with libraries which are licensed under one of
* the following licenses, the combination of the program with the linked
* library is not considered a "derivative work" of the program:
*
* - Apache License, version 2.0
* - Apache Software License, version 1.0
* - GNU Lesser General Public License, version 3
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
* - Common Development and Distribution License (CDDL), version 1.0
*
* Therefore the distribution of the program linked with libraries licensed
* under the aforementioned licenses, is permitted by the copyright holders
* if the distribution is compliant with both the GNU General Public
* License version 2 and the aforementioned licenses.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
package org.n52.sos.ds.hibernate.util;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.proxy.HibernateProxy;
import org.n52.series.db.beans.DataEntity;

public interface HibernateUnproxy {

default DataEntity<?> unproxy(DataEntity<?> dataEntity, Session session) {
return !(dataEntity instanceof HibernateProxy) ? dataEntity
: ((HibernateProxy) dataEntity).getHibernateLazyInitializer()
.getSession() == null ? unproxy(session.load(DataEntity.class, dataEntity.getId()), session)
: (DataEntity<?>) Hibernate.unproxy(dataEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Copyright (C) 2012-2020 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If the program is linked with libraries which are licensed under one of
* the following licenses, the combination of the program with the linked
* library is not considered a "derivative work" of the program:
*
* - Apache License, version 2.0
* - Apache Software License, version 1.0
* - GNU Lesser General Public License, version 3
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
* - Common Development and Distribution License (CDDL), version 1.0
*
* Therefore the distribution of the program linked with libraries licensed
* under the aforementioned licenses, is permitted by the copyright holders
* if the distribution is compliant with both the GNU General Public
* License version 2 and the aforementioned licenses.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
package org.n52.sos.ds.hibernate.util.observation;

import org.n52.series.db.beans.BlobDataEntity;
import org.n52.series.db.beans.BooleanDataEntity;
import org.n52.series.db.beans.CategoryDataEntity;
import org.n52.series.db.beans.ComplexDataEntity;
import org.n52.series.db.beans.CountDataEntity;
import org.n52.series.db.beans.DataArrayDataEntity;
import org.n52.series.db.beans.DataEntity;
import org.n52.series.db.beans.GeometryDataEntity;
import org.n52.series.db.beans.HibernateRelations.HasObservablePropertyGetter;
import org.n52.series.db.beans.ProfileDataEntity;
import org.n52.series.db.beans.QuantityDataEntity;
import org.n52.series.db.beans.ReferencedDataEntity;
import org.n52.series.db.beans.TextDataEntity;
import org.n52.series.db.beans.UnitEntity;
import org.n52.shetland.ogc.UoM;
import org.n52.shetland.ogc.om.values.BooleanValue;
import org.n52.shetland.ogc.om.values.CategoryValue;
import org.n52.shetland.ogc.om.values.GeometryValue;
import org.n52.shetland.ogc.om.values.QuantityValue;
import org.n52.shetland.ogc.om.values.ReferenceValue;
import org.n52.shetland.ogc.om.values.TextValue;
import org.n52.shetland.ogc.om.values.UnknownValue;
import org.n52.shetland.ogc.om.values.Value;
import org.n52.shetland.ogc.ows.exception.OwsExceptionReport;
import org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType;
import org.n52.svalbard.decode.DecoderRepository;

public abstract class AbstractObservationValueCreator extends AbstractValuedObservationCreator<Value<?>> {

public AbstractObservationValueCreator(DecoderRepository decoderRepository) {
super(decoderRepository);
}

public AbstractObservationValueCreator(DecoderRepository decoderRepository, boolean noValues) {
super(decoderRepository, noValues);
}

@SuppressWarnings("rawtypes")
protected void addAdditonalDataEntity(DataEntity o, SweAbstractSimpleType v) {
if (o.hasValueIdentifier()) {
v.setIdentifier(o.getValueIdentifier());
}
if (o.hasValueName()) {
v.setName(o.getValueName());
}
if (o.hasValueDescription()) {
v.setDescription(o.getValueDescription());
}
}

@SuppressWarnings("rawtypes")
protected void addDefinitionFromObservableProperty(DataEntity o, SweAbstractSimpleType v) {
if (o instanceof HasObservablePropertyGetter) {
if (((HasObservablePropertyGetter) o).getObservableProperty() != null) {
v.setDefinition(((HasObservablePropertyGetter) o).getObservableProperty().getIdentifier());
}
}
}

protected UoM getUnit(UnitEntity unit) {
UoM uom = new UoM(unit.getUnit());
return uom;
}

@Override
public Value<?> visit(DataEntity o) throws OwsExceptionReport {
if (o instanceof QuantityDataEntity) {
return visit((QuantityDataEntity) o);
} else if (o instanceof BlobDataEntity) {
return visit((BlobDataEntity) o);
} else if (o instanceof BooleanDataEntity) {
return visit((BooleanDataEntity) o);
} else if (o instanceof CategoryDataEntity) {
return visit((CategoryDataEntity) o);
} else if (o instanceof ComplexDataEntity) {
return visit((ComplexDataEntity) o);
} else if (o instanceof CountDataEntity) {
return visit((CountDataEntity) o);
} else if (o instanceof GeometryDataEntity) {
return visit((GeometryDataEntity) o);
} else if (o instanceof TextDataEntity) {
return visit((TextDataEntity) o);
} else if (o instanceof DataArrayDataEntity) {
return visit((DataArrayDataEntity) o);
} else if (o instanceof ProfileDataEntity) {
return visit((ProfileDataEntity) o);
} else if (o instanceof ReferencedDataEntity) {
return visit((ReferencedDataEntity) o);
}
return null;
}

public QuantityValue visit(QuantityDataEntity o, QuantityValue v) {
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public UnknownValue visit(BlobDataEntity o, UnknownValue v) {
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public BooleanValue visit(BooleanDataEntity o, BooleanValue v) {
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public CategoryValue visit(CategoryDataEntity o, CategoryValue v) {
addAdditonalDataEntity(o, v);
addDefinitionFromObservableProperty(o, v);
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public GeometryValue visit(GeometryDataEntity o, GeometryValue v) throws OwsExceptionReport {
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public TextValue visit(TextDataEntity o, TextValue v) {
addAdditonalDataEntity(o, v);
addDefinitionFromObservableProperty(o, v);
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}

public ReferenceValue visit(ReferencedDataEntity o, ReferenceValue v) {
if (o.hasValueName()) {
v.getValue().setTitle(o.getValueName());
}
if (o.getDataset().hasUnit()) {
v.setUnit(getUnit(o.getDataset().getUnit()));
}
return v;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (C) 2012-2020 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If the program is linked with libraries which are licensed under one of
* the following licenses, the combination of the program with the linked
* library is not considered a "derivative work" of the program:
*
* - Apache License, version 2.0
* - Apache Software License, version 1.0
* - GNU Lesser General Public License, version 3
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
* - Common Development and Distribution License (CDDL), version 1.0
*
* Therefore the distribution of the program linked with libraries licensed
* under the aforementioned licenses, is permitted by the copyright holders
* if the distribution is compliant with both the GNU General Public
* License version 2 and the aforementioned licenses.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
package org.n52.sos.ds.hibernate.util.observation;

import java.util.LinkedList;
import java.util.List;

import org.apache.xmlbeans.XmlObject;
import org.n52.series.db.beans.DataArrayDataEntity;
import org.n52.series.db.beans.DataEntity;
import org.n52.shetland.ogc.ows.exception.CodedException;
import org.n52.shetland.ogc.ows.exception.NoApplicableCodeException;
import org.n52.shetland.ogc.swe.SweAbstractDataComponent;
import org.n52.shetland.ogc.swe.SweAbstractDataRecord;
import org.n52.shetland.ogc.swe.SweDataArray;
import org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding;
import org.n52.shetland.ogc.swe.encoding.SweTextEncoding;
import org.n52.shetland.util.JavaHelper;
import org.n52.svalbard.decode.DecoderRepository;
import org.n52.svalbard.decode.exception.DecodingException;
import org.n52.svalbard.util.CodingHelper;
import org.n52.svalbard.util.XmlHelper;

public abstract class AbstractValuedObservationCreator<T> implements ValuedObservationVisitor<T> {

private DecoderRepository decoderRepository;
private boolean noValues;

public AbstractValuedObservationCreator(DecoderRepository decoderRepository) {
this(decoderRepository, false);
}

public AbstractValuedObservationCreator(DecoderRepository decoderRepository, boolean noValues) {
this.decoderRepository = decoderRepository;
this.noValues = noValues;
}

protected DecoderRepository getDecoderRepository() {
return decoderRepository;
}

protected boolean isNoValues() {
return noValues;
}

protected Object decode(XmlObject xml) throws DecodingException {
return getDecoderRepository().getDecoder(CodingHelper.getDecoderKey(xml)).decode(xml);
}

protected SweDataArray createSweDataArray(DataArrayDataEntity o) throws CodedException {
try {
SweDataArray array = new SweDataArray();
decode(XmlHelper.parseXmlString(o.getResultTemplate().getEncoding()));
array.setEncoding(
(SweAbstractEncoding) decode(XmlHelper.parseXmlString(o.getResultTemplate().getEncoding())));
array.setElementType(
(SweAbstractDataComponent) decode(XmlHelper.parseXmlString(o.getResultTemplate().getStructure())));
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!");
}
}

}
Loading

0 comments on commit 3253d97

Please sign in to comment.