Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation and Design/Architectural Refactoring Updates #1548

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.n52.shetland.ogc.gml.CodeWithAuthority;
import org.n52.shetland.ogc.om.OmConstants;
import org.n52.shetland.ogc.ows.OWSConstants;
import org.n52.shetland.ogc.ows.exception.CodedException;
import org.n52.shetland.ogc.ows.exception.MissingParameterValueException;
import org.n52.shetland.ogc.ows.exception.NoApplicableCodeException;
import org.n52.shetland.ogc.ows.exception.OwsExceptionReport;
Expand Down Expand Up @@ -148,14 +149,7 @@ private OwsServiceRequest parseRequest(HttpServletRequest req) throws OwsExcepti
Object object = decode(req);
if (object != null) {
SosProcedureDescription<?> procDesc = null;
if (object instanceof SosProcedureDescription<?>) {
procDesc = (SosProcedureDescription<?>) object;
} else if (object instanceof AbstractFeature) {
procDesc = new SosProcedureDescription<AbstractFeature>((AbstractFeature) object);
} else {
throw new NoApplicableCodeException().withMessage("The requested type '{}' is not supported!",
object.getClass().getName());
}
procDesc = getSosProcedureDescription(object);

InsertSensorRequest request = new InsertSensorRequest();
request.setRequestContext(getRequestContext(req));
Expand All @@ -182,57 +176,82 @@ private OwsServiceRequest parseRequest(HttpServletRequest req) throws OwsExcepti
request.setProcedureDescriptionFormat(procDesc.getDescriptionFormat());
// observable properties
// get from parameter or from sml:output
List<String> observableProperties = checkForObservablePropertyParameter(procDesc, parameters);
if (!observableProperties.isEmpty()) {
request.setObservableProperty(observableProperties);
} else if (procDesc.getProcedureDescription() instanceof AbstractSensorML) {
request.setObservableProperty(getObservablePropertyFromAbstractSensorML(
(AbstractSensorML) procDesc.getProcedureDescription()));
} else if (isTypeRequest) {
request.setObservableProperty(Lists.newArrayList("not_defined"));
} else {
throw new NoApplicableCodeException().withMessage(
"The sensor description does not contain sml:outputs which is used to "
+ "fetch the possible observableProperties! "
+ "Please add an sml:ouput section or define the observableProperties"
+ " via 'observableProperty' URL parameter!'");
}
setRequestObservableProperty(parameters, procDesc, request, isTypeRequest);
// metadata
if (!isTypeRequest) {
SosInsertionMetadata metadata = new SosInsertionMetadata();
List<String> featureOfInterestTypes = checkForFeatureOfInterestTypeParameter(procDesc, parameters);
if (!featureOfInterestTypes.isEmpty()) {
metadata.setFeatureOfInterestTypes(featureOfInterestTypes);
} else {
metadata.setFeatureOfInterestTypes(supportedTypeRepository.getFeatureOfInterestTypesAsString());
}
List<String> observationTypes = checkForObservationTypeParameter(procDesc, parameters);
if (!observationTypes.isEmpty()) {
metadata.setObservationTypes(observationTypes);
} else if (procDesc.getProcedureDescription() instanceof AbstractProcess
&& ((AbstractProcess) procDesc.getProcedureDescription()).isSetOutputs()) {
metadata.setObservationTypes(getObservationTypeFrom(
((AbstractProcess) procDesc.getProcedureDescription()).getOutputs()));
} else if (procDesc.getProcedureDescription() instanceof SensorML
&& ((SensorML) procDesc.getProcedureDescription()).isWrapper()) {
Set<String> obsTyp = Sets.newHashSet();
for (AbstractProcess abstractProcess : ((SensorML) procDesc.getProcedureDescription())
.getMembers()) {
if (abstractProcess.isSetOutputs()) {
obsTyp.addAll(getObservationTypeFrom(abstractProcess.getOutputs()));
}
}
metadata.setObservationTypes(obsTyp);
} else {
metadata.setObservationTypes(supportedTypeRepository.getObservationTypesAsString());
}
setMetadataFeatureOfInterestTypes(parameters, procDesc, metadata);
setMetadataObservationTypes(parameters, procDesc, metadata);
request.setMetadata(metadata);
}
return request;
}
throw new InvalidRequestException().withMessage("The requested sensor description null is not supported!");
}

