-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #823 from 52North/feature/result_template_generate
Feature - generate result template if not defined or transactional operations are not supported
- Loading branch information
Showing
23 changed files
with
1,306 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
hibernate/common/src/main/java/org/n52/sos/ds/hibernate/util/HibernateUnproxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
178 changes: 178 additions & 0 deletions
178
.../main/java/org/n52/sos/ds/hibernate/util/observation/AbstractObservationValueCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
...main/java/org/n52/sos/ds/hibernate/util/observation/AbstractValuedObservationCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.