diff --git a/pom.xml b/pom.xml
index 6d0f846..82176d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,11 +122,28 @@
provided
+
org.gcube.portal
custom-portal-handler
+ provided
+
+
+ org.gcube.portal
+ social-networking-library
+ provided
+
+
+
+ org.gcube.applicationsupportlayer
+ aslsocial
+ provided
+
+
+
+
org.gcube.common
home-library
@@ -204,14 +221,9 @@
provided
-
-
+
+
diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java
index cf05b4f..5c192d1 100644
--- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java
@@ -145,6 +145,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Unio
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecutionDirector;
import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTDCreator;
import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTypeMap;
+import org.gcube.portlets.user.td.gwtservice.server.social.TDMNotifications;
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ExtractReferences;
@@ -4711,7 +4712,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
-
/**
*
* @param trId
@@ -4853,8 +4853,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceIsFlow(tabularResource);
checkTabularResourceLocked(tabularResource);
-
- ///
+
+ // /
OpExecution4SDMXCodelistExport opEx = new OpExecution4SDMXCodelistExport(
service, exportSession);
OpExecutionDirector director = new OpExecutionDirector();
@@ -5915,6 +5915,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Share with Users: " + users);
service.share(tabularResourceId, usersArray);
+ TDMNotifications tdmNotifications = new TDMNotifications(
+ aslSession, shareInfo);
+ tdmNotifications.start();
+
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
@@ -5960,6 +5964,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Share with Users: " + users);
service.share(templateId, usersArray);
+ TDMNotifications tdmNotifications = new TDMNotifications(
+ aslSession, shareTemplate);
+ tdmNotifications.start();
+
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
@@ -6004,6 +6012,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Share with Users: " + users);
service.share(ruleId, usersArray);
+ TDMNotifications tdmNotifications = new TDMNotifications(
+ aslSession, shareRule);
+ tdmNotifications.start();
+
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
@@ -8988,7 +9000,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException("Resource has type null!");
}
-
switch (resourceTDType) {
case CHART:
case CODELIST:
@@ -8997,7 +9008,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case GENERIC_TABLE:
case GUESSER:
case JSON:
- case SDMX:
+ case SDMX:
saveResourceByStorageId(saveResourceSession, aslSession,
mimeType, resourceTDDescriptor);
break;
@@ -9025,19 +9036,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
-
+
protected void saveResourceByStorageId(
SaveResourceSession saveResourceSession, ASLSession aslSession,
- String mimeType, ResourceTDDescriptor resourceTDDescriptor) throws TDGWTServiceException {
+ String mimeType, ResourceTDDescriptor resourceTDDescriptor)
+ throws TDGWTServiceException {
ResourceTD resource = resourceTDDescriptor.getResourceTD();
- String storageId=null;
+ String storageId = null;
if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD = (StringResourceTD) resource;
- storageId=stringResourceTD.getStringValue();
+ storageId = stringResourceTD.getStringValue();
} else {
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
- storageId=internalURITD.getId();
+ storageId = internalURITD.getId();
mimeType = internalURITD.getMimeType();
} else {
if (resource instanceof TableResourceTD) {
@@ -9053,22 +9065,22 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (storageId == null || storageId.isEmpty()) {
throw new TDGWTServiceException(
- "This resource does not have valid storage id: " + storageId);
+ "This resource does not have valid storage id: "
+ + storageId);
}
- logger.debug("Create Item On Workspace: [storageId=" + storageId + " ,user: "
- + aslSession.getUsername() + " ,fileName: "
+ logger.debug("Create Item On Workspace: [storageId=" + storageId
+ + " ,user: " + aslSession.getUsername() + " ,fileName: "
+ saveResourceSession.getFileName() + " ,fileDescription: "
+ saveResourceSession.getFileDescription() + " ,mimetype:"
+ mimeType + " ,folder: " + saveResourceSession.getItemId()
+ "]");
FilesStorage storage = new FilesStorage();
- storage.createItemOnWorkspaceByStorageId(storageId, aslSession.getUsername(),
- saveResourceSession.getFileName(),
+ storage.createItemOnWorkspaceByStorageId(storageId,
+ aslSession.getUsername(), saveResourceSession.getFileName(),
saveResourceSession.getFileDescription(), mimeType,
saveResourceSession.getItemId());
}
-
protected void saveResourceByInputStream(
SaveResourceSession saveResourceSession, ASLSession aslSession,
@@ -9079,8 +9091,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD = (StringResourceTD) resource;
String uri = stringResourceTD.getStringValue();
- uriResolverSession = new UriResolverSession(uri,
- applicationType);
+ uriResolverSession = new UriResolverSession(uri, applicationType);
} else {
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
@@ -9453,8 +9464,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try {
// HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
- logger.debug("StartApplyTableRule: "+applyTableRuleSession);
-
+ logger.debug("StartApplyTableRule: " + applyTableRuleSession);
+
SessionUtil
.setApplyTableRuleSession(session, applyTableRuleSession);
@@ -9463,20 +9474,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(
"Error in apply rule on table: ApplyTableRuleSession is null");
}
-
+
if (applyTableRuleSession.getRuleDescriptionData() == null) {
- logger.error("Apply Table Rule Session: RuleDescriptionData is null: "+applyTableRuleSession);
+ logger.error("Apply Table Rule Session: RuleDescriptionData is null: "
+ + applyTableRuleSession);
throw new TDGWTServiceException(
"Error in apply rule on table: rule description is null");
}
if (applyTableRuleSession.getPlaceHolderToColumnMap() == null) {
- logger.error("Apply Table Rule Session: PlaceHolderToColumnMap is null: "+applyTableRuleSession);
+ logger.error("Apply Table Rule Session: PlaceHolderToColumnMap is null: "
+ + applyTableRuleSession);
throw new TDGWTServiceException(
"Error in apply rule on table: map is null");
}
-
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
@@ -9492,10 +9504,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceLocked(tabularResource);
checkTabularResourceIsFinal(tabularResource);
-
RuleId ruleId = new RuleId(applyTableRuleSession
.getRuleDescriptionData().getId());
-
+
Task trTask = service.applyTableRule(tabularResourceId,
applyTableRuleSession.getPlaceHolderToColumnMap(), ruleId);
logger.debug("Rules On Table Apply: TaskId " + trTask.getId());
diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/social/TDMNotifications.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/social/TDMNotifications.java
new file mode 100644
index 0000000..dbeb6f8
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/social/TDMNotifications.java
@@ -0,0 +1,261 @@
+package org.gcube.portlets.user.td.gwtservice.server.social;
+
+import java.util.List;
+
+import org.gcube.application.framework.core.session.ASLSession;
+import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
+import org.gcube.applicationsupportlayer.social.NotificationsManager;
+import org.gcube.common.homelibrary.util.WorkspaceUtil;
+import org.gcube.portal.databook.shared.NotificationType;
+import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
+import org.gcube.portlets.user.td.gwtservice.shared.share.ShareRule;
+import org.gcube.portlets.user.td.gwtservice.shared.share.ShareTabResource;
+import org.gcube.portlets.user.td.gwtservice.shared.share.ShareTemplate;
+import org.gcube.portlets.user.td.widgetcommonevent.shared.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TDMNotification notification sharing TR, templates or rules
+ *
+ * @author giancarlo email: g.panichi@isti.cnr.it
+ *
+ */
+public class TDMNotifications extends Thread {
+ private static Logger logger = LoggerFactory
+ .getLogger(TDMNotifications.class);
+ private ASLSession aslSession;
+ private NotificationType notificationType;
+ private ShareTabResource shareTabularResource;
+ private ShareRule shareRule;
+ private ShareTemplate shareTemplate;
+
+ /**
+ * Share Tabular Resource
+ *
+ * @param aslSession
+ * @param shareTabularResource
+ */
+ public TDMNotifications(ASLSession aslSession,
+ ShareTabResource shareTabularResource) {
+ this.aslSession = aslSession;
+ this.shareTabularResource = shareTabularResource;
+ this.notificationType = NotificationType.TDM_TAB_RESOURCE_SHARE;
+
+ }
+
+ /**
+ *
+ * @param aslSession
+ * @param shareRule
+ */
+ public TDMNotifications(ASLSession aslSession, ShareRule shareRule) {
+ this.aslSession = aslSession;
+ this.shareRule = shareRule;
+ this.notificationType = NotificationType.TDM_RULE_SHARE;
+
+ }
+
+ /**
+ *
+ * @param aslSession
+ * @param shareTemplate
+ */
+ public TDMNotifications(ASLSession aslSession, ShareTemplate shareTemplate) {
+ this.aslSession = aslSession;
+ this.shareTemplate = shareTemplate;
+ this.notificationType = NotificationType.TDM_TEMPLATE_SHARE;
+
+ }
+
+ public void run() {
+ switch (notificationType) {
+ case TDM_TAB_RESOURCE_SHARE:
+ tabularResourceNotify();
+ break;
+ case TDM_TEMPLATE_SHARE:
+ templateNotify();
+ break;
+ case TDM_RULE_SHARE:
+ ruleNotify();
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ private void tabularResourceNotify() {
+ NotificationsManager nm = new ApplicationNotificationsManager(
+ aslSession, Constants.APPLICATION_ID);
+
+ for (Contacts contact : shareTabularResource.getContacts()) {
+ if (contact.isGroup()) {
+ try {
+ List members = WorkspaceUtil
+ .getMembersByGroup(contact.getLogin());
+ for (String member : members) {
+ try {
+ nm.notifyTDMTabularResourceSharing(member,
+ shareTabularResource.getTabResource()
+ .getName(), new String(
+ Constants.TABULAR_RESOURCE_ID
+ + "="
+ + shareTabularResource
+ .getTabResource()
+ .getTrId().getId()));
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername()
+ + " share tabular resource id="
+ + shareTabularResource.getTabResource()
+ .getTrId().getId() + " with "
+ + member + "): " + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+ }
+
+ } catch (Exception e) {
+ logger.error("Error in the notification(No members found for group "
+ + contact.getLogin()
+ + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ } else {
+ try {
+ nm.notifyTDMTabularResourceSharing(contact.getLogin(),
+ shareTabularResource.getTabResource().getName(),
+ new String(Constants.TABULAR_RESOURCE_ID
+ + "="
+ + shareTabularResource.getTabResource()
+ .getTrId().getId()));
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername()
+ + " share tabular resource id="
+ + shareTabularResource.getTabResource().getTrId()
+ .getId() + " with " + contact.getLogin()
+ + "): " + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ }
+ }
+ }
+
+ private void ruleNotify() {
+ NotificationsManager nm = new ApplicationNotificationsManager(
+ aslSession, Constants.APPLICATION_ID);
+
+ for (Contacts contact : shareRule.getContacts()) {
+ if (contact.isGroup()) {
+
+ try {
+ List members = WorkspaceUtil
+ .getMembersByGroup(contact.getLogin());
+ for (String member : members) {
+ try {
+ nm.notifyTDMObjectSharing(member, notificationType,
+ shareRule.getRuleDescriptionData()
+ .getName(), null);
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername()
+ + " share rule id="
+ + shareRule.getRuleDescriptionData()
+ .getId() + " with " + member
+ + "): " + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+ }
+
+ } catch (Exception e) {
+ logger.error("Error in the notification(No members found for group "
+ + contact.getLogin()
+ + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ } else {
+ try {
+ nm.notifyTDMObjectSharing(contact.getLogin(),
+ notificationType, shareRule
+ .getRuleDescriptionData().getName(), null);
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername() + " share rule id="
+ + shareRule.getRuleDescriptionData().getId()
+ + " with " + contact.getLogin() + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ }
+
+ private void templateNotify() {
+ NotificationsManager nm = new ApplicationNotificationsManager(
+ aslSession, Constants.APPLICATION_ID);
+
+ for (Contacts contact : shareTemplate.getContacts()) {
+ if (contact.isGroup()) {
+
+ try {
+ List members = WorkspaceUtil
+ .getMembersByGroup(contact.getLogin());
+ for (String member : members) {
+ try {
+ nm.notifyTDMObjectSharing(member, notificationType,
+ shareTemplate.getTemplateData().getName(),
+ null);
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername()
+ + " share template id="
+ + shareTemplate.getTemplateData().getId()
+ + " with " + member + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+ }
+
+ } catch (Exception e) {
+ logger.error("Error in the notification(No members found for group "
+ + contact.getLogin()
+ + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ } else {
+ try {
+ nm.notifyTDMObjectSharing(contact.getLogin(),
+ notificationType, shareTemplate.getTemplateData()
+ .getName(), null);
+
+ } catch (Exception e) {
+ logger.error("Error in the notification("
+ + aslSession.getUsername() + " share template id="
+ + shareTemplate.getTemplateData().getId()
+ + " with " + contact.getLogin() + "): "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java
index 130a3bc..abffefa 100644
--- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java
+++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java
@@ -3,7 +3,6 @@
*/
package org.gcube.portlets.user.td.gwtservice.shared;
-
/**
*
* @author "Giancarlo Panichi"
- * FieldVerifier validates that the name the user enters is valid.
- *
- *
- * This class is in the shared
packing because we use it in both
- * the client code and on the server. On the client, we verify that the name is
- * valid before sending an RPC request so the user doesn't have to wait for a
- * network round trip to get feedback. On the server, we verify that the name is
- * correct to ensure that the input is correct regardless of where the RPC
- * originates.
- *
- *
- * When creating a class that is used on both the client and the server, be sure
- * that all code is translatable and does not use native JavaScript. Code that
- * is note translatable (such as code that interacts with a database or the file
- * system) cannot be compiled into client side JavaScript. Code that uses native
- * JavaScript (such as Widgets) cannot be run on the server.
- *
- */
-public class FieldVerifier {
-
- /**
- * Verifies that the specified name is valid for our service.
- *
- * In this example, we only require that the name is at least four
- * characters. In your application, you can use more complex checks to ensure
- * that usernames, passwords, email addresses, URLs, and other fields have the
- * proper syntax.
- *
- * @param name the name to validate
- * @return true if valid, false if invalid
- */
- public static boolean isValidName(String name) {
- if (name == null) {
- return false;
- }
- return name.length() > 3;
- }
-}