diff --git a/pom.xml b/pom.xml
index ed40363..1034cab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
4.0.0
org.gcube.portlets.user
uri-resolver-manager
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOT
jar
uri-resolver-manager
The URI Resolver Manager
@@ -30,19 +30,6 @@
-
-
-
-
- org.gcube.distribution
- maven-portal-bom
- LATEST
- pom
- import
-
-
-
-
${project.basedir}/distro
${project.build.directory}/${project.build.finalName}
@@ -68,7 +55,7 @@
org.gcube.resources.discovery
ic-client
-
+ [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)
provided
@@ -119,16 +106,19 @@
log4j
log4j
- compile
+ 1.2.16
+ provided
org.slf4j
slf4j-log4j12
+ 1.6.4
compile
org.slf4j
slf4j-api
+ 1.6.4
compile
diff --git a/src/it/settings.xml b/src/it/settings.xml
deleted file mode 100644
index c8f77f0..0000000
--- a/src/it/settings.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
-
-
-
-
- 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
deleted file mode 100644
index bc33cd2..0000000
--- a/src/it/simple-it/pom.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
- 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
deleted file mode 100644
index 7b307c7..0000000
--- a/src/it/simple-it/verify.groovy
+++ /dev/null
@@ -1,3 +0,0 @@
-File touchFile = new File( basedir, "target/touch.txt" );
-
-assert touchFile.isFile()
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
index 1a86e42..5f3d304 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/readers/UriResolverMapReader.java
@@ -30,13 +30,15 @@ import org.xml.sax.InputSource;
* May 4, 2015
*/
public class UriResolverMapReader {
-
+
/**
- *
+ *
*/
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);
+ //TODO TEMP SOLUTION IN ORDER TO PRINT USING ALSO LOG4J INTO GEOEXPLORER PORTLET
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
private String secondaryType;
private String scope;
@@ -50,16 +52,16 @@ public class UriResolverMapReader {
* @param scope - the scope to be searched
* @throws Exception the exception
*/
- public UriResolverMapReader(String scope) throws Exception {
+ public UriResolverMapReader(String scope) throws Exception {
this.scope = scope;
-
+
if(scope==null){
throw new Exception("Scope is null, set scope provider!");
}
-
+
this.resourceName = URI_RESOLVER_MAP_RESOURCE_NAME;
this.secondaryType = URIRESOLVERMAP_SECONDARY_TYPE;
- readProfileFromInfrastrucure();
+ readProfileFromInfrastrucure();
}
@@ -73,29 +75,38 @@ public class UriResolverMapReader {
private void readProfileFromInfrastrucure() throws Exception {
String queryString = getGcubeGenericQueryString(secondaryType, resourceName);
-
+
logger.info("Trying to fetch applicationProfile profile from the infrastructure for " + secondaryType + " scope: " + scope);
logger.info(queryString);
try {
-
+
+ logger.info("Getting Infrastructure Name...: ");
String infra = ScopeUtil.getInfrastructureNameFromScope(this.scope);
-
+ logger.info("Infrastructure Name returned: "+infra);
+
ScopeProvider.instance.set(infra);
logger.info("scope provider set instance: "+infra);
Query q = new QueryBox(queryString);
-
- DiscoveryClient client = client();
- List appUriResolverMap = client.submit(q);
+ logger.info("new query box works");
- if (appUriResolverMap == null || appUriResolverMap.size() == 0)
+ DiscoveryClient client = client();
+ logger.info("submitting query is: "+queryString);
+ List appUriResolverMap = client.submit(q);
+ logger.info("submit query works");
+
+ if (appUriResolverMap == null || appUriResolverMap.size() == 0){
+ logger.error("Your applicationProfile with secondaryType: "+secondaryType+" and name "+resourceName+" is not registered in the infrastructure, scope: "+ScopeProvider.instance.get());
throw new ApplicationProfileException("Your applicationProfile with secondaryType: "+secondaryType+" and name "+resourceName+" is not registered in the infrastructure");
- else {
+ }else {
+ logger.info("Building new DocumentBuilder..");
String elem = appUriResolverMap.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
+ logger.info("Building new XPathHelper..");
XPathHelper helper = new XPathHelper(node);
List currValue = null;
+ logger.info("Evaluating XPath..");
currValue = helper.evaluate("/Resource/Profile/Body/access_point/application_type/text()");
if (currValue != null && currValue.size() > 0) {
logger.info("Application Types are: "+currValue.size());
@@ -120,10 +131,13 @@ public class UriResolverMapReader {
} catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure", e);
throw new ApplicationProfileException("Error while trying to fetch applicationProfile with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure");
+ }finally{
+
+ ScopeProvider.instance.reset();
}
}
-
+
/**
* Gets the gcube generic query string.
*
@@ -132,14 +146,14 @@ public class UriResolverMapReader {
* @return the gcube generic query string
*/
public static String getGcubeGenericQueryString(String secondaryType, String name){
-
+
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' and $profile/Profile/Name/string() " +
" eq '" + name + "'" +
"return $profile";
-
+
}
-
+
/**
* Gets the application types.
*
@@ -176,7 +190,7 @@ public class UriResolverMapReader {
public String getResourceName() {
return resourceName;
}
-
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -194,8 +208,8 @@ public class UriResolverMapReader {
builder.append("]");
return builder.toString();
}
-
-
+
+
// /**
// * The main method.
// *
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
index f2cc17f..d4bdd58 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/ScopeUtil.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/ScopeUtil.java
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package org.gcube.portlets.user.uriresolvermanager.util;
@@ -15,31 +15,31 @@ 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?");
+ logger.warn("Input scope: "+scope+" has not / 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);
}
-
+
logger.trace("scope is "+ scope +" infra: "+rootScope);
-
+
return rootScope;
-
+
}
}
diff --git a/src/test/java/UriResolverManagerTest.java b/src/test/java/UriResolverManagerTest.java
index c338ec6..2d1ddc0 100644
--- a/src/test/java/UriResolverManagerTest.java
+++ b/src/test/java/UriResolverManagerTest.java
@@ -8,7 +8,7 @@ import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapExcept
import org.junit.Test;
/**
- *
+ *
*/
/**
@@ -17,12 +17,12 @@ import org.junit.Test;
*
*/
public class UriResolverManagerTest {
-
+
@Test
public void testUriResolverManger(){
UriResolverManager manager;
try {
- ScopeProvider.instance.set("/gcube/devsec/devVRE");
+ ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
manager = new UriResolverManager();
System.out.println(manager.getCapabilities());
System.out.println(manager.getApplicationTypes());
@@ -33,12 +33,12 @@ public class UriResolverManagerTest {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
}
-
- @Test
+
+// @Test
public void testGIS() {
-
+
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver = new UriResolverManager("GIS");
@@ -55,17 +55,17 @@ public class UriResolverManagerTest {
e.printStackTrace();
}
}
-
+
// @Test
public void testSMP() {
-
+
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver = new UriResolverManager("SMP");
Map params = new HashMap();
params.put("smp-uri","smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
params.put("fileName", "wikipediaLogo");
- params.put("contentType", "");
+ params.put("contentType", "");
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none
System.out.println(shortLink);
} catch (UriResolverMapException e) {
@@ -76,12 +76,12 @@ public class UriResolverManagerTest {
e.printStackTrace();
}
}
-
-
+
+
/**
* Thread safe
*/
- @Test
+// @Test
public void testSMPID(){
try {
@@ -91,7 +91,7 @@ public class UriResolverManagerTest {
Map params = new HashMap();
params.put("smp-id","553f9265e4b0567b75021fce");
params.put("fileName", "dog");
- params.put("contentType", "image/jpg");
+ params.put("contentType", "image/jpg");
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none
System.out.println(shortLink);
} catch (UriResolverMapException e) {
@@ -102,14 +102,14 @@ public class UriResolverManagerTest {
e.printStackTrace();
}
}
-
+
/**
* Thread safe
*/
// @Test
public void test2(){
-
-
+
+
//create thread to print counter value
Thread t = new Thread(new Runnable() {
@@ -117,17 +117,17 @@ public class UriResolverManagerTest {
public void run() {
while (true) {
try {
-
+
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver;
resolver = new UriResolverManager("GIS");
-
+
Map params = new HashMap();
params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec");
params.put("scope", "/gcube/devsec/devVRE");
String shortLink = resolver.getLink(params, true);
System.out.println(shortLink); //true, link is shorted otherwise none
-
+
System.out.println("Thread "+Thread.currentThread().getId() +" reading counter is: " + resolver.countReaders());
Thread.sleep(1000);
} catch (InterruptedException ex) {
@@ -141,11 +141,11 @@ public class UriResolverManagerTest {
}
}
}
-
+
});
-
+
t.start();
-
+
try {
Thread.sleep(500000);
} catch (InterruptedException e) {
@@ -153,7 +153,7 @@ public class UriResolverManagerTest {
e.printStackTrace();
}
}
-
+
}