This commit is contained in:
Francesco Mangiacrapa 2014-10-14 15:27:13 +00:00
parent ca453475b1
commit 4f20747f5e
3 changed files with 51 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import java.util.Set;
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException; import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException; import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader; import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
/** /**
@ -20,8 +21,8 @@ public class UriResolverManager {
private UriResolverMapReader uriResolverMapReader; private UriResolverMapReader uriResolverMapReader;
private Map<String, String> applicationTypes; private Map<String, String> applicationTypes;
private String userScope; private String scope;
private String userApplicationType; private String applicationType;
/** /**
* *
@ -43,13 +44,23 @@ public class UriResolverManager {
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes()); throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
} }
this.userApplicationType = applicationType; this.applicationType = applicationType;
this.userScope = scope; this.scope = scope;
} }
public String getLink(Map<String, String> parameters) throws IllegalArgumentException{ public String getLink(Map<String, String> parameters) throws IllegalArgumentException{
String resourceName = this.applicationTypes.get(applicationType);
try {
RuntimeResourceReader reader = new RuntimeResourceReader(scope, resourceName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ""; return "";
} }
@ -72,7 +83,8 @@ public class UriResolverManager {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
UriResolverManager resolver = new UriResolverManager("/gcube", "NA"); UriResolverManager resolver = new UriResolverManager("/gcube", "GIS");
resolver.getLink(null);
} catch (UriResolverMapException e) { } catch (UriResolverMapException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View File

@ -0,0 +1,8 @@
package org.gcube.portlets.user.uriresolvermanager.readers;
@SuppressWarnings("serial")
public class RuntimeResourceException extends Exception {
public RuntimeResourceException(String message) {
super(message);
}
}

View File

@ -29,27 +29,35 @@ import org.slf4j.LoggerFactory;
*/ */
public class RuntimeResourceReader { public class RuntimeResourceReader {
public static final String RESOURCE_NAME = "Gis-Resolver";
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class); public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
public List<ServiceProperty> serviceProperties; public List<ServiceProperty> serviceProperties;
private String resourceName; private String resourceName;
private String scope;
/**
* @throws Exception
*
*/
public RuntimeResourceReader(String scope, String resourceName) throws Exception {
this.scope = scope;
this.resourceName = resourceName;
readResource(scope, resourceName);
}
/** /**
* *
* @param scope * @param scope
* @return the application URI * @return the application URI
* @throws Exception * @throws Exception
*/ */
private String readResource(String scope, String resourceName) throws Exception private String readResource(String scope, String resourceName) throws Exception {
{
try{ try{
this.resourceName = resourceName; this.resourceName = resourceName;
String infraName = ScopeUtil.getInfrastructureNameFromScope(scope); String infraName = ScopeUtil.getInfrastructureNameFromScope(scope);
logger.info("Instancing root scope: "+infraName); logger.info("Instancing root scope: "+infraName);
@ -59,7 +67,7 @@ public class RuntimeResourceReader {
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'"); query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> r = client.submit(query); List<ServiceEndpoint> r = client.submit(query);
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName); if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName);
@ -71,7 +79,7 @@ public class RuntimeResourceReader {
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found"); if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
AccessPoint ap = accessPoints.iterator().next(); AccessPoint ap = accessPoints.iterator().next();
logger.info("returning GIS resolver URI root scope: "+ap.address());
Group<Property> properties = ap.properties(); Group<Property> properties = ap.properties();
@ -91,18 +99,18 @@ public class RuntimeResourceReader {
} }
} }
logger.info("returning URI: "+ap.address());
return ap.address(); return ap.address();
// parameters.setUser(ap.username()); //username // parameters.setUser(ap.username()); //username
// //
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password()); // String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
// //
// parameters.setPassword(decryptedPassword); //password // parameters.setPassword(decryptedPassword); //password
// Group<Property> properties = ap.properties(); // Group<Property> properties = ap.properties();
}catch (Exception e) { }catch (Exception e) {
logger.error("Sorry, an error occurred on reading the resource "+RESOURCE_NAME+ "Runtime Reosurces",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 "+RESOURCE_NAME+ "Runtime Reosurces"); throw new Exception("Sorry, an error occurred on reading the resource "+resourceName+ "Runtime Reosurces");
} }
} }
@ -127,9 +135,8 @@ public class RuntimeResourceReader {
} }
public static void main(String[] args) { public static void main(String[] args) {
RuntimeResourceReader resolver = new RuntimeResourceReader();
try { try {
resolver.readResource("/gcube", "Gis-Resolver"); RuntimeResourceReader resolver = new RuntimeResourceReader("/gcube", "Gis-Resolver");
System.out.println(resolver); System.out.println(resolver);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block