private void setMetadataObservationTypes(Map<String, String> parameters, SosProcedureDescription<?> procDesc, SosInsertionMetadata metadata) throws OwsExceptionReport {
List<String> observationTypes = checkForObservationTypeParameter(procDesc, parameters);
if (!observationTypes.isEmpty()) {
metadata.setObservationTypes(observationTypes);
} else if (procDesc.getProcedureDescription() instanceof AbstractProcess
&& ((AbstractProcess) procDesc.getProcedureDescription()).isSetOutputs()) {
metadata.setObservationTypes(getObservationTypeFrom(
((AbstractProcess) procDesc.getProcedureDescription()).getOutputs()));
} else if (procDesc.getProcedureDescription() instanceof SensorML
&& ((SensorML) procDesc.getProcedureDescription()).isWrapper()) {
Set<String> obsTyp = Sets.newHashSet();
for (AbstractProcess abstractProcess : ((SensorML) procDesc.getProcedureDescription())
.getMembers()) {
if (abstractProcess.isSetOutputs()) {
obsTyp.addAll(getObservationTypeFrom(abstractProcess.getOutputs()));
}
}
metadata.setObservationTypes(obsTyp);
} else {
metadata.setObservationTypes(supportedTypeRepository.getObservationTypesAsString());
}
}

private void setMetadataFeatureOfInterestTypes(Map<String, String> parameters, SosProcedureDescription<?> procDesc, SosInsertionMetadata metadata) throws OwsExceptionReport {
List<String> featureOfInterestTypes = checkForFeatureOfInterestTypeParameter(procDesc, parameters);
if (!featureOfInterestTypes.isEmpty()) {
metadata.setFeatureOfInterestTypes(featureOfInterestTypes);
} else {
metadata.setFeatureOfInterestTypes(supportedTypeRepository.getFeatureOfInterestTypesAsString());
}
}

private void setRequestObservableProperty(Map<String, String> parameters, SosProcedureDescription<?> procDesc, InsertSensorRequest request, boolean isTypeRequest) throws OwsExceptionReport {
List<String> observableProperties = checkForObservablePropertyParameter(procDesc, parameters);
if (!observableProperties.isEmpty()) {
request.setObservableProperty(observableProperties);
} else if (procDesc.getProcedureDescription() instanceof AbstractSensorML) {
request.setObservableProperty(getObservablePropertyFromAbstractSensorML(
(AbstractSensorML) procDesc.getProcedureDescription()));
} else if (isTypeRequest) {
request.setObservableProperty(Lists.newArrayList("not_defined"));
} else {
throw new NoApplicableCodeException().withMessage(
"The sensor description does not contain sml:outputs which is used to "
+ "fetch the possible observableProperties! "
+ "Please add an sml:ouput section or define the observableProperties"
+ " via 'observableProperty' URL parameter!'");
}
}

private static SosProcedureDescription<?> getSosProcedureDescription(Object object) throws CodedException {
SosProcedureDescription<?> procDesc;
if (object instanceof SosProcedureDescription<?>) {
procDesc = (SosProcedureDescription<?>) object;
} else if (object instanceof AbstractFeature) {
procDesc = new SosProcedureDescription<AbstractFeature>((AbstractFeature) object);
} else {
throw new NoApplicableCodeException().withMessage("The requested type '{}' is not supported!",
object.getClass().getName());
}
return procDesc;
}

