Updated to support several Access Point for each Resolver
Introduced Entry Names in Uri-Resolver-Map Updated pom version at 1.1.0 git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/uri-resolver-manager@114649 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
81cbf16841
commit
841fd5c2a6
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/uri-resolver-manager-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/uri-resolver-manager-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -23,5 +23,5 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/uri-resolver-manager-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/uri-resolver-manager-1.1.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -10,7 +10,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>uri-resolver-manager</name>
|
||||
<description>The URI Resolver Manager</description>
|
||||
|
@ -117,16 +117,20 @@
|
|||
<version>20090211</version>
|
||||
</dependency>
|
||||
|
||||
<!-- LOGGER -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<!-- <version>1.2.16</version> -->
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<!-- <version>1.6.4</version> -->
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.util.Timer;
|
|||
import java.util.TimerTask;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||
|
@ -20,10 +22,13 @@ import org.gcube.portlets.user.urlshortener.UrlShortener;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 14, 2014
|
||||
* The Class UriResolverManager.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 4, 2015
|
||||
*/
|
||||
public class UriResolverManager {
|
||||
|
||||
|
@ -39,7 +44,7 @@ public class UriResolverManager {
|
|||
public static int RESET_TIME = RESET_DELAY; //10 MINUTES
|
||||
|
||||
private UriResolverMapReader uriResolverMapReader;
|
||||
private Map<String, String> applicationTypes;
|
||||
private Map<String, Resolver> applicationTypes;
|
||||
private String scope;
|
||||
private String applicationType;
|
||||
private RuntimeResourceReader reader;
|
||||
|
@ -48,29 +53,46 @@ public class UriResolverManager {
|
|||
* A lock to prevent reader = null;
|
||||
*/
|
||||
private int usingReader = 0;
|
||||
|
||||
private ServiceAccessPoint serviceAccessPoint;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
/**
|
||||
* Lock reader.
|
||||
*/
|
||||
public synchronized void lockReader() {
|
||||
usingReader++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release reader.
|
||||
*/
|
||||
public synchronized void releaseReader() {
|
||||
usingReader--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count readers.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public synchronized int countReaders() {
|
||||
return usingReader;
|
||||
}
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
||||
|
||||
|
||||
/**
|
||||
* Instance a UriResolverManager
|
||||
* Instantiates a new uri resolver manager.
|
||||
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
||||
* The scope is used to look up the generic resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the infrastructure to map ApplicationType with its Resolver
|
||||
* @param applicationType a key Application Type {@link UriResolverManager#getApplicationTypes()}
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws UriResolverMapException the uri resolver map exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
*/
|
||||
public UriResolverManager(String applicationType) throws UriResolverMapException, IllegalArgumentException{
|
||||
public UriResolverManager() throws UriResolverMapException, IllegalArgumentException{
|
||||
try {
|
||||
|
||||
this.scope = ScopeProvider.instance.get();
|
||||
|
@ -80,35 +102,66 @@ public class UriResolverManager {
|
|||
|
||||
this.uriResolverMapReader = new UriResolverMapReader(this.scope);
|
||||
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
||||
|
||||
this.setTimerUriResolverReader(RESET_DELAY, RESET_TIME);
|
||||
} catch (Exception e) {
|
||||
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance a UriResolverManager
|
||||
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
||||
* The scope is used to look up the generic resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the infrastructure to map ApplicationType with its Resolver
|
||||
*
|
||||
* @param applicationType a (valid) key Application Type {@link UriResolverManager#getApplicationTypes()}
|
||||
* @throws UriResolverMapException the uri resolver map exception
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
*/
|
||||
public UriResolverManager(String applicationType) throws UriResolverMapException, IllegalArgumentException{
|
||||
this();
|
||||
|
||||
if(!this.applicationTypes.containsKey(applicationType)){
|
||||
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
|
||||
}
|
||||
|
||||
this.applicationType = applicationType;
|
||||
this.reloadRuntimeResourceParameter(RESET_DELAY, RESET_TIME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the link.
|
||||
*
|
||||
* @param applicationType the application type
|
||||
* @param parameters the map of the parameters sent as HTTP query string
|
||||
* @param shortLink if true the link is shorted otherwise none
|
||||
* @return the link
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws UriResolverMapException the uri resolver map exception
|
||||
*/
|
||||
public String getLink(String applicationType, Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
||||
this.applicationType = applicationType;
|
||||
return getLink(parameters, shortLink);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parameters the map of the parameters sent with HTTP request (link) generated
|
||||
* Gets the link.
|
||||
*
|
||||
* @param parameters the map of the parameters sent as HTTP query string
|
||||
* @param shortLink if true the link is shorted otherwise none
|
||||
* @return
|
||||
* @throws IllegalArgumentException
|
||||
* @throws UriResolverMapException
|
||||
* @return the link
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws UriResolverMapException the uri resolver map exception
|
||||
*/
|
||||
public String getLink(Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
||||
|
||||
String resourceName = this.applicationTypes.get(applicationType);
|
||||
if(applicationType==null)
|
||||
throw new IllegalArgumentException("Application type is null");
|
||||
|
||||
Resolver resolver = this.applicationTypes.get(applicationType);
|
||||
String link;
|
||||
|
||||
if(parameters==null){
|
||||
if(parameters==null)
|
||||
throw new IllegalArgumentException("Input Map parameters is null");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
|
@ -117,10 +170,20 @@ public class UriResolverManager {
|
|||
if(reader==null){
|
||||
logger.info("Runtime Resource Reader is null, istancing...");
|
||||
ScopeProvider.instance.set(this.scope);
|
||||
reader = new RuntimeResourceReader(this.scope, resourceName);
|
||||
reader = new RuntimeResourceReader(this.scope, resolver.getResourceName());
|
||||
}
|
||||
|
||||
List<ServiceParameter> resourceParameters = reader.getServiceParameters();
|
||||
if(resolver.getEntryName()==null || resolver.getEntryName().isEmpty()){
|
||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||
}else{
|
||||
logger.warn("Reading Access Point for Entry Name: "+resolver.getEntryName());
|
||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||
if(serviceAccessPoint==null)
|
||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
||||
}
|
||||
|
||||
List<ServiceParameter> resourceParameters = serviceAccessPoint.getServiceParameters();
|
||||
|
||||
//CHECK PARAMETERS
|
||||
for (ServiceParameter serviceParameter : resourceParameters) {
|
||||
|
@ -131,7 +194,7 @@ public class UriResolverManager {
|
|||
}
|
||||
}
|
||||
|
||||
String baseURI = reader.getServiceBaseURI();
|
||||
String baseURI = serviceAccessPoint.getServiceUrl();
|
||||
|
||||
releaseReader();
|
||||
|
||||
|
@ -150,16 +213,18 @@ public class UriResolverManager {
|
|||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e){
|
||||
logger.error("Uri Resolver IllegalArgumentException: ", e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.error("Uri Resolver error: ", e);
|
||||
logger.error("Uri Resolver Exception: ", e);
|
||||
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the application types.
|
||||
*
|
||||
* @return the Application Types available
|
||||
*/
|
||||
public Set<String> getApplicationTypes(){
|
||||
|
@ -167,18 +232,72 @@ public class UriResolverManager {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a map Application Type - Resource Name
|
||||
* Discovery service parameters.
|
||||
*
|
||||
* @param resolver the resolver
|
||||
* @return the list
|
||||
* @throws IllegalArgumentException the illegal argument exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public Map<String, String> getCapabilities(){
|
||||
return this.applicationTypes;
|
||||
public List<ServiceParameter> discoveryServiceParameters(Resolver resolver) throws IllegalArgumentException, Exception{
|
||||
try {
|
||||
|
||||
if(this.scope == null)
|
||||
throw new IllegalArgumentException("Scope is null, set ScopeProvider");
|
||||
|
||||
if(resolver == null)
|
||||
throw new IllegalArgumentException("Resolver is null, set Resolver");
|
||||
|
||||
RuntimeResourceReader reader = new RuntimeResourceReader(this.scope, resolver.getResourceName());
|
||||
|
||||
ServiceAccessPoint serviceAccessPoint = null;
|
||||
if(resolver.getEntryName()==null || resolver.getEntryName().isEmpty()){
|
||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||
}else{
|
||||
logger.info("Reading Access Point for entryname: "+resolver.getEntryName());
|
||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||
if(serviceAccessPoint==null)
|
||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
||||
}
|
||||
|
||||
return serviceAccessPoint.getServiceParameters();
|
||||
} catch (Exception e) {
|
||||
logger.error("Uri Resolver error: ", e);
|
||||
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the resolver.
|
||||
*
|
||||
* @param applicationType the application type
|
||||
* @return the resolver
|
||||
*/
|
||||
public void reloadRuntimeResourceParameter(long delay, long period) {
|
||||
Timer timer = new Timer(true);
|
||||
public Resolver getResolver(String applicationType){
|
||||
return this.applicationTypes.get(applicationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the capabilities.
|
||||
*
|
||||
* @return a map Application Type - Resolver
|
||||
*/
|
||||
public Map<String, Resolver> getCapabilities(){
|
||||
return this.applicationTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timer uri resolver reader.
|
||||
*
|
||||
* @param delay the delay
|
||||
* @param period the period
|
||||
*/
|
||||
public void setTimerUriResolverReader(long delay, long period) {
|
||||
|
||||
cancelTimerUriResolverReader();
|
||||
|
||||
timer = new Timer(true);
|
||||
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
|
@ -194,5 +313,33 @@ public class UriResolverManager {
|
|||
}
|
||||
}, delay, period);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Cancel timer uri resolver reader.
|
||||
*/
|
||||
public void cancelTimerUriResolverReader(){
|
||||
if(timer!=null)
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invalid uri resolver reader.
|
||||
*/
|
||||
public void invalidUriResolverReader(){
|
||||
reader = null;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// String scope ="/gcube";
|
||||
// UriResolverMapReader resolver = new UriResolverMapReader(scope);
|
||||
// System.out.println(resolver);
|
||||
// } catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 29, 2015
|
||||
*/
|
||||
public class ApplicationType {
|
||||
|
||||
String resourceName;
|
||||
ServiceAccessPoint accessPoint;
|
||||
|
||||
/**
|
||||
* @param resourceName
|
||||
* @param accessPoint
|
||||
*/
|
||||
public ApplicationType(String resourceName, ServiceAccessPoint accessPoint) {
|
||||
this.resourceName = resourceName;
|
||||
this.accessPoint = accessPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resourceName
|
||||
*/
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accessPoint
|
||||
*/
|
||||
public ServiceAccessPoint getAccessPoint() {
|
||||
return accessPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resourceName the resourceName to set
|
||||
*/
|
||||
public void setResourceName(String resourceName) {
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param accessPoint the accessPoint to set
|
||||
*/
|
||||
public void setAccessPoint(ServiceAccessPoint accessPoint) {
|
||||
this.accessPoint = accessPoint;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ApplicationType [resourceName=");
|
||||
builder.append(resourceName);
|
||||
builder.append(", accessPoint=");
|
||||
builder.append(accessPoint);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||
|
||||
|
||||
/**
|
||||
* The Class Resolver.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 4, 2015
|
||||
*/
|
||||
public class Resolver {
|
||||
|
||||
private String resourceName;
|
||||
private String entryName;
|
||||
|
||||
/**
|
||||
* Instantiates a new resolver.
|
||||
*
|
||||
* @param resourceName the resource name
|
||||
* @param entryName the entry name
|
||||
*/
|
||||
public Resolver(String resourceName, String entryName) {
|
||||
super();
|
||||
this.resourceName = resourceName;
|
||||
this.entryName = entryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resource name.
|
||||
*
|
||||
* @return the resourceName
|
||||
*/
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entry name.
|
||||
*
|
||||
* @return the entryName
|
||||
*/
|
||||
public String getEntryName() {
|
||||
return entryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resource name.
|
||||
*
|
||||
* @param resourceName the resourceName to set
|
||||
*/
|
||||
public void setResourceName(String resourceName) {
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry name.
|
||||
*
|
||||
* @param entryName the entryName to set
|
||||
*/
|
||||
public void setEntryName(String entryName) {
|
||||
this.entryName = entryName;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Resolver [resourceName=");
|
||||
builder.append(resourceName);
|
||||
builder.append(", entryName=");
|
||||
builder.append(entryName);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 29, 2015
|
||||
*/
|
||||
public class ServiceAccessPoint {
|
||||
|
||||
private String serviceUrl;
|
||||
private String entryName;
|
||||
private List<ServiceParameter> serviceParameters;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ServiceAccessPoint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entryName
|
||||
* @param serviceUrl
|
||||
* @param serviceParameters
|
||||
*/
|
||||
public ServiceAccessPoint(String entryName, String serviceUrl,
|
||||
List<ServiceParameter> serviceParameters) {
|
||||
super();
|
||||
this.entryName = entryName;
|
||||
this.serviceUrl = serviceUrl;
|
||||
this.serviceParameters = serviceParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entryName
|
||||
*/
|
||||
public String getEntryName() {
|
||||
return entryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serviceUrl
|
||||
*/
|
||||
public String getServiceUrl() {
|
||||
return serviceUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serviceParameters
|
||||
*/
|
||||
public List<ServiceParameter> getServiceParameters() {
|
||||
return serviceParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entryName the entryName to set
|
||||
*/
|
||||
public void setEntryName(String entryName) {
|
||||
this.entryName = entryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param serviceUrl the serviceUrl to set
|
||||
*/
|
||||
public void setServiceUrl(String serviceUrl) {
|
||||
this.serviceUrl = serviceUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param serviceParameters the serviceParameters to set
|
||||
*/
|
||||
public void setServiceParameters(List<ServiceParameter> serviceParameters) {
|
||||
this.serviceParameters = serviceParameters;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("AccessPoint [entryName=");
|
||||
builder.append(entryName);
|
||||
builder.append(", serviceUrl=");
|
||||
builder.append(serviceUrl);
|
||||
builder.append(", serviceParameters=");
|
||||
builder.append(serviceParameters);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||
import org.gcube.portlets.user.uriresolvermanager.util.ScopeUtil;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -22,39 +23,47 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 7, 2014
|
||||
* The Class RuntimeResourceReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 30, 2015
|
||||
*/
|
||||
public class RuntimeResourceReader {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
|
||||
|
||||
public List<ServiceParameter> serviceParameters;
|
||||
public List<ServiceAccessPoint> serviceAccessPoints;
|
||||
|
||||
private String resourceName;
|
||||
|
||||
private String scope;
|
||||
|
||||
private String serviceBaseURI;
|
||||
private String entryName;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*
|
||||
* Instantiates a new runtime resource reader.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceName the resource name
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public RuntimeResourceReader(String scope, String resourceName) throws Exception {
|
||||
this.scope = scope;
|
||||
this.resourceName = resourceName;
|
||||
readResource(scope, resourceName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param scope
|
||||
* Read resource.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceName the resource name
|
||||
* @return the application URI
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected String readResource(String scope, String resourceName) throws Exception {
|
||||
private void readResource(String scope, String resourceName) throws Exception {
|
||||
|
||||
try{
|
||||
logger.info("Tentative read resource: "+resourceName+", scope: "+scope);
|
||||
|
@ -82,30 +91,33 @@ public class RuntimeResourceReader {
|
|||
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
||||
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
||||
|
||||
AccessPoint ap = accessPoints.iterator().next();
|
||||
Iterator<AccessPoint> acIt = accessPoints.iterator();
|
||||
serviceAccessPoints = new ArrayList<ServiceAccessPoint>(accessPoints.size());
|
||||
|
||||
|
||||
Group<Property> properties = ap.properties();
|
||||
|
||||
if(properties.size()==0){
|
||||
logger.warn("Properties in resource "+resourceName+" not found");
|
||||
}else{
|
||||
|
||||
serviceParameters = new ArrayList<ServiceParameter>(properties.size());
|
||||
while(acIt.hasNext()){
|
||||
|
||||
Iterator<Property> iter = properties.iterator();
|
||||
AccessPoint ap = acIt.next();
|
||||
|
||||
Group<Property> properties = ap.properties();
|
||||
|
||||
if(properties.size()==0){
|
||||
logger.warn("Properties in resource "+resourceName+" not found");
|
||||
}else{
|
||||
|
||||
while (iter.hasNext()) {
|
||||
List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size());
|
||||
|
||||
Property prop = iter.next();
|
||||
Iterator<Property> iter = properties.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
Property prop = iter.next();
|
||||
|
||||
serviceParameters.add(new ServiceParameter(prop.value(), true));
|
||||
}
|
||||
|
||||
serviceParameters.add(new ServiceParameter(prop.value(), true));
|
||||
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), serviceParameters));
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("returning URI: "+ap.address());
|
||||
this.serviceBaseURI = ap.address();
|
||||
return serviceBaseURI;
|
||||
// parameters.setUser(ap.username()); //username
|
||||
//
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
|
@ -114,46 +126,67 @@ public class RuntimeResourceReader {
|
|||
// Group<Property> properties = ap.properties();
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("Sorry, an error occurred on reading the resource "+resourceName+ "Runtime Reosurces",e);
|
||||
throw new Exception("Sorry, an error occurred on reading the resource "+resourceName+ "Runtime Reosurces");
|
||||
logger.error("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Reosurce",e);
|
||||
throw new Exception("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Reosurce");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param entryName
|
||||
* @return
|
||||
*/
|
||||
public ServiceAccessPoint getServiceAccessPointForEntryName(String entryName){
|
||||
|
||||
for (ServiceAccessPoint serviceAccessPoint : serviceAccessPoints) {
|
||||
if(serviceAccessPoint.getEntryName().equals(entryName))
|
||||
return serviceAccessPoint;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resource name.
|
||||
*
|
||||
* @return the resource name
|
||||
*/
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
public List<ServiceParameter> getServiceParameters() {
|
||||
return serviceParameters;
|
||||
/**
|
||||
* Gets the entry name.
|
||||
*
|
||||
* @return the entryName
|
||||
*/
|
||||
public String getEntryName() {
|
||||
return entryName;
|
||||
}
|
||||
|
||||
public String getServiceBaseURI() {
|
||||
return serviceBaseURI;
|
||||
/**
|
||||
* @return the scope
|
||||
*/
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("RuntimeResourceReader [serviceParameters=");
|
||||
builder.append(serviceParameters);
|
||||
builder.append(", resourceName=");
|
||||
builder.append(resourceName);
|
||||
builder.append(", scope=");
|
||||
builder.append(scope);
|
||||
builder.append(", serviceBaseURI=");
|
||||
builder.append(serviceBaseURI);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
|
||||
/**
|
||||
* @return the serviceAccessPoints
|
||||
*/
|
||||
public List<ServiceAccessPoint> getServiceAccessPoints() {
|
||||
return serviceAccessPoints;
|
||||
}
|
||||
|
||||
/*public static void main(String[] args) {
|
||||
try {
|
||||
RuntimeResourceReader resolver = new RuntimeResourceReader("/gcube", "Gis-Resolver");
|
||||
System.out.println(resolver);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// RuntimeResourceReader rr = new RuntimeResourceReader("/gcube", "Gis-Resolver");
|
||||
// System.out.println(rr);
|
||||
//
|
||||
// System.out.println(rr.getServiceAccessPointForEntryName("gis"));
|
||||
// } catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||
import org.gcube.portlets.user.uriresolvermanager.util.ScopeUtil;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
|
@ -21,33 +22,33 @@ import org.slf4j.LoggerFactory;
|
|||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 13, 2014
|
||||
* The Class UriResolverMapReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 4, 2015
|
||||
*/
|
||||
public class UriResolverMapReader {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final String URIRESOLVERMAP = "UriResolverMap";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final String URI_RESOLVER_MAP = "Uri-Resolver-Map";
|
||||
public static final String URIRESOLVERMAP_SECONDARY_TYPE = "UriResolverMap";
|
||||
public static final String URI_RESOLVER_MAP_RESOURCE_NAME = "Uri-Resolver-Map";
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
||||
private String secondaryType;
|
||||
private String scope;
|
||||
private String resourceName;
|
||||
|
||||
private Map<String, String> applicationTypes; //A map ApplicationType - Resource Name
|
||||
private Map<String, Resolver> applicationTypes; //A map ApplicationType - Resolver
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new uri resolver map reader.
|
||||
*
|
||||
* @param scope - the scope to be searched
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public UriResolverMapReader(String scope) throws Exception {
|
||||
this.scope = scope;
|
||||
|
@ -56,18 +57,18 @@ public class UriResolverMapReader {
|
|||
throw new Exception("Scope is null, set scope provider!");
|
||||
}
|
||||
|
||||
this.resourceName = URI_RESOLVER_MAP;
|
||||
this.secondaryType = URIRESOLVERMAP;
|
||||
this.resourceName = URI_RESOLVER_MAP_RESOURCE_NAME;
|
||||
this.secondaryType = URIRESOLVERMAP_SECONDARY_TYPE;
|
||||
readProfileFromInfrastrucure();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this method looks up the generic resource among the ones available in the infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
||||
* resource name {@value #URI_RESOLVER_MAP} and secondaryType {@value #URIRESOLVERMAP}
|
||||
* @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile
|
||||
* resource name {@value #URI_RESOLVER_MAP_RESOURCE_NAME} and secondaryType {@value #URIRESOLVERMAP_SECONDARY_TYPE}
|
||||
*
|
||||
* @return the applicationProfile profile
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private void readProfileFromInfrastrucure() throws Exception {
|
||||
|
||||
|
@ -98,17 +99,18 @@ public class UriResolverMapReader {
|
|||
currValue = helper.evaluate("/Resource/Profile/Body/access_point/application_type/text()");
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
logger.info("Application Types are: "+currValue.size());
|
||||
applicationTypes = new HashMap<String, String>(currValue.size());
|
||||
applicationTypes = new HashMap<String, Resolver>(currValue.size());
|
||||
// List<String> appTypes = currValue;
|
||||
//FOR EACH APPLICATION TYPE
|
||||
for (String at : currValue) {
|
||||
logger.info("Application Type "+at);
|
||||
// currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
||||
List<String> resources = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/resource/text()");
|
||||
|
||||
List<String> entryNames = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/entryname/text()");
|
||||
if(resources!=null && resources.size()>0){
|
||||
applicationTypes.put(at, resources.get(0));
|
||||
logger.info("Stored: "+at +" -> Resource: "+ resources.get(0));
|
||||
Resolver resolver = new Resolver(resources.get(0), entryNames.get(0));
|
||||
applicationTypes.put(at, resolver);
|
||||
logger.info("Stored: "+at +" -> Resolver: "+ resolver);
|
||||
}else
|
||||
logger.warn("Skipping Type "+at+" mapping to runtime resource not found!");
|
||||
}
|
||||
|
@ -122,6 +124,13 @@ public class UriResolverMapReader {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @param name the name
|
||||
* @return the gcube generic query string
|
||||
*/
|
||||
public static String getGcubeGenericQueryString(String secondaryType, String name){
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
|
@ -131,26 +140,46 @@ public class UriResolverMapReader {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the application types.
|
||||
*
|
||||
* @return the applicationTypes
|
||||
*/
|
||||
public Map<String, Resolver> getApplicationTypes() {
|
||||
return applicationTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secondary type.
|
||||
*
|
||||
* @return the secondary type
|
||||
*/
|
||||
public String getSecondaryType() {
|
||||
return secondaryType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the scope.
|
||||
*
|
||||
* @return the scope
|
||||
*/
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public Map<String, String> getApplicationTypes() {
|
||||
return applicationTypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the resource name.
|
||||
*
|
||||
* @return the resource name
|
||||
*/
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -166,14 +195,20 @@ public class UriResolverMapReader {
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
/*public static void main(String[] args) {
|
||||
|
||||
String scope ="/gcube";
|
||||
try {
|
||||
UriResolverMapReader resolver = new UriResolverMapReader(scope);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
// /**
|
||||
// * The main method.
|
||||
// *
|
||||
// * @param args the arguments
|
||||
// */
|
||||
// public static void main(String[] args) {
|
||||
// String scope ="/gcube";
|
||||
// try {
|
||||
// UriResolverMapReader resolver = new UriResolverMapReader(scope);
|
||||
// System.out.println(resolver);
|
||||
// } catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 20, 2014
|
||||
*
|
||||
*/
|
||||
public class UriResolverManagerMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
||||
System.out.println(resolver.getCapabilities());
|
||||
System.out.println(resolver.getApplicationTypes());
|
||||
// System.out.println(resolver.discoveryServiceParameters(resolver.getResolver("SMP-ID")));
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
||||
params.put("scope", "/gcube/devsec/devVRE");
|
||||
String shortLink = resolver.getLink(params, true);
|
||||
System.out.println(shortLink); //true, link is shorted otherwise none
|
||||
} catch (UriResolverMapException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ public class UriResolverManagerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void testSMP() {
|
||||
|
||||
try {
|
||||
|
@ -59,6 +59,32 @@ public class UriResolverManagerTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Thread safe
|
||||
*/
|
||||
// @Test
|
||||
public void testSMPID(){
|
||||
|
||||
try {
|
||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||
UriResolverManager resolver;
|
||||
resolver = new UriResolverManager("SMP-ID");
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("smp-id","553f9265e4b0567b75021fce");
|
||||
params.put("fileName", "dog");
|
||||
params.put("contentType", "image/jpg");
|
||||
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none
|
||||
System.out.println(shortLink);
|
||||
} catch (UriResolverMapException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread safe
|
||||
*/
|
||||
|
@ -109,5 +135,7 @@ public class UriResolverManagerTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="${groupId}.${artifactId}.1-1-0" date="2015-05-04">
|
||||
<Change>Updated to support several Access Point for each Resolver</Change>
|
||||
<Change>Introduced Entry Names in Uri-Resolver-Map</Change>
|
||||
</Changeset>
|
||||
<Changeset component="${groupId}.${artifactId}.1-0-0" date="2014-10-13">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
|
|
Loading…
Reference in New Issue