diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..28b5b6c
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..d2e5a4f
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ uri-resolver-manager
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..e9441bb
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..abec6ca
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..feb696b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,244 @@
+
+ 4.0.0
+
+ org.gcube.portlets.user
+ uri-resolver-manager
+ 1.0.0-SNAPSHOT
+ jar
+
+ uri-resolver-manager
+
+
+ The URI Resolver Manager
+
+ https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}
+
+
+
+
+ Francesco Mangiacrapa
+ francesco.mangiacrapa@isti.cnr.it
+ CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"
+
+ architect
+ developer
+
+
+
+
+
+
+
+
+ org.gcube.distribution
+ maven-bom
+ LATEST
+ pom
+ import
+
+
+
+
+
+
+ ${project.basedir}/distro
+ ${project.build.directory}/${project.build.finalName}
+ 2014-05-16
+ templates
+ distro
+ config
+
+
+ 2.5.1
+
+ ${env.GLOBUS_LOCATION}
+
+ UTF-8
+ UTF-8
+
+
+
+
+
+
+
+ org.gcube.resources.discovery
+ ic-client
+
+ provided
+
+
+
+
+ commons-httpclient
+ commons-httpclient
+ 3.1
+
+
+
+ org.gcube.core
+ common-encryption
+ [1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)
+ provided
+
+
+
+ javax.validation
+ validation-api
+ 1.0.0.GA
+ test
+
+
+ javax.validation
+ validation-api
+ 1.0.0.GA
+ sources
+ test
+
+
+
+
+ org.json
+ json
+ 20090211
+
+
+
+ log4j
+ log4j
+
+ compile
+
+
+ org.slf4j
+ slf4j-log4j12
+
+ compile
+
+
+
+
+ junit
+ junit
+ 4.8.1
+ test
+
+
+
+
+
+
+ ${webappDirectory}/WEB-INF/classes
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.16
+
+ true
+
+
+
+
+ org.apache.maven.surefire
+ surefire-junit47
+ 2.16
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-profile
+ process-resources
+
+ copy-resources
+
+
+ ${configDirectory}
+
+
+ ${templatesDirectory}
+
+ profile.xml
+
+ true
+
+
+
+
+
+ copy-distro-resources
+ process-resources
+
+ copy-resources
+
+
+ ${distroDirectory}
+
+
+ ${templatesDirectory}
+
+ profile.xml
+ descriptor.xml
+
+ true
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 2.5
+
+
+
+ ${distroDirectory}
+
+ **
+
+ false
+
+
+ ${configDirectory}
+
+ **
+
+ false
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.2
+
+
+ ${templatesDirectory}/descriptor.xml
+
+
+
+
+ servicearchive
+ package
+
+ single
+
+
+
+
+
+
+
+
diff --git a/src/it/settings.xml b/src/it/settings.xml
new file mode 100644
index 0000000..c8f77f0
--- /dev/null
+++ b/src/it/settings.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ it-repo
+
+ true
+
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+
diff --git a/src/it/simple-it/pom.xml b/src/it/simple-it/pom.xml
new file mode 100644
index 0000000..bc33cd2
--- /dev/null
+++ b/src/it/simple-it/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+
+ org.gcube.portlets.user.it
+ simple-it
+ 1.0-SNAPSHOT
+
+ A simple IT verifying the basic use case.
+
+
+ UTF-8
+
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+ touch
+ validate
+
+ touch
+
+
+
+
+
+
+
diff --git a/src/it/simple-it/verify.groovy b/src/it/simple-it/verify.groovy
new file mode 100644
index 0000000..7b307c7
--- /dev/null
+++ b/src/it/simple-it/verify.groovy
@@ -0,0 +1,3 @@
+File touchFile = new File( basedir, "target/touch.txt" );
+
+assert touchFile.isFile()
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolveManager.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolveManager.java
new file mode 100644
index 0000000..ce52f9a
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolveManager.java
@@ -0,0 +1,64 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.uriresolvermanager;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.gcube.portlets.user.uriresolvermanager.type.ApplicationTypePropertyReader;
+import org.gcube.portlets.user.uriresolvermanager.type.PropertyFileNotFoundException;
+
+/**
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * @Oct 14, 2014
+ *
+ */
+public class UriResolveManager {
+
+
+ private ApplicationTypePropertyReader applicationTypeReader;
+ private String userApplicationType;
+
+ private Map applicationTypes;
+
+ /**
+ *
+ * @param scope
+ * @param applicationType a key Application Type
+ */
+ public UriResolveManager(String scope, String applicationType){
+ try {
+
+ this.applicationTypes = new ApplicationTypePropertyReader().getApplicationTypes();
+
+ this.userApplicationType = applicationType;
+
+ if(!this.applicationTypeReader.getApplicationTypes().containsKey(applicationType)){
+
+ }
+
+
+ } catch (PropertyFileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @return the Application Types availables
+ */
+ public Set getApplicationTypes(){
+ return this.applicationTypes.keySet();
+ }
+
+ /**
+ *
+ * @return a map Application Type - Resource Name
+ */
+ public Map getCapabilities(){
+ return this.applicationTypes;
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/ServiceProperty.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/ServiceProperty.java
new file mode 100644
index 0000000..ca921d6
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/entity/ServiceProperty.java
@@ -0,0 +1,62 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.uriresolvermanager.entity;
+
+/**
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * @Oct 14, 2014
+ *
+ */
+public class ServiceProperty {
+
+ private String key;
+ private String defaultValue;
+ private boolean isMandatory;
+
+
+ /**
+ * @param key
+ * @param defaultValue
+ * @param isMandatory
+ */
+ public ServiceProperty(String key, boolean isMandatory) {
+ super();
+ this.key = key;
+ this.isMandatory = isMandatory;
+ }
+
+
+ public String getKey() {
+ return key;
+ }
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+ public boolean isMandatory() {
+ return isMandatory;
+ }
+ public void setKey(String key) {
+ this.key = key;
+ }
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+ public void setMandatory(boolean isMandatory) {
+ this.isMandatory = isMandatory;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("ServiceProperty [key=");
+ builder.append(key);
+ builder.append(", defaultValue=");
+ builder.append(defaultValue);
+ builder.append(", isMandatory=");
+ builder.append(isMandatory);
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/exception/IllegalArgumentException.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/exception/IllegalArgumentException.java
new file mode 100644
index 0000000..21a748e
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/exception/IllegalArgumentException.java
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.uriresolvermanager.exception;
+
+/**
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * @Oct 14, 2014
+ *
+ */
+public class IllegalArgumentException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 769797235962949500L;
+
+ /**
+ *
+ */
+ public IllegalArgumentException() {
+ super();
+ }
+
+ public IllegalArgumentException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/ApplicationTypePropertyReader.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/ApplicationTypePropertyReader.java
new file mode 100644
index 0000000..d9ee910
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/ApplicationTypePropertyReader.java
@@ -0,0 +1,67 @@
+package org.gcube.portlets.user.uriresolvermanager.type;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+public class ApplicationTypePropertyReader {
+
+ protected static final String RESOURCE_FILE_PROPERTIES = "applicationtyperesources.properties";
+
+ private Map applicationTypes; //A map ApplicationType - Resource Name
+
+ private Logger logger = Logger.getLogger(ApplicationTypePropertyReader.class);
+
+ public ApplicationTypePropertyReader() throws PropertyFileNotFoundException {
+
+ Properties prop = new Properties();
+
+ try {
+
+ InputStream in = (InputStream) ApplicationTypePropertyReader.class.getResourceAsStream(RESOURCE_FILE_PROPERTIES);
+
+ // load a properties file
+ prop.load(in);
+
+ applicationTypes = new HashMap(prop.keySet().size());
+
+ for (Object key : prop.keySet()) {
+ String resource = (String) prop.get(key);
+ applicationTypes.put((String)key, resource);
+ }
+
+ } catch (IOException e) {
+ logger.error("An error occurred on read property file "+e, e);
+ throw new PropertyFileNotFoundException("An error occurred on read property file "+e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("ApplicationTypePropertyReader [applicationTypes=");
+ builder.append(applicationTypes);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ public Map getApplicationTypes() {
+ return applicationTypes;
+ }
+
+ public static void main(String[] args) {
+ try {
+ ApplicationTypePropertyReader reader = new ApplicationTypePropertyReader();
+ System.out.println(reader);
+ } catch (PropertyFileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/PropertyFileNotFoundException.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/PropertyFileNotFoundException.java
new file mode 100644
index 0000000..0263036
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/PropertyFileNotFoundException.java
@@ -0,0 +1,8 @@
+package org.gcube.portlets.user.uriresolvermanager.type;
+
+@SuppressWarnings("serial")
+public class PropertyFileNotFoundException extends Exception {
+ public PropertyFileNotFoundException(String message) {
+ super(message);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/applicationtyperesources.properties b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/applicationtyperesources.properties
new file mode 100644
index 0000000..a22203e
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/type/applicationtyperesources.properties
@@ -0,0 +1,9 @@
+# Property files
+#
+# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+# created 10/2014
+#
+#
+
+GIS = Gis-Resolver
+SMP = HTTP-URI-Resolver
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/RuntimeResourceReader.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/RuntimeResourceReader.java
new file mode 100644
index 0000000..dd283fd
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/RuntimeResourceReader.java
@@ -0,0 +1,140 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.uriresolvermanager.util;
+
+import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
+import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.gcube.common.resources.gcore.ServiceEndpoint;
+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.ServiceProperty;
+import org.gcube.resources.discovery.client.api.DiscoveryClient;
+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
+ *
+ */
+public class RuntimeResourceReader {
+
+ public static final String RESOURCE_NAME = "Gis-Resolver";
+
+ public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
+
+ public List serviceProperties;
+
+ private String resourceName;
+
+
+ /**
+ *
+ * @param scope
+ * @return the application URI
+ * @throws Exception
+ */
+ private String readResource(String scope, String resourceName) throws Exception
+ {
+ try{
+
+ this.resourceName = resourceName;
+
+ String infraName = ScopeUtil.getInfrastructureNameFromScope(scope);
+
+ logger.info("Instancing root scope: "+infraName);
+ ScopeProvider.instance.set(infraName);
+
+ SimpleQuery query = queryFor(ServiceEndpoint.class);
+ query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
+
+ DiscoveryClient client = clientFor(ServiceEndpoint.class);
+
+ List r = client.submit(query);
+ if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName);
+
+ ServiceEndpoint se = r.get(0);
+ if(se.profile()==null)
+ throw new Exception("IS profile is null for resource: "+resourceName);
+
+ Group accessPoints = se.profile().accessPoints();
+ if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
+
+ AccessPoint ap = accessPoints.iterator().next();
+ logger.info("returning GIS resolver URI root scope: "+ap.address());
+
+ Group properties = ap.properties();
+
+ if(properties.size()==0){
+ logger.warn("Properties in resource "+resourceName+" not found");
+ }else{
+
+ serviceProperties = new ArrayList(properties.size());
+
+ Iterator iter = properties.iterator();
+
+ while (iter.hasNext()) {
+
+ Property prop = iter.next();
+
+ serviceProperties.add(new ServiceProperty(prop.value(), true));
+ }
+ }
+
+
+ return ap.address();
+// parameters.setUser(ap.username()); //username
+//
+// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
+//
+// parameters.setPassword(decryptedPassword); //password
+// Group properties = ap.properties();
+
+ }catch (Exception e) {
+ logger.error("Sorry, an error occurred on reading the resource "+RESOURCE_NAME+ "Runtime Reosurces",e);
+ throw new Exception("Sorry, an error occurred on reading the resource "+RESOURCE_NAME+ "Runtime Reosurces");
+ }
+ }
+
+ public List getServiceProperties() {
+ return serviceProperties;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("RuntimeResourceReader [serviceProperties=");
+ builder.append(serviceProperties);
+ builder.append(", resourceName=");
+ builder.append(resourceName);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ public static void main(String[] args) {
+ RuntimeResourceReader resolver = new RuntimeResourceReader();
+ try {
+ resolver.readResource("/gcube", "Gis-Resolver");
+ System.out.println(resolver);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/ScopeUtil.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/ScopeUtil.java
new file mode 100644
index 0000000..dde24e2
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/ScopeUtil.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.uriresolvermanager.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * @Oct 13, 2014
+ *
+ */
+public class ScopeUtil {
+
+ private static final String SCOPE_SEPARATOR = "/";
+ public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
+
+
+ public static String getInfrastructureNameFromScope(String scope) throws Exception{
+
+ if(scope==null || scope.isEmpty()){
+ throw new Exception("Scope is null or empty");
+ }
+
+ if(!scope.startsWith(SCOPE_SEPARATOR)){
+ logger.warn("Input scope: "+scope+" not have / is a really scope?");
+ scope = SCOPE_SEPARATOR+scope;
+ logger.warn("Tentative as scope: "+scope);
+ }
+
+ String[] splitScope = scope.split(SCOPE_SEPARATOR);
+
+ String rootScope = SCOPE_SEPARATOR + splitScope[1];
+
+ if(rootScope.length()<2){
+ throw new Exception("Infrastructure name not found in "+scope);
+ }
+
+ return rootScope;
+
+ }
+}