private String getServiceParameterValue(Map<String, String> map) {
final String service = getParameterValue(OWSConstants.RequestParams.service, map);
if (Strings.isNullOrEmpty(service)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private TemporalFilter createTemporalFilter(String name, String value, String op
}

private TemporalFilter createTemporalFilter(String name, String value, TimeOperator timeOperator,
String valueReference) throws DecodingException {
String valueReference) throws DecodingException {
String[] times = value.split("/");
final Time time;
if (times.length == 1 && timeOperator != TimeOperator.TM_During) {
Expand Down Expand Up @@ -355,8 +355,8 @@ protected SpatialFilter decodeSpatialFilter(String name, List<String> parameterV
double[] coordinates = values.stream().mapToDouble(Double::valueOf).toArray();

geometry = factory.createPolygon(new Coordinate[] { new Coordinate(coordinates[0], coordinates[1]),
new Coordinate(coordinates[0], coordinates[3]), new Coordinate(coordinates[2], coordinates[3]),
new Coordinate(coordinates[2], coordinates[1]), new Coordinate(coordinates[0], coordinates[1]) });
new Coordinate(coordinates[0], coordinates[3]), new Coordinate(coordinates[2], coordinates[3]),
new Coordinate(coordinates[2], coordinates[1]), new Coordinate(coordinates[0], coordinates[1]) });

return new SpatialFilter(SpatialOperator.BBOX, geometry, valueReference);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.n52.sos.decode.kvp;

import org.n52.shetland.ogc.filter.TemporalFilter;
import org.n52.svalbard.decode.exception.DecodingException;

import java.util.List;

public interface CreateTemporalFilter {

TemporalFilter decodeTemporalFilter(String name, List<String> parameterValues) throws DecodingException;

TemporalFilter createTemporalFilter(String name, String value, String operator, String valueReference) throws DecodingException;

TemporalFilter createTemporalFilter(String value, String name, String valueReference)
throws DecodingException;

public TemporalFilter decodeTemporalFilter();

TemporalFilter createTemporalFilter();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.n52.sos.decode.kvp;

import org.n52.shetland.ogc.filter.FilterConstants;
import org.n52.shetland.ogc.filter.TemporalFilter;
import org.n52.svalbard.decode.exception.DecodingException;

import java.util.List;

public class ParameterValuesSizeEqualThree implements CreateTemporalFilter{
public TemporalFilter pmtValueSizeThree(String name, List<String> parameterValues) throws DecodingException {
return createTemporalFilter(name,
parameterValues.get(2),
parameterValues.get(1),
parameterValues.get(0));
}

@Override
public TemporalFilter decodeTemporalFilter(String name, List<String> parameterValues) throws DecodingException {
return null;
}

@Override
public TemporalFilter createTemporalFilter(String name, String value, String operator, String valueReference)
throws DecodingException {
FilterConstants.TimeOperator timeOperator;
try {
timeOperator = FilterConstants.TimeOperator.from(operator);
} catch (IllegalArgumentException e1) {
try {
timeOperator = FilterConstants.TimeOperator.from(FilterConstants.TimeOperator2.from(operator));
} catch (IllegalArgumentException e2) {
throw new DecodingException(name, "Unsupported operator '%s'!", operator);
}
}
return createTemporalFilter(name, value, String.valueOf(timeOperator), valueReference);
}

@Override
public TemporalFilter createTemporalFilter(String value, String name, String valueReference) throws DecodingException {
return null;
}

@Override
public TemporalFilter decodeTemporalFilter() {
return null;
}

@Override
public TemporalFilter createTemporalFilter() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.n52.sos.decode.kvp;


import org.n52.shetland.ogc.filter.FilterConstants;
import org.n52.shetland.ogc.filter.TemporalFilter;
import org.n52.svalbard.decode.exception.DecodingException;

import java.util.List;

class ParameterValuesSizeEqualTwo implements CreateTemporalFilter {
public TemporalFilter pmtValueSizeTwo(String name, List<String> parameterValues) throws DecodingException {
return createTemporalFilter(parameterValues.get(1), name, parameterValues.get(0));
}

@Override
public TemporalFilter decodeTemporalFilter(String name, List<String> parameterValues) throws DecodingException {
return null;
}

@Override
public TemporalFilter createTemporalFilter(String name, String value, String operator, String valueReference) throws DecodingException {
return null;
}

@Override
public TemporalFilter createTemporalFilter(String value, String name, String valueReference)
throws DecodingException {
switch (value.split("/").length) {
case 1:
return createTemporalFilter(name, value, String.valueOf(FilterConstants.TimeOperator.TM_Equals), valueReference);
case 2:
return createTemporalFilter(name, value, String.valueOf(FilterConstants.TimeOperator.TM_During), valueReference);
default:
throw new DecodingException(name, "The paramter value '%s' is invalid!", value);
}
}

@Override
public TemporalFilter decodeTemporalFilter() {
return null;
}

@Override
public TemporalFilter createTemporalFilter() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.n52.sos.converter;

import org.n52.shetland.ogc.om.NamedValue;
import org.n52.shetland.ogc.om.ParameterHolder;

import java.util.List;

import static org.n52.sos.converter.EprtrConverter.CONFIDENTIAL_CODE;
import static org.n52.sos.converter.EprtrConverter.CONFIDENTIAL_INDICATOR;

public class AssessConfidential {

EprtrConverter eprtrConverter = new EprtrConverter();

boolean containsConfidentialCode(List<NamedValue<?>> parameters) {
for (NamedValue<?> namedValue : parameters) {
if (namedValue.getName().getHref().equalsIgnoreCase(CONFIDENTIAL_CODE)) {
return true;
}
}
return false;
}

boolean containsConfidentialIndicator(List<NamedValue<?>> parameters) {
for (NamedValue<?> namedValue : parameters) {
if (namedValue.getName().getHref().equalsIgnoreCase(CONFIDENTIAL_INDICATOR)) {
return true;
}
}
return false;
}

String getConfidentialIndicator(String confidentialCode, ParameterHolder parameterHolder) {
String confidentialIndicator = eprtrConverter.getParameter(parameterHolder, CONFIDENTIAL_INDICATOR);
return confidentialIndicator != null && !confidentialIndicator.isEmpty() ? confidentialIndicator
: confidentialCode != null && !confidentialCode.isEmpty() ? "true" : "false";
}
}
Loading