diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index 9adcb81..8f0b83a 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,4 +1,3 @@ -#Wed Jun 27 12:10:12 CEST 2012 eclipse.preferences.version=1 jarsExcludedFromWebInfLib= warSrcDir= diff --git a/pom.xml b/pom.xml index 0c5136e..92b9354 100644 --- a/pom.xml +++ b/pom.xml @@ -87,13 +87,13 @@ org.gcube.portlets.user home-library - [4.3.0-SNAPSHOT, 5.0.0-SNAPSHOT) + [4.3.0-SNAPSHOT, 5.0.0-SNAPSHOT) provided org.gcube.portlets.user home-library-jcr - [1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT) provided @@ -230,7 +230,7 @@ - + org.codehaus.mojo gwt-maven-plugin @@ -243,11 +243,7 @@ - - WorkspacePortlet.html - ${webappDirectory} diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 1e5f52c..eb8d3b7 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -184,7 +184,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt @Override public void onFailure(Throwable caught) { - new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR+" un share folder. "+ ConstantsExplorer.TRY_AGAIN, null); + new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR+" un share folder. "+ caught.getMessage() +". " +ConstantsExplorer.TRY_AGAIN, null); } @@ -874,7 +874,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt @Override public void onFailure(Throwable caught) { explorerPanel.getAsycTreePanel().unmask(); - new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR +" deleting item. Reload root", null); + new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR +" deleting item. "+caught.getMessage()+". Reload root", null); explorerPanel.getAsycTreePanel().removeAllAndRecoveryRoot(); } @@ -1021,7 +1021,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt @Override public void onFailure(Throwable caught) { - new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " moving item. Reload root" , null); + new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " moving item. "+caught.getMessage()+". Reload root" , null); System.out.println(caught.getMessage()); explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(event.getTargetParentFileModel().getIdentifier()); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index dc34e6a..bfa88fa 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -11,6 +11,7 @@ import org.gcube.application.framework.core.session.ASLSession; import org.gcube.applicationsupportlayer.social.SocialPortalBridge; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.portlets.user.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException; import org.gcube.portlets.user.homelibrary.home.workspace.Workspace; @@ -58,7 +59,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT public static final String LAST_OPEN_FOLDER_ATTRIBUTE = "WORKSPACE.LAST_OPEN_FOLDER"; public static final String SELECTION_STATE_ATTRIBUTE = "WORKSPACE.SELECTION_STATE"; - protected GCUBEClientLog workspaceLogger = new GCUBEClientLog("GWTWorkspaceServiceImpl"); + protected GCUBELog workspaceLogger = new GCUBEClientLog(GWTWorkspaceServiceImpl.class); protected GWTWorkspaceBuilder getGWTWorkspaceBuilder() diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/GcubeApplicationProfileReader.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/GcubeApplicationProfileReader.java new file mode 100644 index 0000000..12d656a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/GcubeApplicationProfileReader.java @@ -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 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 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 element in "); + + 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 element in "); + currValue = node.evaluate(RESOURCE_PROFILE_BODY_ENDPOINT_SCOPE_TEXT); + if (currValue != null && currValue.size() > 0) { + List 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 element in "); + return toReturn; + } + + } catch (Exception e) { + logger.error("Error while trying to fetch applicationProfile profile from the infrastructure"); + e.printStackTrace(); + return null; + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/ApplicationProfile.java b/src/main/java/org/gcube/portlets/user/workspace/shared/ApplicationProfile.java new file mode 100644 index 0000000..26a8de4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/ApplicationProfile.java @@ -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 + "]"; + } +}