Merge pull request '#23026 reinforced the logic to discovery the WEA Generic Resource' (!3) from feature_23026 into master
Reviewed-on: #3
This commit is contained in:
commit
7496865a60
|
@ -4,10 +4,11 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v6.34.2-SNAPSHOT] - 2022-03-08
|
||||
## [v6.34.3-SNAPSHOT] - 2022-03-23
|
||||
|
||||
#### Enhancements
|
||||
|
||||
- [#23020] Reinforce the (ApplicationProfile-)Workspace-Explorer-App discovery
|
||||
- [#22923] Migrate to maven-portal-bom 3.7.0[-SNAPSHOT]
|
||||
|
||||
## [v6.34.1] - 2021-12-20
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>workspace-tree-widget</artifactId>
|
||||
<version>6.34.2-SNAPSHOT</version>
|
||||
<version>6.34.3-SNAPSHOT</version>
|
||||
<name>gCube Workspace Tree Widget</name>
|
||||
<description>
|
||||
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
|
||||
|
|
|
@ -10,7 +10,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
|
@ -19,7 +20,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ApplicationProfileReader.
|
||||
*
|
||||
|
@ -48,6 +48,20 @@ public class ApplicationProfileReader {
|
|||
private String resourceName;
|
||||
private String appID;
|
||||
|
||||
public enum APPLICATION_PROFILE_ITEM {
|
||||
|
||||
SCOPE("/Scope/text()"), URL("/URL/text()");
|
||||
|
||||
private String xPath;
|
||||
|
||||
APPLICATION_PROFILE_ITEM(String xpath) {
|
||||
this.xPath = xpath;
|
||||
}
|
||||
|
||||
public String getXPath() {
|
||||
return xPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new application profile reader.
|
||||
|
@ -64,15 +78,17 @@ public class ApplicationProfileReader {
|
|||
this.scope = ScopeProvider.instance.get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this method looks up the generic resource among the ones available in the infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
||||
* resource name {@value #WORKSPACE_EXPLORER_APP_NAME} and secondaryType {@value #SECONDARY_TYPE}
|
||||
* this method looks up the generic resource among the ones available in the
|
||||
* infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
||||
* resource name {@value #WORKSPACE_EXPLORER_APP_NAME} and secondaryType
|
||||
* {@value #SECONDARY_TYPE}
|
||||
*
|
||||
* @return the applicationProfile profile
|
||||
*/
|
||||
/**
|
||||
* this method looks up the applicationProfile profile among the ones available in the infrastructure.
|
||||
* this method looks up the applicationProfile profile among the ones available
|
||||
* in the infrastructure.
|
||||
*
|
||||
* @return the applicationProfile profile
|
||||
*/
|
||||
|
@ -86,13 +102,15 @@ public class ApplicationProfileReader {
|
|||
if (scope == null)
|
||||
throw new Exception("Scope is null, set scope into ScopeProvider");
|
||||
|
||||
logger.info("Trying to fetch ApplicationProfile in the scope: "+scope+", SecondaryType: " + secondaryType + ", AppId: " + appID);
|
||||
logger.info("Trying to fetch " + SECONDARY_TYPE + " in the scope: " + scope + ", 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 scope: "+scope);
|
||||
throw new ApplicationProfileNotFoundException("Generic Resource with SecondaryType: " + secondaryType
|
||||
+ ", AppId: " + appID + " is not registered in the scope: " + scope);
|
||||
else {
|
||||
String elem = appProfile.get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
@ -103,77 +121,36 @@ public class ApplicationProfileReader {
|
|||
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 " + SECONDARY_TYPE + " NAME was not found in the generic resource");
|
||||
|
||||
currValue = helper.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
appProf.setDescription(currValue.get(0));
|
||||
}
|
||||
else logger.warn("No Description exists for " + appProf.getName());
|
||||
} else
|
||||
logger.warn("No Description exists for " + appProf.getName());
|
||||
|
||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_APP_ID_TEXT);
|
||||
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 " + SECONDARY_TYPE
|
||||
+ " ID was not found in the generic resource, consider adding <AppId> element in <Body>");
|
||||
|
||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
appProf.setImageUrl(currValue.get(0));
|
||||
}
|
||||
else{
|
||||
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
||||
} else {
|
||||
logger.warn("Null or empty <ThumbnailURL> element in <Body> of " + 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()");
|
||||
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
List<String> scopes = currValue;
|
||||
String currentScope = scopes.get(0);
|
||||
appProf = readEndPointForScopeWithRetry(helper, scope, APPLICATION_PROFILE_ITEM.SCOPE, appProf);
|
||||
|
||||
//int slashCount = StringUtils.countMatches(currentScope, "/");
|
||||
|
||||
boolean isVRE = WsUtil.isVRE(currentScope);
|
||||
|
||||
//if(slashCount < 3){//CASE not VRE - set session scope
|
||||
if(!isVRE){//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
|
||||
logger.debug("ListSessionScope is: "+ listSessionScope.toString());
|
||||
|
||||
if(listSessionScope!=null && listSessionScope.size()>0){ //If sessions scope exists
|
||||
|
||||
logger.debug("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());
|
||||
|
||||
}
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile with scope "+scope.toString()+" was not found in the profile, consider adding <EndPoint><Scope> element in <Body>");
|
||||
appProf = readEndPointForScopeWithRetry(helper, scope, APPLICATION_PROFILE_ITEM.URL, appProf);
|
||||
|
||||
logger.debug("returning: " + appProf);
|
||||
return appProf;
|
||||
|
@ -184,30 +161,84 @@ public class ApplicationProfileReader {
|
|||
return null;
|
||||
} finally {
|
||||
/*
|
||||
if(originalScope!=null && !originalScope.isEmpty()){
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||
}else{
|
||||
ScopeProvider.instance.reset();
|
||||
logger.info("scope provider reset");
|
||||
}*/
|
||||
* if(originalScope!=null && !originalScope.isEmpty()){
|
||||
* ScopeProvider.instance.set(originalScope);
|
||||
* logger.info("scope provider setted to orginal scope: "+originalScope); }else{
|
||||
* ScopeProvider.instance.reset(); logger.info("scope provider reset"); }
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ApplicationProfile readEndPointForScopeWithRetry(XPathHelper helper, String scope,
|
||||
APPLICATION_PROFILE_ITEM searchItem, ApplicationProfile appProf)
|
||||
throws ApplicationProfileNotFoundException {
|
||||
|
||||
String xPathToQuery = "/Resource/Profile/Body/EndPoint[Scope='" + scope + "']" + searchItem.getXPath();
|
||||
logger.debug("Identifying path with current scope: " + xPathToQuery);
|
||||
List<String> currValue = helper.evaluate(xPathToQuery);
|
||||
|
||||
String queryResult = null;
|
||||
|
||||
if (currValue == null || currValue.isEmpty()) {
|
||||
logger.warn("In the " + SECONDARY_TYPE + " with name " + appProf.getName() + " the xPath " + xPathToQuery
|
||||
+ " returned with no results");
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(scope);
|
||||
if (scopeBean.is(Type.VRE) || scopeBean.is(Type.VO)) {
|
||||
String pathSeparator = "/";
|
||||
String[] components = scope.split(pathSeparator);
|
||||
scope = pathSeparator + components[1];
|
||||
logger.info("The scope "+scopeBean.toString()+" is of kind " + Type.VRE + " or " + Type.VO
|
||||
+ ". Retry in action - going to search the default <EndPoint> with the root scope: " + scope);
|
||||
|
||||
xPathToQuery = "/Resource/Profile/Body/EndPoint[Scope='" + scope + "']" + searchItem.getXPath();
|
||||
logger.debug("Identifying path with root scope: " + xPathToQuery);
|
||||
currValue = helper.evaluate(xPathToQuery);
|
||||
|
||||
if (currValue == null || currValue.isEmpty()) {
|
||||
logger.warn("In the " + SECONDARY_TYPE + " with name " + appProf.getName() + " the xPath " + xPathToQuery
|
||||
+ " returned with no results");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (currValue == null || currValue.isEmpty()) {
|
||||
throw new ApplicationProfileNotFoundException("Your ApplicationProfile in the scope " + scope
|
||||
+ " have not an <EndPoint> accessible, consider adding <EndPoint><Scope></Scope> element in <Body>");
|
||||
}
|
||||
|
||||
queryResult = currValue.get(0);
|
||||
logger.info("The xPath: " + xPathToQuery + " returned with the result: " + queryResult);
|
||||
|
||||
switch (searchItem) {
|
||||
case SCOPE:
|
||||
appProf.setScope(currValue.get(0));
|
||||
break;
|
||||
case URL:
|
||||
appProf.setUrl(currValue.get(0));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return appProf;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string.
|
||||
* Gets the gcube generic xPath string.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @param appId the app id
|
||||
* @return the gcube generic query string
|
||||
* @return the gcube generic xPath string
|
||||
*/
|
||||
public static String getGcubeGenericQueryString(String secondaryType, String appId) {
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' and $profile/Profile/Body/AppId/string() " +
|
||||
" eq '" + appId + "'" +
|
||||
"return $profile";
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
|
||||
+ "' and $profile/Profile/Body/AppId/string() " + " eq '" + appId + "'" + "return $profile";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,7 +250,6 @@ public class ApplicationProfileReader {
|
|||
return secondaryType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the scope.
|
||||
*
|
||||
|
@ -238,8 +268,9 @@ public class ApplicationProfileReader {
|
|||
return resourceName;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl;
|
||||
import org.gcube.portlets.user.workspace.server.reader.ApplicationProfileReader;
|
||||
|
||||
public class TestProperties {
|
||||
|
||||
// public static void main(String[] args) {
|
||||
|
@ -28,19 +21,5 @@ public class TestProperties {
|
|||
//
|
||||
// }
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/D4Research/Limnodata");
|
||||
ApplicationProfileReader ap = new ApplicationProfileReader("Workspace-Explorer-App", "org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl");
|
||||
System.out.println(ap.readProfileFromInfrastrucure());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.gcube.portlets.user.workspace.junit;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.workspace.server.reader.ApplicationProfileReader;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WEA_AP_Reader {
|
||||
|
||||
String scope = "/gcube/devsec/devVRE";
|
||||
String resourceName = "Workspace-Explorer-App";
|
||||
String appID = "org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl";
|
||||
|
||||
@Test
|
||||
public void readAP() {
|
||||
|
||||
try {
|
||||
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/D4Research/Limnodata");
|
||||
ScopeProvider.instance.set(scope);
|
||||
ApplicationProfileReader ap = new ApplicationProfileReader(resourceName, appID);
|
||||
System.out.println("ApplicationProfile found: "+ap.readProfileFromInfrastrucure());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue