Added ScopeProvider.instance.reset() in finally statement
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@128574 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1d79703f6f
commit
36b49746d3
|
@ -19,13 +19,13 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* @Oct 13, 2014
|
* @Oct 13, 2014
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ApplicationProfileReader {
|
public class ApplicationProfileReader {
|
||||||
|
|
||||||
protected static final String RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT = "/Resource/Profile/Body/EndPoint/URL/text()";
|
protected static final String RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT = "/Resource/Profile/Body/EndPoint/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_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_TEXT = "/Resource/Profile/Body/text()";
|
||||||
|
@ -33,25 +33,25 @@ public class ApplicationProfileReader {
|
||||||
protected static final String RESOURCE_PROFILE_BODY_APP_ID_TEXT = "/Resource/Profile/Body/AppId/text()";
|
protected static final String RESOURCE_PROFILE_BODY_APP_ID_TEXT = "/Resource/Profile/Body/AppId/text()";
|
||||||
protected static final String RESOURCE_PROFILE_DESCRIPTION_TEXT = "/Resource/Profile/Description/text()";
|
protected static final String RESOURCE_PROFILE_DESCRIPTION_TEXT = "/Resource/Profile/Description/text()";
|
||||||
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
|
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(ApplicationProfileReader.class);
|
private Logger logger = Logger.getLogger(ApplicationProfileReader.class);
|
||||||
private String secondaryType;
|
private String secondaryType;
|
||||||
private String appId;
|
private String appId;
|
||||||
private String scope;
|
private String scope;
|
||||||
private ApplicationProfile applicationProfile;
|
private ApplicationProfile applicationProfile;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param scope - the scope to be searched
|
* @param scope - the scope to be searched
|
||||||
* @param genericResource - the name of generic resource
|
* @param genericResource - the name of generic resource
|
||||||
* @param portletClassName - the AppId of generic resource
|
* @param portletClassName - the AppId of generic resource
|
||||||
*/
|
*/
|
||||||
public ApplicationProfileReader(String scope, String secondaryType, String portletClassName) {
|
public ApplicationProfileReader(String scope, String secondaryType, String portletClassName) {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.secondaryType = secondaryType;
|
this.secondaryType = secondaryType;
|
||||||
this.appId = portletClassName;
|
this.appId = portletClassName;
|
||||||
this.applicationProfile = readProfileFromInfrastrucure();
|
this.applicationProfile = readProfileFromInfrastrucure();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationProfile getApplicationProfile() {
|
public ApplicationProfile getApplicationProfile() {
|
||||||
|
@ -67,47 +67,47 @@ public class ApplicationProfileReader {
|
||||||
|
|
||||||
ApplicationProfile appProf = new ApplicationProfile();
|
ApplicationProfile appProf = new ApplicationProfile();
|
||||||
String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId);
|
String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId);
|
||||||
|
|
||||||
logger.info("Trying to fetch applicationProfile profile from the infrastructure for " + secondaryType + " scope: " + scope);
|
logger.info("Trying to fetch applicationProfile profile from the infrastructure for " + secondaryType + " scope: " + scope);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String infra = ScopeUtil.getInfrastructureNameFromScope(this.scope);
|
String infra = ScopeUtil.getInfrastructureNameFromScope(this.scope);
|
||||||
ScopeProvider.instance.set(infra);
|
ScopeProvider.instance.set(infra);
|
||||||
logger.info("scope provider set instance: "+infra);
|
logger.info("scope provider set instance: "+infra);
|
||||||
|
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
|
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> appProfile = client.submit(q);
|
List<String> appProfile = client.submit(q);
|
||||||
|
|
||||||
if (appProfile == null || appProfile.size() == 0)
|
if (appProfile == null || appProfile.size() == 0)
|
||||||
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure");
|
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure");
|
||||||
else {
|
else {
|
||||||
String elem = appProfile.get(0);
|
String elem = appProfile.get(0);
|
||||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||||
XPathHelper helper = new XPathHelper(node);
|
XPathHelper helper = new XPathHelper(node);
|
||||||
|
|
||||||
List<String> currValue = null;
|
List<String> currValue = null;
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
currValue = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
appProf.setName(currValue.get(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);
|
currValue = helper.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
appProf.setDescription(currValue.get(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);
|
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_APP_ID_TEXT);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
appProf.setKey(currValue.get(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 n was not found in the profile, consider adding <AppId> element in <Body>");
|
||||||
|
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
appProf.setImageUrl(currValue.get(0));
|
appProf.setImageUrl(currValue.get(0));
|
||||||
|
@ -115,23 +115,23 @@ public class ApplicationProfileReader {
|
||||||
else{
|
else{
|
||||||
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
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()");
|
||||||
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
List<String> scopes = currValue;
|
List<String> scopes = currValue;
|
||||||
String currentScope = scopes.get(0);
|
String currentScope = scopes.get(0);
|
||||||
|
|
||||||
int slashCount = StringUtils.countMatches(currentScope, "/");
|
int slashCount = StringUtils.countMatches(currentScope, "/");
|
||||||
|
|
||||||
if(slashCount < 3){//CASE not VRE - set session scope
|
if(slashCount < 3){//CASE not VRE - set session scope
|
||||||
logger.info("Scope "+ scope.toString() + " is not a VRE");
|
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
|
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
|
if(listSessionScope!=null && listSessionScope.size()>0){ //If sessions scope exists
|
||||||
|
|
||||||
logger.trace("setting session scope "+ listSessionScope.get(0));
|
logger.trace("setting session scope "+ listSessionScope.get(0));
|
||||||
appProf.setScope(listSessionScope.get(0));
|
appProf.setScope(listSessionScope.get(0));
|
||||||
}
|
}
|
||||||
|
@ -143,12 +143,12 @@ public class ApplicationProfileReader {
|
||||||
else{ //CASE IS A VRE
|
else{ //CASE IS A VRE
|
||||||
logger.info("Scope "+ scope.toString() + " is a VRE");
|
logger.info("Scope "+ scope.toString() + " is a VRE");
|
||||||
appProf.setScope(scope.toString());
|
appProf.setScope(scope.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//RETRIEVE URL
|
//RETRIEVE URL
|
||||||
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/URL/text()");
|
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/URL/text()");
|
||||||
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
String url = currValue.get(0);
|
String url = currValue.get(0);
|
||||||
// System.out.println("URL "+url);
|
// System.out.println("URL "+url);
|
||||||
|
@ -158,10 +158,10 @@ public class ApplicationProfileReader {
|
||||||
throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString());
|
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 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>");
|
else throw new ApplicationProfileNotFoundException("Your applicationProfile with scope "+scope.toString()+" was not found in the profile, consider adding <EndPoint><Scope> element in <Body>");
|
||||||
|
|
||||||
return appProf;
|
return appProf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,10 +169,12 @@ public class ApplicationProfileReader {
|
||||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure");
|
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
}finally{
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -187,17 +189,17 @@ public class ApplicationProfileReader {
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
|
String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
|
||||||
String scope ="/gcube";
|
String scope ="/gcube";
|
||||||
String secondaryType = "ApplicationProfile";
|
String secondaryType = "ApplicationProfile";
|
||||||
ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName);
|
ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName);
|
||||||
|
|
||||||
System.out.println(reader);
|
System.out.println(reader);
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,8 @@ public class GeoRuntimeReader {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Sorry, an error occurred on reading parameters in Runtime Reosurces",e);
|
logger.error("Sorry, an error occurred on reading parameters in Runtime Reosurces",e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
|
|
Loading…
Reference in New Issue