Skip to content

Commit

Permalink
Refactor configuration of service.serviceURL
Browse files Browse the repository at this point in the history
Reduce duplicate code by injecting SosHelper
  • Loading branch information
Carsten Hollmann committed May 27, 2020
1 parent 1972811 commit 92e3b4e
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 150 deletions.
2 changes: 1 addition & 1 deletion core/api/src/main/java/org/n52/sos/util/SosHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class SosHelper {
/**
* Hide utility constructor
*/
protected SosHelper() {
public SosHelper() {
}

public String getServiceURL() {
Expand Down
3 changes: 3 additions & 0 deletions core/api/src/main/resources/contexts/configured/sos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<bean id="geometryHandler"
class="org.n52.sos.util.GeometryHandler" />

<bean id="sosHelper"
class="org.n52.sos.util.SosHelper" />

<bean id="encoderRepository"
class="org.n52.sos.coding.encode.SosEncoderRepository" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
package org.n52.sos.inspire.capabilities;

import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collections;
import java.util.Set;

import javax.inject.Inject;

import org.n52.faroe.annotation.Configurable;
import org.n52.iceland.ogc.ows.OwsServiceMetadataRepository;
import org.n52.iceland.ogc.ows.extension.OwsOperationMetadataExtensionProvider;
import org.n52.iceland.ogc.ows.extension.OwsOperationMetadataExtensionProviderKey;
import org.n52.shetland.ogc.ows.service.OwsServiceRequest;
import org.n52.shetland.ogc.ows.service.GetCapabilitiesRequest;
import org.n52.iceland.service.ServiceSettings;
import org.n52.janmayen.http.MediaType;
import org.n52.janmayen.http.MediaTypes;
import org.n52.shetland.inspire.InspireConformity;
import org.n52.shetland.inspire.InspireConformity.InspireDegreeOfConformity;
import org.n52.shetland.inspire.InspireConformityCitation;
import org.n52.shetland.inspire.InspireConstants;
import org.n52.shetland.inspire.InspireDateOfCreation;
Expand All @@ -52,7 +52,6 @@
import org.n52.shetland.inspire.InspireResourceLocator;
import org.n52.shetland.inspire.InspireTemporalReference;
import org.n52.shetland.inspire.InspireUniqueResourceIdentifier;
import org.n52.shetland.inspire.InspireConformity.InspireDegreeOfConformity;
import org.n52.shetland.inspire.dls.FullInspireExtendedCapabilities;
import org.n52.shetland.inspire.dls.MinimalInspireExtendedCapabilities;
import org.n52.shetland.ogc.gml.time.TimeInstant;
Expand All @@ -65,6 +64,8 @@
import org.n52.shetland.ogc.ows.exception.NoApplicableCodeException;
import org.n52.shetland.ogc.ows.exception.OwsExceptionReport;
import org.n52.shetland.ogc.ows.extension.Extension;
import org.n52.shetland.ogc.ows.service.GetCapabilitiesRequest;
import org.n52.shetland.ogc.ows.service.OwsServiceRequest;
import org.n52.shetland.ogc.sos.Sos2Constants;
import org.n52.shetland.ogc.sos.SosConstants;
import org.n52.shetland.ogc.swe.simpleType.SweCount;
Expand All @@ -76,13 +77,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

import org.n52.iceland.ogc.ows.extension.OwsOperationMetadataExtensionProvider;
import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
import org.n52.faroe.annotation.Configurable;
import org.n52.faroe.annotation.Setting;
import org.n52.iceland.ogc.ows.OwsServiceMetadataRepository;

/**
* Provider for the INSPIRE ExtendedCapabilities
*
Expand All @@ -99,21 +93,16 @@ public class InspireExtendedCapabilitiesProvider extends AbstractInspireProvider

private OwsServiceMetadataRepository serviceMetadataRepository;

private String serviceURL;
private SosHelper sosHelper;

@Inject
public void setServiceMetadataRepository(OwsServiceMetadataRepository repo) {
this.serviceMetadataRepository = repo;
}

@Setting(ServiceSettings.SERVICE_URL)
public void setServiceURL(final URI serviceURL) throws ConfigurationError {
Validation.notNull("Service URL", serviceURL);
String url = serviceURL.toString();
if (url.contains("?")) {
url = url.split("[?]")[0];
}
this.serviceURL = url;
@Inject
public void setSosHelperL(SosHelper sosHelper) {
this.sosHelper = sosHelper;
}

public OwsServiceProvider getOwsServiceProvider() {
Expand Down Expand Up @@ -240,7 +229,8 @@ private void addMetadataUrl(FullInspireExtendedCapabilities fullInspireExtendedC
private InspireResourceLocator getResourceLocator() throws OwsExceptionReport {
try {
InspireResourceLocator resourceLocator =
new InspireResourceLocator(SosHelper.getGetCapabilitiesKVPRequest(serviceURL).toString());
new InspireResourceLocator(SosHelper.getGetCapabilitiesKVPRequest(sosHelper.getServiceURL())
.toString());
resourceLocator.addMediaType(MediaTypes.APPLICATION_XML);
return resourceLocator;
} catch (MalformedURLException ex) {
Expand Down Expand Up @@ -305,7 +295,7 @@ private Set<InspireUniqueResourceIdentifier> getSpatialDataSetIdentifier(String
if (getInspireHelper().isSetNamespace()) {
iuri.setNamespace(getInspireHelper().getNamespace());
} else {
iuri.setNamespace(serviceURL);
iuri.setNamespace(sosHelper.getServiceURL());
}
spatialDataSetIdentifier.add(iuri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@
*/
package org.n52.sos.inspire.offering;

import java.net.URI;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Stream;

import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
import javax.inject.Inject;

import org.n52.faroe.annotation.Configurable;
import org.n52.faroe.annotation.Setting;
import org.n52.iceland.service.ServiceSettings;
import org.n52.shetland.inspire.InspireConstants;
import org.n52.shetland.inspire.InspireObject;
import org.n52.shetland.inspire.InspireUniqueResourceIdentifier;
Expand All @@ -49,6 +47,7 @@
import org.n52.sos.inspire.settings.InspireSettings;
import org.n52.sos.ogc.sos.SosObservationOfferingExtensionKey;
import org.n52.sos.ogc.sos.SosObservationOfferingExtensionProvider;
import org.n52.sos.util.SosHelper;

import com.google.common.base.Strings;

Expand All @@ -71,7 +70,7 @@ public class InspireOfferingExtensionProvider extends AbstractInspireProvider

private String namespace;

private String serviceURL;
private SosHelper sosHelper;

@Setting(InspireSettings.INSPIRE_ENABLED_KEY)
public void setEnabled(boolean enabled) {
Expand All @@ -87,16 +86,12 @@ public void setNamespace(String namespace) {
this.namespace = namespace;
}

@Setting(ServiceSettings.SERVICE_URL)
public void setServiceURL(final URI serviceURL) throws ConfigurationError {
Validation.notNull("Service URL", serviceURL);
String url = serviceURL.toString();
if (url.contains("?")) {
url = url.split("[?]")[0];
}
this.serviceURL = url;
@Inject
public void setSosHelperL(SosHelper sosHelper) {
this.sosHelper = sosHelper;
}


@Override
public Set<SosObservationOfferingExtensionKey> getKeys() {
return Collections.unmodifiableSet(KEYS);
Expand All @@ -122,7 +117,7 @@ private InspireUniqueResourceIdentifier getSpatialDataSetIdentifier(String ident
if (!Strings.isNullOrEmpty(namespace)) {
iuri.setNamespace(namespace);
} else {
iuri.setNamespace(serviceURL);
iuri.setNamespace(sosHelper.getServiceURL());
}
return iuri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
*/
package org.n52.sos.ds.procedure;

import java.net.URI;
import java.util.Locale;

import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
import javax.inject.Inject;

import org.n52.faroe.annotation.Configurable;
import org.n52.faroe.annotation.Setting;
import org.n52.iceland.binding.BindingRepository;
Expand All @@ -41,14 +40,14 @@
import org.n52.iceland.i18n.I18NDAORepository;
import org.n52.iceland.i18n.I18NSettings;
import org.n52.iceland.ogc.ows.OwsServiceMetadataRepository;
import org.n52.iceland.service.ServiceSettings;
import org.n52.iceland.service.operator.ServiceOperatorRepository;
import org.n52.janmayen.i18n.LocaleHelper;
import org.n52.sos.cache.SosContentCache;
import org.n52.sos.ds.procedure.generator.AbstractProcedureDescriptionGeneratorFactoryRepository;
import org.n52.sos.service.ProcedureDescriptionSettings;
import org.n52.sos.service.SosSettings;
import org.n52.sos.util.GeometryHandler;
import org.n52.sos.util.SosHelper;
import org.n52.svalbard.decode.DecoderRepository;

@Configurable
Expand All @@ -64,7 +63,7 @@ public class AbstractProcedureCreationContext {
private BindingRepository bindingRepository;
private boolean showAllLanguageValues;
private ServiceOperatorRepository serviceOperatorRepository;
private String serviceURL;
private SosHelper sosHelper;
private Locale defaultLocale;
private ContentCacheController contentCacheController;
private ProcedureDescriptionSettings procedureSettings;
Expand Down Expand Up @@ -133,19 +132,13 @@ public Locale getDefaultLocale() {
return defaultLocale;
}

@Setting(ServiceSettings.SERVICE_URL)
public void setServiceURL(final URI serviceURL)
throws ConfigurationError {
Validation.notNull("Service URL", serviceURL);
String url = serviceURL.toString();
if (url.contains("?")) {
url = url.split("[?]")[0];
}
this.serviceURL = url;
@Inject
public void setSosHelperL(SosHelper sosHelper) {
this.sosHelper = sosHelper;
}

public String getServiceURL() {
return serviceURL;
return sosHelper.getServiceURL();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,22 @@

import static java.util.stream.Collectors.toSet;

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

import javax.inject.Inject;

import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
import org.n52.faroe.annotation.Configurable;
import org.n52.faroe.annotation.Setting;
import org.n52.iceland.i18n.I18NDAORepository;
import org.n52.iceland.service.ServiceSettings;
import org.n52.series.db.beans.DataEntity;
import org.n52.series.db.beans.ereporting.EReportingSamplingPointEntity;
import org.n52.shetland.ogc.ows.exception.CodedException;
import org.n52.shetland.ogc.ows.exception.OwsExceptionReport;
import org.n52.shetland.util.EReportingSetting;
import org.n52.sos.service.SosSettings;
import org.n52.sos.ds.FeatureQueryHandler;
import org.n52.sos.request.operator.AbstractRequestOperator;
import org.n52.sos.ds.hibernate.dao.observation.AbstractObservationTimeDAO;
import org.n52.sos.ds.hibernate.dao.observation.ereporting.EReportingObservationDAO;
import org.n52.sos.ds.hibernate.dao.observation.ereporting.EReportingObservationTimeDAO;
Expand All @@ -68,7 +62,10 @@
import org.n52.sos.ds.hibernate.dao.observation.series.SeriesValueDAO;
import org.n52.sos.ds.hibernate.dao.observation.series.SeriesValueTimeDAO;
import org.n52.sos.ds.hibernate.util.HibernateHelper;
import org.n52.sos.request.operator.AbstractRequestOperator;
import org.n52.sos.service.SosSettings;
import org.n52.sos.util.GeometryHandler;
import org.n52.sos.util.SosHelper;
import org.n52.svalbard.decode.DecoderRepository;
import org.n52.svalbard.encode.EncoderRepository;
import org.n52.svalbard.util.SweHelper;
Expand All @@ -93,9 +90,9 @@ public class DaoFactory {
private GeometryHandler geometryHandler;
private SweHelper sweHelper;
private FeatureQueryHandler featureQueryHandler;
private String serviceURL;
private boolean includeChildObservableProperties;
private boolean staSupportsUrls;
private SosHelper sosHelper;

@Inject
public void setI18NDAORepository(I18NDAORepository i18NDAORepository) {
Expand Down Expand Up @@ -139,14 +136,9 @@ public void setSweHelper(SweHelper sweHelper) {
this.sweHelper = sweHelper;
}

@Setting(ServiceSettings.SERVICE_URL)
public void setServiceURL(final URI serviceURL) throws ConfigurationError {
Validation.notNull("Service URL", serviceURL);
String url = serviceURL.toString();
if (url.contains("?")) {
url = url.split("[?]")[0];
}
this.serviceURL = url;
@Inject
public void setSosHelper(SosHelper sosHelper) {
this.sosHelper = sosHelper;
}

public boolean isIncludeChildObservableProperties() {
Expand Down Expand Up @@ -304,12 +296,16 @@ public SweHelper getSweHelper() {
return sweHelper;
}

public SosHelper getSosHelper() {
return sosHelper;
}

public FeatureQueryHandler getFeatureQueryHandler() {
return featureQueryHandler;
}

public String getServiceURL() {
return serviceURL;
return getSosHelper().getServiceURL();
}

public XmlOptionsHelper getXmlOptionsHelper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,21 @@
*/
package org.n52.sos.ds.hibernate.util.observation;

import java.net.URI;
import java.util.Collections;
import java.util.Set;

import javax.inject.Inject;

import org.hibernate.Session;
import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
import org.n52.faroe.annotation.Configurable;
import org.n52.faroe.annotation.Setting;
import org.n52.iceland.binding.BindingRepository;
import org.n52.iceland.service.ServiceSettings;
import org.n52.janmayen.http.MediaTypes;
import org.n52.series.db.beans.DataEntity;
import org.n52.series.db.beans.DatasetEntity;
import org.n52.series.db.beans.RelatedDatasetEntity;
import org.n52.shetland.ogc.om.OmObservation;
import org.n52.shetland.ogc.ows.exception.CodedException;
import org.n52.sos.util.SosHelper;

@Configurable
public class InspireObservationCreator implements AdditionalObservationCreator {
Expand All @@ -58,17 +54,9 @@ public class InspireObservationCreator implements AdditionalObservationCreator {

@Inject
private BindingRepository bindingRepository;
private String serviceURL;
@Inject
private SosHelper sosHelper;

@Setting(ServiceSettings.SERVICE_URL)
public void setServiceURL(URI serviceURL) throws ConfigurationError {
Validation.notNull("Service URL", serviceURL);
String url = serviceURL.toString();
if (url.contains("?")) {
url = url.split("[?]")[0];
}
this.serviceURL = url;
}

@Override
public Set<AdditionalObservationCreatorKey> getKeys() {
Expand Down Expand Up @@ -102,7 +90,7 @@ public OmObservation add(OmObservation omObservation, DataEntity<?> observation,

private void addRelatedSeries(OmObservation omObservation, Set<RelatedDatasetEntity> relatedSeries)
throws CodedException {
new RelatedSeriesAdder(omObservation, relatedSeries, serviceURL.toString(),
new RelatedSeriesAdder(omObservation, relatedSeries, sosHelper.getServiceURL(),
bindingRepository.isActive(MediaTypes.APPLICATION_KVP)).add();
}
}
Loading

0 comments on commit 92e3b4e

Please sign in to comment.