Just a bit of code optimization

This commit is contained in:
Francesco Mangiacrapa 2019-11-13 11:27:17 +01:00
parent 7214f2e188
commit f0fb363818
4 changed files with 22 additions and 16 deletions

View File

@ -24,6 +24,7 @@ public class ItemCatalogueURLs {
private String itemName;
private boolean isPublicItem;
private String privateVRECataloguePortletURL;
private String publicGatewayCataloguePortletURL;
private String publicVRECataloguePortletURL;
private String publicGatewayCataloguePortletURL;
}

View File

@ -50,8 +50,7 @@ public class CkanCatalogueConfigurationsReader {
public final static String APPLICATION_PROFILE_NAME = "CkanPortlet";
private static final String DATACATALOGUECONFIGURATION_PROPERTIES = "datacatalogueconfiguration.properties";
/**
* Load catalogue end points.
*
@ -64,23 +63,27 @@ public class CkanCatalogueConfigurationsReader {
DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl();
//String privatePortletURL = catalogueImpl.getPortletUrl();
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> accessLevelMap = catalogueImpl.getMapAccessURLToCatalogue();
links.setMapAccessURLToCatalogue(accessLevelMap);
String privatePortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE);
links.setPrivateVREPortletURL(privatePortletURL);
String publicVREPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
links.setPublicVREPortletURL(publicVREPortletURL);
//Building public URL from private portlet URL
String publicGatewayPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY);
links.setPublicGatewayPortletURL(publicGatewayPortletURL);
try{
URI toURL = new URI(privatePortletURL);
String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost();
//It returns the string "catalogue"
String prefixToPublicCtlg = getRelativeURLToCatalogue();
//Replacing for example "ckan-bb" with "catalogue-bb"
String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg);
links.setPublicGatewayPortletURL(publicURL+"/"+publicCatalogueName);
if(publicGatewayPortletURL==null || publicGatewayPortletURL.isEmpty()) {
//Building the gateway catalogue public URL from private VRE Portlet URL
URI toURL = new URI(privatePortletURL);
String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost();
//It returns the string "catalogue"
String prefixToPublicCtlg = getRelativeURLToCatalogue();
//Replacing for example "ckan-bb" with "catalogue-bb"
String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg);
links.setPublicGatewayPortletURL(publicURL+"/"+publicCatalogueName);
}
}catch(Exception e){
logger.warn("Erron on generating public catalogue URL from private URL: "+privatePortletURL, e);
}

View File

@ -12,6 +12,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
@ -27,6 +28,7 @@ import lombok.Setter;
@NoArgsConstructor
@Getter
@Setter
@ToString
public class GatewayCKANCatalogueReference implements Serializable{
/**
@ -43,5 +45,5 @@ public class GatewayCKANCatalogueReference implements Serializable{
private String ckanURL;
public Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue;
}

View File

@ -226,7 +226,7 @@ public class CatalogueResolver {
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicGatewayPortletURL(),entityContextValue, entityName);
String privateVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPrivateVREPortletURL(),entityContextValue, entityName);
String publicVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicVREPortletURL(),entityContextValue, entityName);
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicGatewayPorltetURL, publicVREPortletURL);
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL, publicGatewayPorltetURL);
}catch (Exception e) {
logger.error("Error when resolving CatalogueURL:", e);
throw e;