Skip to content

Commit

Permalink
fix dataavailability creation after changes in arctic-sea
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenHollmann committed May 2, 2022
1 parent 23bbeab commit 379b153
Showing 1 changed file with 72 additions and 32 deletions.
104 changes: 72 additions & 32 deletions handler/src/main/java/org/n52/sos/ds/GetDataAvailabilityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
@SuppressFBWarnings({ "EI_EXPOSE_REP", "EI_EXPOSE_REP2" })
public class GetDataAvailabilityHandler extends AbstractGetDataAvailabilityHandler
implements ApiQueryHelper, DatabaseQueryHelper {

Expand Down Expand Up @@ -166,11 +166,9 @@ private DataAvailability defaultProcessDataAvailability(DatasetEntity entity, GD
Session session) throws OwsExceptionReport {
TimePeriod timePeriod = createTimePeriod(entity);
if (timePeriod != null && !timePeriod.isEmpty()) {
DataAvailability dataAvailability =
new DataAvailability(getProcedureReference(entity, context.getProcedures()),
getObservedPropertyReference(entity, context.getObservableProperties()),
getFeatureOfInterestReference(entity, context.getFeaturesOfInterest()),
getOfferingReference(entity, context.getOfferings()), timePeriod);
DataAvailability dataAvailability = new DataAvailability(getProcedureReference(entity, context),
getObservedPropertyReference(entity, context), getFeatureOfInterestReference(entity, context),
getOfferingReference(entity, context), timePeriod);
if (isShowCount(context.getRequest()) && entity.getObservationCount() >= 0) {
dataAvailability.setCount(entity.getObservationCount());
}
Expand All @@ -186,8 +184,7 @@ private DataAvailability defaultProcessDataAvailability(DatasetEntity entity, GD
* Get {@link DataAvailability}s for each series
*
* @param entity
* the {@link DatasetEntity} to get
* {@link DataAvailability}s for
* the {@link DatasetEntity} to get {@link DataAvailability}s for
* @param context
* Request context to get {@link DataAvailability}s
* @param session
Expand All @@ -207,8 +204,7 @@ private void processDataAvailability(DatasetEntity entity, GDARequestContext con
* Get {@link DataAvailability}s for each offering of a series
*
* @param entity
* the {@link DatasetEntity} to get
* {@link DataAvailability}s for
* the {@link DatasetEntity} to get {@link DataAvailability}s for
* @param context
* Request context to get {@link DataAvailability}s
* @throws OwsExceptionReport
Expand Down Expand Up @@ -305,54 +301,52 @@ private List<DataAvailability> checkForDuplictation(List<DataAvailability> dataA
return checked;
}

private ReferenceType getProcedureReference(DatasetEntity entity, Map<String, ReferenceType> procedures) {
private ReferenceType getProcedureReference(DatasetEntity entity, GDARequestContext context) {
String identifier = entity.getProcedure().getIdentifier();
if (!procedures.containsKey(identifier)) {
if (!context.hasProcedures(identifier)) {
ReferenceType referenceType = new ReferenceType(identifier);
if (entity.getProcedure().isSetName()) {
referenceType.setTitle(entity.getProcedure().getName());
}
procedures.put(identifier, referenceType);
context.addProcedures(identifier, referenceType);
}
return procedures.get(identifier);
return context.getProcedures(identifier);
}

private ReferenceType getObservedPropertyReference(DatasetEntity entity,
Map<String, ReferenceType> observableProperties) {
private ReferenceType getObservedPropertyReference(DatasetEntity entity, GDARequestContext context) {
String identifier = entity.getPhenomenon().getIdentifier();
if (!observableProperties.containsKey(identifier)) {
if (!context.hasObservableProperties(identifier)) {
ReferenceType referenceType = new ReferenceType(identifier);
if (entity.getPhenomenon().isSetName()) {
referenceType.setTitle(entity.getPhenomenon().getName());
}
observableProperties.put(identifier, referenceType);
context.addObservableProperties(identifier, referenceType);
}
return observableProperties.get(identifier);
return context.getObservableProperties(identifier);
}

private ReferenceType getFeatureOfInterestReference(DatasetEntity entity,
Map<String, ReferenceType> featuresOfInterest) {
private ReferenceType getFeatureOfInterestReference(DatasetEntity entity, GDARequestContext context) {
String identifier = entity.getFeature().getIdentifier();
if (!featuresOfInterest.containsKey(identifier)) {
if (!context.hasFeaturesOfInterest(identifier)) {
ReferenceType referenceType = new ReferenceType(identifier);
if (entity.getFeature().isSetName()) {
referenceType.setTitle(entity.getFeature().getName());
}
featuresOfInterest.put(identifier, referenceType);
context.addFeaturesOfInterest(identifier, referenceType);
}
return featuresOfInterest.get(identifier);
return context.getFeaturesOfInterest(identifier);
}

private ReferenceType getOfferingReference(DatasetEntity entity, Map<String, ReferenceType> offerings) {
private ReferenceType getOfferingReference(DatasetEntity entity, GDARequestContext context) {
String identifier = entity.getOffering().getIdentifier();
if (!offerings.containsKey(identifier)) {
if (!context.hasOfferings(identifier)) {
ReferenceType referenceType = new ReferenceType(identifier);
if (entity.getOffering().isSetName()) {
referenceType.setTitle(entity.getOffering().getName());
}
offerings.put(identifier, referenceType);
context.addOfferings(identifier, referenceType);
}
return offerings.get(identifier);
return context.getOfferings(identifier);
}

/**
Expand Down Expand Up @@ -385,13 +379,11 @@ private boolean isIncludeResultTime(GetDataAvailabilityRequest request) {
}

/**
* Check if extensions contains a temporal filter with valueReference
* phenomenonTime
* Check if extensions contains a temporal filter with valueReference phenomenonTime
*
* @param extensions
* Extensions to check
* @return <code>true</code>, if extensions contains a temporal filter with
* valueReference phenomenonTime
* @return <code>true</code>, if extensions contains a temporal filter with valueReference phenomenonTime
*/
private boolean hasPhenomenonTimeFilter(Extensions extensions) {
boolean hasFilter = false;
Expand Down Expand Up @@ -485,18 +477,66 @@ public Map<String, ReferenceType> getFeaturesOfInterest() {
return Collections.unmodifiableMap(featuresOfInterest);
}

public void addFeaturesOfInterest(String key, ReferenceType reference) {
featuresOfInterest.put(key, reference);
}

public ReferenceType getFeaturesOfInterest(String key) {
return featuresOfInterest.get(key);
}

public boolean hasFeaturesOfInterest(String key) {
return featuresOfInterest.containsKey(key);
}

public Map<String, ReferenceType> getObservableProperties() {
return Collections.unmodifiableMap(observableProperties);
}

public void addObservableProperties(String key, ReferenceType reference) {
observableProperties.put(key, reference);
}

public ReferenceType getObservableProperties(String key) {
return observableProperties.get(key);
}

public boolean hasObservableProperties(String key) {
return observableProperties.containsKey(key);
}

public Map<String, ReferenceType> getProcedures() {
return Collections.unmodifiableMap(procedures);
}

public void addProcedures(String key, ReferenceType reference) {
procedures.put(key, reference);
}

public ReferenceType getProcedures(String key) {
return procedures.get(key);
}

public boolean hasProcedures(String key) {
return procedures.containsKey(key);
}

public Map<String, ReferenceType> getOfferings() {
return Collections.unmodifiableMap(offerings);
}

public void addOfferings(String key, ReferenceType reference) {
offerings.put(key, reference);
}

public ReferenceType getOfferings(String key) {
return offerings.get(key);
}

public boolean hasOfferings(String key) {
return offerings.containsKey(key);
}

public GDARequestContext setDataAvailabilityList(List<DataAvailability> dataAvailabilityValues) {
this.dataAvailabilityValues.clear();
return addDataAvailabilities(dataAvailabilityValues);
Expand Down

0 comments on commit 379b153

Please sign in to comment.