Skip to content

Commit

Permalink
Add feature to not abort the insertion of observations via InsertResu…
Browse files Browse the repository at this point in the history
…lt whether some observations already exist in the database.

The default behavior is that the insertion would fail but with the new setting, the user can enable to insert the not existing observations and ignore the existing ones.
  • Loading branch information
Carsten Hollmann committed Jul 9, 2019
1 parent 4bb4fae commit 7eebd83
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ private ServiceConfiguration() {

private boolean mergeForEprtr = false;

private Boolean abortInsertResultForExistingObservations = true;

/**
* Returns the default token seperator for results.
* <p/>
Expand Down Expand Up @@ -563,6 +565,17 @@ public void setCheckForDuplicatedObservations(Boolean checkForDuplicatedObservat
public boolean isCheckForDuplicatedObservations() {
return checkForDuplicatedObservations;
}

@Setting(ServiceSettings.ABORT_INSERT_RESULT_FOR_EXISTING_OBSERVATIONS)
public void setAbortInsertResultForExistingObservations(Boolean abortInsertResultForExistingObservations) {
if (abortInsertResultForExistingObservations != null) {
this.abortInsertResultForExistingObservations = abortInsertResultForExistingObservations;
}
}

public boolean isAbortInsertResultForExistingObservations() {
return abortInsertResultForExistingObservations;
}

/*
* Now, we return the list of returned features and not a complex encoded
Expand Down
19 changes: 16 additions & 3 deletions core/api/src/main/java/org/n52/sos/service/ServiceSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class ServiceSettings implements SettingDefinitionProvider {

public static final String CHECK_FOR_REQUEST_DUPLICITY = "service.checkForRequestDuplicity";

public static final String ABORT_INSERT_RESULT_FOR_EXISTING_OBSERVATIONS = "service.abortInsertResultForExistingObservations";

public static final String REQUEST_TIMEOUT = "service.requestTimeout";

public static final SettingDefinitionGroup GROUP = new SettingDefinitionGroup().setTitle("Service").setOrder(2);
Expand Down Expand Up @@ -218,7 +220,7 @@ public class ServiceSettings implements SettingDefinitionProvider {
.setOrder(23)
.setKey(CHECK_FOR_DUPLICITY)
.setDefaultValue(false)
.setTitle("Should this SOS check for duplicated observations in the response?")
.setTitle("Should this SOS check for duplicated observations in the RESPONSE?")
.setDescription(
"Whether the SOS should if the response contains duplicated observations. Only necessary if you have inserted an observation for multiple offerings!");

Expand All @@ -229,10 +231,20 @@ public class ServiceSettings implements SettingDefinitionProvider {
.setOrder(24)
.setKey(CHECK_FOR_REQUEST_DUPLICITY)
.setDefaultValue(true)
.setTitle("Should this SOS check for duplicated observations in the request?")
.setTitle("Should this SOS check for duplicated observations in the REQUEST?")
.setDescription(
"Whether the SOS should check if the request contains duplicated observations. Consider that this may lead to duplicated observation in the database!!!");

public static final BooleanSettingDefinition ABORT_INSERT_RESULT_FOR_EXISTING_OBSERVATIONS_DEFINITION =
new BooleanSettingDefinition()
.setGroup(GROUP)
.setOrder(25)
.setKey(ABORT_INSERT_RESULT_FOR_EXISTING_OBSERVATIONS)
.setDefaultValue(true)
.setTitle("Should this SOS abort the InsertResult if an observation already exist but others not?")
.setDescription(
"Whether the SOS should abort the InsertResult if an observation already exist in the databse but others are new. Default is that the insertion would be stopped!");


public static final IntegerSettingDefinition REQUEST_TIMEOUT_DEFINITION =
new IntegerSettingDefinition()
Expand All @@ -257,7 +269,8 @@ public class ServiceSettings implements SettingDefinitionProvider {
INCLUDE_RESULT_TIME_FOR_MERGING_DEFINITION,
CHECK_FOR_DUPLICITY_DEFINITION,
REQUEST_TIMEOUT_DEFINITION,
CHECK_FOR_REQUEST_DUPLICITY_DEFINITION);
CHECK_FOR_REQUEST_DUPLICITY_DEFINITION,
ABORT_INSERT_RESULT_FOR_EXISTING_OBSERVATIONS_DEFINITION);

@Override
public Set<SettingDefinition<?, ?>> getSettingDefinitions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,20 @@ public synchronized InsertResultResponse insertResult(final InsertResultRequest
featureEntityMap.put(feature.getIdentifier(), feature);
}
}
if (observation.getValue() instanceof SingleObservationValue) {
observationDAO.insertObservationSingleValue(obsConst, feature,
observation, codespaceCache, unitCache, Sets.newHashSet(obsConst.getOffering()), checkForDuplicatedObservations(), session);
} else if (observation.getValue() instanceof MultiObservationValues) {
observationDAO.insertObservationMultiValue(obsConst, feature,
observation, codespaceCache, unitCache, Sets.newHashSet(obsConst.getOffering()), checkForDuplicatedObservations(), session);
try {
if (observation.getValue() instanceof SingleObservationValue) {
observationDAO.insertObservationSingleValue(obsConst, feature,
observation, codespaceCache, unitCache, Sets.newHashSet(obsConst.getOffering()), checkForDuplicatedObservations(), session);
} else if (observation.getValue() instanceof MultiObservationValues) {
observationDAO.insertObservationMultiValue(obsConst, feature,
observation, codespaceCache, unitCache, Sets.newHashSet(obsConst.getOffering()), checkForDuplicatedObservations(), session);
}
} catch (NoApplicableCodeException nace) {
if (abortInsertResultForExistingObservations()) {
throw nace;
} else {
LOGGER.debug("Already existing observation would be ignored!", nace);
}
}
if ((++insertion % FLUSH_THRESHOLD) == 0) {
session.flush();
Expand Down Expand Up @@ -602,5 +610,9 @@ public boolean isSupported() {
private boolean checkForDuplicatedObservations() {
return ServiceConfiguration.getInstance().isCheckForDuplicatedObservations();
}

private boolean abortInsertResultForExistingObservations() {
return ServiceConfiguration.getInstance().isAbortInsertResultForExistingObservations();
}

}

0 comments on commit 7eebd83

Please sign in to comment.