git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/uri-resolver-manager@100682 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ca453475b1
commit
4f20747f5e
|
@ -8,6 +8,7 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
||||
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
|
||||
|
||||
/**
|
||||
|
@ -20,8 +21,8 @@ public class UriResolverManager {
|
|||
|
||||
private UriResolverMapReader uriResolverMapReader;
|
||||
private Map<String, String> applicationTypes;
|
||||
private String userScope;
|
||||
private String userApplicationType;
|
||||
private String scope;
|
||||
private String applicationType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,13 +44,23 @@ public class UriResolverManager {
|
|||
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
|
||||
}
|
||||
|
||||
this.userApplicationType = applicationType;
|
||||
this.userScope = scope;
|
||||
this.applicationType = applicationType;
|
||||
this.scope = scope;
|
||||
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
@ -72,7 +83,8 @@ public class UriResolverManager {
|
|||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
UriResolverManager resolver = new UriResolverManager("/gcube", "NA");
|
||||
UriResolverManager resolver = new UriResolverManager("/gcube", "GIS");
|
||||
resolver.getLink(null);
|
||||
} catch (UriResolverMapException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.portlets.user.uriresolvermanager.readers;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class RuntimeResourceException extends Exception {
|
||||
public RuntimeResourceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -29,27 +29,35 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class RuntimeResourceReader {
|
||||
|
||||
public static final String RESOURCE_NAME = "Gis-Resolver";
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
|
||||
|
||||
public List<ServiceProperty> serviceProperties;
|
||||
|
||||
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
|
||||
* @return the application URI
|
||||
* @throws Exception
|
||||
*/
|
||||
private String readResource(String scope, String resourceName) 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);
|
||||
|
@ -59,7 +67,7 @@ public class RuntimeResourceReader {
|
|||
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
|
||||
|
||||
List<ServiceEndpoint> r = client.submit(query);
|
||||
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");
|
||||
|
||||
AccessPoint ap = accessPoints.iterator().next();
|
||||
logger.info("returning GIS resolver URI root scope: "+ap.address());
|
||||
|
||||
|
||||
Group<Property> properties = ap.properties();
|
||||
|
||||
|
@ -91,18 +99,18 @@ public class RuntimeResourceReader {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
logger.info("returning URI: "+ap.address());
|
||||
return ap.address();
|
||||
// parameters.setUser(ap.username()); //username
|
||||
//
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
//
|
||||
// parameters.setPassword(decryptedPassword); //password
|
||||
// Group<Property> properties = ap.properties();
|
||||
// parameters.setUser(ap.username()); //username
|
||||
//
|
||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
//
|
||||
// parameters.setPassword(decryptedPassword); //password
|
||||
// Group<Property> 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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,9 +135,8 @@ public class RuntimeResourceReader {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RuntimeResourceReader resolver = new RuntimeResourceReader();
|
||||
try {
|
||||
resolver.readResource("/gcube", "Gis-Resolver");
|
||||
RuntimeResourceReader resolver = new RuntimeResourceReader("/gcube", "Gis-Resolver");
|
||||
System.out.println(resolver);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
|
Loading…
Reference in New Issue