git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/uri-resolver-manager@100678 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
aced9c15c6
commit
6ea76582bc
|
@ -7,8 +7,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.type.ApplicationTypePropertyReader;
|
||||
import org.gcube.portlets.user.uriresolvermanager.type.PropertyFileNotFoundException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||
import org.gcube.portlets.user.uriresolvermanager.util.UriResolverMapReader;
|
||||
|
||||
/**
|
||||
|
@ -28,25 +27,25 @@ public class UriResolverManager {
|
|||
*
|
||||
* @param scope
|
||||
* @param applicationType a key Application Type
|
||||
* @throws IllegalArgumentException
|
||||
* @throws Exception
|
||||
*/
|
||||
public UriResolverManager(String scope, String applicationType) throws IllegalArgumentException{
|
||||
public UriResolverManager(String scope, String applicationType) throws UriResolverMapException, IllegalArgumentException{
|
||||
try {
|
||||
|
||||
this.applicationTypes = new ApplicationTypePropertyReader().getApplicationTypes();
|
||||
this.uriResolverMapReader = new UriResolverMapReader(scope);
|
||||
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
||||
|
||||
if(!this.uriResolverMapReader.getApplicationTypes().containsKey(applicationType)){
|
||||
throw new IllegalArgumentException("Application type: "+applicationType +" not found in "+getApplicationTypes());
|
||||
}
|
||||
|
||||
this.userApplicationType = applicationType;
|
||||
this.userScope = scope;
|
||||
|
||||
|
||||
} catch (PropertyFileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
||||
}
|
||||
|
||||
if(!this.applicationTypes.containsKey(applicationType)){
|
||||
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
|
||||
}
|
||||
|
||||
this.userApplicationType = applicationType;
|
||||
this.userScope = scope;
|
||||
|
||||
}
|
||||
|
||||
public String getLink(Map<String, String> parameters) throws IllegalArgumentException{
|
||||
|
@ -70,5 +69,18 @@ public class UriResolverManager {
|
|||
public Map<String, String> getCapabilities(){
|
||||
return this.applicationTypes;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
UriResolverManager resolver = new UriResolverManager("/gcube", "NA");
|
||||
} catch (UriResolverMapException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.uriresolvermanager.exception;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Oct 14, 2014
|
||||
*
|
||||
*/
|
||||
public class UriResolverMapException extends Exception {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -914311044943568036L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public UriResolverMapException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UriResolverMapException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
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<String, String> 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<String, String>(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<String, String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package org.gcube.portlets.user.uriresolvermanager.type;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PropertyFileNotFoundException extends Exception {
|
||||
public PropertyFileNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
# Property files
|
||||
#
|
||||
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
# created 10/2014
|
||||
#
|
||||
#
|
||||
|
||||
GIS = Gis-Resolver
|
||||
SMP = HTTP-URI-Resolver
|
Loading…
Reference in New Issue