exception alert was updated
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@69373 82a268e6-3cf1-43bd-a215-b396298e98cftask/19600
parent
9237f3d052
commit
f51c6fe6f0
@ -0,0 +1,126 @@
|
||||
package org.gcube.portlets.user.workspace.server.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.XMLResult;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||
import org.gcube.portlets.user.workspace.shared.ApplicationProfile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class GcubeApplicationProfileReader {
|
||||
|
||||
protected static final String RESOURCE_PROFILE_BODY_ENDPOINT_URL_TEXT = "/Resource/Profile/Body/EndPoint/URL/text()";
|
||||
protected static final String RESOURCE_PROFILE_BODY_ENDPOINT_SCOPE_TEXT = "/Resource/Profile/Body/EndPoint/Scope/text()";
|
||||
protected static final String RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT = "/Resource/Profile/Body/ThumbnailURL/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_NAME_TEXT = "/Resource/Profile/Name/text()";
|
||||
|
||||
private ASLSession aslSession;
|
||||
private ApplicationProfile applicationProfile;
|
||||
private GCUBEClientLog logger = new GCUBEClientLog(GcubeApplicationProfileReader.class);
|
||||
|
||||
public ApplicationProfile getApplicationProfile() {
|
||||
return applicationProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param session
|
||||
*/
|
||||
public GcubeApplicationProfileReader(ASLSession session, String portletClassName) {
|
||||
this.aslSession = session;
|
||||
this.applicationProfile = readProfileFromInfrastrucure(portletClassName);
|
||||
}
|
||||
|
||||
|
||||
public GcubeApplicationProfileReader(ASLSession session) {
|
||||
this.aslSession = session;
|
||||
this.applicationProfile = null;
|
||||
}
|
||||
/**
|
||||
* this method looks up the applicationProfile profile among the ones available in the infrastructure
|
||||
* @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile
|
||||
* @return the applicationProfile profile
|
||||
*/
|
||||
private ApplicationProfile readProfileFromInfrastrucure(String portletClassName) {
|
||||
try {
|
||||
ApplicationProfile toReturn = new ApplicationProfile();
|
||||
ISClient client = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericQuery query = client.getQuery(GCUBEGenericQuery.class);
|
||||
|
||||
|
||||
query.setExpression("for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq 'ApplicationProfile' and $profile/Profile/Body/AppId/string() " +
|
||||
" eq '" + portletClassName + "'" +
|
||||
"return $profile");
|
||||
|
||||
GCUBEScope scope = aslSession.getScope();
|
||||
|
||||
List<XMLResult> appProfile = client.execute(query, scope.getInfrastructure());
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure");
|
||||
else {
|
||||
XMLResult node = appProfile.get(0);
|
||||
List<String> currValue = null;
|
||||
currValue = node.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
toReturn.setName(currValue.get(0));
|
||||
}
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile NAME was not found in the profile");
|
||||
|
||||
currValue = node.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
toReturn.setDescription(currValue.get(0));
|
||||
}
|
||||
else logger.warn("No Description exists for " + toReturn.getName());
|
||||
|
||||
currValue = node.evaluate(RESOURCE_PROFILE_BODY_APP_ID_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
toReturn.setKey(currValue.get(0));
|
||||
}
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile ID n was not found in the profile, consider adding <AppId> element in <Body>");
|
||||
|
||||
currValue = node.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
toReturn.setImageUrl(currValue.get(0));
|
||||
}
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile Image Url was not found in the profile, consider adding <ThumbnailURL> element in <Body>");
|
||||
currValue = node.evaluate(RESOURCE_PROFILE_BODY_ENDPOINT_SCOPE_TEXT);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
List<String> scopes = currValue;
|
||||
boolean foundUrl = false;
|
||||
for (int i = 0; i < scopes.size(); i++) {
|
||||
if (currValue.get(i).trim().compareTo(scope.toString()) == 0) {
|
||||
toReturn.setUrl(node.evaluate(RESOURCE_PROFILE_BODY_ENDPOINT_URL_TEXT).get(i));
|
||||
toReturn.setScope(scope.toString());
|
||||
foundUrl = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! foundUrl)
|
||||
throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString());
|
||||
}
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile EndPoint was not found in the profile, consider adding <EndPoint><Scope> element in <Body>");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package org.gcube.portlets.user.workspace.shared;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ApplicationProfile implements Serializable {
|
||||
|
||||
private String key;
|
||||
private String name;
|
||||
private String description;
|
||||
private String imageUrl;
|
||||
private String scope;
|
||||
private String url;
|
||||
|
||||
public ApplicationProfile() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ApplicationProfile(String key, String name, String description, String imageUrl, String scope, String url) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.imageUrl = imageUrl;
|
||||
this.scope = scope;
|
||||
this.url = url;
|
||||
}
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApplicationProfile [key=" + key + ", name=" + name + ", description="
|
||||
+ description + ", imageUrl=" + imageUrl + ", scope=" + scope
|
||||
+ ", url=" + url + "]";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue