Updated pom version at 1.13

Completed Feature #9108

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@150696 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-07-03 14:25:14 +00:00
parent a2cfc02f48
commit 0bb83e8736
7 changed files with 186 additions and 64 deletions

View File

@ -86,4 +86,9 @@
<Change>[Feature #8494] Remove GeoServices query from URI-Resolver
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-13-0"
date="2017-07-03">
<Change>[Feature #9108] Edit the GenericResource (ApplicationProfile-Gis Viewer Application)
</Change>
</Changeset>
</ReleaseNotes>

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId>
<version>1.12.0-SNAPSHOT</version>
<version>1.13.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>The URI Resolver is an HTTP URI resolver implemented as an HTTP servlet which gives access trough HTTP to different protocols URIs. </description>

View File

@ -183,7 +183,7 @@ public class UriResolverRewriteFilter implements Filter{
}
}
else {
logger.debug("is NOT a SMP public uri by ID, doFilter Request");
logger.debug("It is NOT a SMP public uri by ID, doFilter Request");
chain.doFilter(multiReadRequest, response);
}
}

View File

@ -8,7 +8,6 @@ import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
@ -28,7 +27,11 @@ import org.xml.sax.InputSource;
*/
public class ApplicationProfileReader {
protected static final String RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT = "/Resource/Profile/Body/EndPoint/URL/text()";
/**
*
*/
private static final String RESOURCE_PROFILE_BODY_END_POINT_URL = "/Resource/Profile/Body/EndPoint/URL";
protected static final String RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT = RESOURCE_PROFILE_BODY_END_POINT_URL+"/text()";
protected static final String RESOURCE_PROFILE_BODY_END_POINT_SCOPE_TEXT = "/Resource/Profile/Body/EndPoint/Scope/text()";
protected static final String RESOURCE_PROFILE_BODY_TEXT = "/Resource/Profile/Body/text()";
protected static final String RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT = "/Resource/Profile/Body/ThumbnailURL/text()";
@ -85,25 +88,28 @@ public class ApplicationProfileReader {
originalScope = ScopeProvider.instance.get();
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope;
ScopeProvider.instance.set(discoveryScope);
logger.info("Trying to fetch ApplicationProfile in the infra scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
logger.info("Trying to fetch Generic Resource in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the infra scope: "+discoveryScope);
throw new ApplicationProfileNotFoundException("Generic Resource with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the scope: "+discoveryScope);
else {
String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
XPathHelper helper = new XPathHelper(node);
//set scope
appProf.setScope(discoveryScope);
List<String> currValue = null;
currValue = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
if (currValue != null && currValue.size() > 0) {
appProf.setName(currValue.get(0));
}
else throw new ApplicationProfileNotFoundException("Your applicationProfile NAME was not found in the profile");
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile NAME was not found in the profile");
currValue = helper.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
if (currValue != null && currValue.size() > 0) {
@ -115,7 +121,7 @@ public class ApplicationProfileReader {
if (currValue != null && currValue.size() > 0) {
appProf.setKey(currValue.get(0));
}
else throw new ApplicationProfileNotFoundException("Your applicationProfile ID n was not found in the profile, consider adding <AppId> element in <Body>");
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile ID was not found in the profile, consider adding <AppId> element in <Body>");
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
if (currValue != null && currValue.size() > 0) {
@ -125,50 +131,20 @@ public class ApplicationProfileReader {
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
}
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
//currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
//RETRIEVE URL
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT);
if (currValue != null && currValue.size() > 0) {
List<String> scopes = currValue;
String currentScope = scopes.get(0);
int slashCount = StringUtils.countMatches(currentScope, "/");
if(slashCount < 3){//CASE not VRE - set session scope
logger.info("Scope "+ scope.toString() + " is not a VRE");
List<String> listSessionScope = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Sessionscope/text()"); //get session scope of i+1-mo scope
if(listSessionScope!=null && listSessionScope.size()>0){ //If sessions scope exists
logger.trace("setting session scope "+ listSessionScope.get(0));
appProf.setScope(listSessionScope.get(0));
}
else{
logger.trace("session scope not exists setting scope "+ scope.toString());
appProf.setScope(scope.toString());
}
}
else{ //CASE IS A VRE
logger.info("Scope "+ scope.toString() + " is a VRE");
appProf.setScope(scope.toString());
}
//RETRIEVE URL
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/URL/text()");
if (currValue != null && currValue.size() > 0) {
String url = currValue.get(0);
// System.out.println("URL "+url);
if(url!=null)
appProf.setUrl(url);
else
throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString());
}
else throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString());
String url = currValue.get(0);
// System.out.println("URL "+url);
if(url!=null)
appProf.setUrl(url);
else
throw new ApplicationProfileNotFoundException("Your ApplicationProfile URL was not found in the profile for Scope: " + scope.toString() +", consider adding <EndPoint><URL> element in <Body>");
}
else throw new ApplicationProfileNotFoundException("Your applicationProfile with scope "+scope.toString()+" was not found in the profile, consider adding <EndPoint><Scope> element in <Body>");
else throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" in the scope: "+discoveryScope +" does not contain "+RESOURCE_PROFILE_BODY_END_POINT_URL +" property, please add it");
return appProf;
}
@ -206,16 +182,16 @@ public class ApplicationProfileReader {
return builder.toString();
}
/*
public static void main(String[] args) {
String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
String scope ="/gcube";
String secondaryType = "ApplicationProfile";
ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName);
System.out.println(reader);
}*/
// public static void main(String[] args) {
//
// String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
// String scope ="/gcube/devNext/NextNext";
// String secondaryType = "ApplicationProfile";
// ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName, true);
//
// System.out.println(reader);
//
// }
}

View File

@ -210,7 +210,7 @@ public class GisResolver extends HttpServlet{
if(gisViewerAppPropertyReader==null)
resetGisViewerAppEndPoint();
ApplicationProfileReader reader = new ApplicationProfileReader(scope, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId(), true);
ApplicationProfileReader reader = new ApplicationProfileReader(scope, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId(), false);
String url = reader.getApplicationProfile().getUrl();
cachedGisViewerApplHostname.put(scope, url);
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);

View File

@ -0,0 +1,104 @@
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.Serializable;
import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
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
* Jun 10, 2016
*/
public class GcoreEndpointReader implements Serializable{
private static final long serialVersionUID = 7631710353375893823L;
private static final String ckanResource = "org.gcube.data.access.ckanconnector.CkanConnector";
private static final String serviceName = "CkanConnector";
private static final String serviceClass = "DataAccess";
private static final Logger logger = LoggerFactory.getLogger(GcoreEndpointReader.class);
private String ckanResourceEntyName;
/**
* Instantiates a new gcore endpoint reader.
*
* @param scope the scope
* @throws Exception the exception
*/
public GcoreEndpointReader(String scope) throws Exception {
String currentScope = ScopeProvider.instance.get();
try{
logger.info("set scope "+scope);
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName));
query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+ckanResource+"\"]/text()");
logger.debug("submitting quey "+query.toString());
DiscoveryClient<String> client = client();
List<String> endpoints = client.submit(query);
if (endpoints == null || endpoints.isEmpty()) throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
this.ckanResourceEntyName = endpoints.get(0);
if(ckanResourceEntyName==null)
throw new Exception("Endpoint:"+ckanResource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
logger.info("found entyname "+ckanResourceEntyName+" for ckanResource: "+ckanResource);
/*Group<Endpoint> accessPoints = se.profile().endpoints();
if(accessPoints.size()==0) throw new Exception("Endpoint in serviceName serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope +" not found");
Endpoint ep = accessPoints.iterator().next();
String epName = ep.name();
System.out.println(epName);*/
}catch(Exception e){
String error = "An error occurred during GCoreEndpoint discovery, serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope +".";
logger.error(error, e);
throw new Exception(error);
}finally{
logger.info("scope provider reset");
ScopeProvider.instance.set(currentScope);
}
}
/**
* @return the ckanResourceEntyName
*/
public String getCkanResourceEntyName() {
return ckanResourceEntyName;
}
private static String scope = "/d4science.research-infrastructures.eu";
public static void main(String[] args) {
try {
GcoreEndpointReader reader = new GcoreEndpointReader(scope);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -11,6 +11,7 @@ import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.junit.Test;
import org.opengis.metadata.Metadata;
/**
*
@ -21,15 +22,21 @@ public class GeonetworkQueryTest {
private static final int MAX = 10;
private static final String UUID = "8a878105-ef06-4b1f-843f-120fc525b22b";
//private String[] scopes = {"/gcube/devNext/NextNext"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
// private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon"};
private LoginLevel loginLevel = LoginLevel.CKAN;
@ -84,6 +91,38 @@ public class GeonetworkQueryTest {
}
}
//@Test
public void getLayerByUUID() throws Exception{
try{
for(String scope:scopesProd){
ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get();
Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType);
//System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword());
System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
Metadata meta = reader.getById(UUID);
try{
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword());
System.out.println("Decrypted Password: "+decryptedPassword);
}catch(Exception e){
System.out.println("ignoring exception during pwd decrypting");
}
System.out.println("SCOPE "+scope+" found meta "+meta);
}
}catch(Exception e){
System.err.println("Error on getting layer by UUID: "+UUID);
e.printStackTrace();
}
}
//@Test
public void getLayersBySearch() throws Exception{
@ -92,8 +131,6 @@ public class GeonetworkQueryTest {
ScopeProvider.instance.set(scope);
GeoNetworkPublisher reader=GeoNetwork.get();
Configuration config = reader.getConfiguration();
Account account=config.getScopeConfiguration().getAccounts().get(accountType);