197: Tabular Data Manager Portlet to Share News and Notifications to its Users

Task-Url: https://support.d4science.org/issues/197

Added Notifications

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@115327 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-06-11 14:43:08 +00:00
parent cf82fe42ae
commit 171cf27782
5 changed files with 346 additions and 106 deletions

28
pom.xml
View File

@ -122,11 +122,28 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<!-- Social -->
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
<scope>provided</scope>
</dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
@ -204,14 +221,9 @@
<scope>provided</scope>
</dependency>
<!-- Tika
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.7</version>
</dependency>
-->
<!-- Tika <dependency> <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId>
<version>1.7</version> </dependency> -->
<!-- LOGGING -->
<dependency>

View File

@ -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());

View File

@ -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: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<String> 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<String> 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<String> 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();
}
}
}
}
}

View File

@ -3,7 +3,6 @@
*/
package org.gcube.portlets.user.td.gwtservice.shared;
/**
*
* @author "Giancarlo Panichi" <a
@ -12,27 +11,26 @@ package org.gcube.portlets.user.td.gwtservice.shared;
*/
public class Constants {
public final static String VERSION = "2.6.0";
public final static String DEFAULT_USER = "test.user";
public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
public final static String FILE_XML_MIMETYPE="application/xml";
public final static String FILE_CSV_MIMETYPE="text/csv";
public final static String FILE_XML_MIMETYPE = "application/xml";
public final static String FILE_CSV_MIMETYPE = "text/csv";
public static final String PARAMETER_ENCODING = "encoding";
public static final String PARAMETER_HASHEADER = "hasHeader";
public static final String PARAMETER_FIELDMASK = "fieldMask";
public static final String PARAMETER_SKIPERROR = "skipError";
public static final String PARAMETER_SEPARATOR = "separator";
public static final String PARAMETER_VIEW_COLUMNS ="useView";
public static final String PARAMETER_VIEW_COLUMNS = "useView";
public static final String PARAMETER_COLUMNS = "columns";
public static final String PARAMETER_URL = "url";
public static final String PARAMETER_ID = "id";
public static final String PARAMETER_REGISTRYBASEURL = "registryBaseUrl";
public static final String PARAMETER_AGENCY = "agency";
public static final String PARAMETER_VERSION = "version";
public static final String PARAMETER_DATA_TYPE = "dataType";
public static final String PARAMETER_TARGET_DATA_TYPE = "targetDataType";
public static final String PARAMETER_ADDITIONAL_META = "additionalMeta";
@ -42,23 +40,23 @@ public class Constants {
public static final String PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION = "condition";
public static final String PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE = "value";
public static final String PARAMETER_UNION_COMPOSITE_SOURCE = "source";
public static final String PARAMETER_UNION_COMPOSITE_TARGET = "target";
public static final String PARAMETER_UNION_COMPOSITE = "mappings";
public static final String PARAMETER_STATISTICAL_OPERATION_USER = "user";
public static final String PARAMETER_STATISTICAL_OPERATION_ALGORITHM = "algorithm";
public static final String PARAMETER_STATISTICAL_OPERATION_PARAMETERS = "smEntries";
public static final String PARAMETER_STATISTICAL_OPERATION_DESCRIPTION = "description";
public static final String PARAMETER_STATISTICAL_OPERATION_TITLE = "title";
public static final String PARAMETER_STATISTICAL_OPERATION_TITLE = "title";
public static final String PARAMETER_ADD_ROW_COMPOSITE_FIELD = "field";
public static final String PARAMETER_ADD_ROW_COMPOSITE_TOSETVALUE = "toSetValue";
public static final String PARAMETER_ADD_ROW_COMPOSITE = "mapping";
public static final String PARAMETER_IMPORT_CODELIST_MAPPING_OLDCODES = "old_codes";
public static final String PARAMETER_EXTRACT_CODELIST_SOURCE = "source";
public static final String PARAMETER_EXTRACT_CODELIST_TARGET_CODE_COLUMN = "target_code_column";
public static final String PARAMETER_EXTRACT_CODELIST_COLUMN_DEFINITION = "column_definition";
@ -83,35 +81,35 @@ public class Constants {
public static final String PARAMETER_TABLE_TYPE = "tableType";
public static final String PARAMETER_ROW_ID = "rowId";
public static final String PARAMETER_ADD_COLUMN_COLUMN_TYPE = "columnType";
public static final String PARAMETER_ADD_COLUMN_LABEL = "label";
public static final String PARAMETER_ADD_COLUMN_DATA_TYPE = "dataType";
public static final String PARAMETER_ADD_COLUMN_VALUE = "value";
public static final String PARAMETER_ADD_COLUMN_META = "meta";
public static final String PARAMETER_NORMALIZATION_TO_NORMALIZE = "to_normalize";
public static final String PARAMETER_NORMALIZATION_NORM_LABEL = "norm_label";
public static final String PARAMETER_NORMALIZATION_QUANT_LABEL = "quant_label";
public static final String PARAMETER_DENORMALIZATION_VALUE_COLUMN = "value_column";
public static final String PARAMETER_DENORMALIZATION_ATTRIBUTE_COLUMN = "attribute_column";
public static final String PARAMETER_CLONE_TABLE = "table";
public static final String PARAMETER_GENERATEMAP_MAPNAME = "mapName";
public static final String PARAMETER_GENERATEMAP_FEATURE = "feature";
public static final String PARAMETER_GENERATEMAP_GEOM = "geom";
public static final String PARAMETER_GENERATEMAP_FEATURE = "feature";
public static final String PARAMETER_GENERATEMAP_GEOM = "geom";
public static final String PARAMETER_GENERATEMAP_USEVIEW = "useView";
public static final String PARAMETER_GENERATEMAP_METAABSTRACT = "metaAbstract";
public static final String PARAMETER_GENERATEMAP_METAPURPOSE = "metaPurpose";
public static final String PARAMETER_GENERATEMAP_USER = "User";
public static final String PARAMETER_GENERATEMAP_METACREDITS = "metaCredits";
public static final String PARAMETER_GENERATEMAP_METAKEYWORDS = "metaKeywords";
public static final String PARAMETER_GENERATEMAP_METAABSTRACT = "metaAbstract";
public static final String PARAMETER_GENERATEMAP_METAPURPOSE = "metaPurpose";
public static final String PARAMETER_GENERATEMAP_USER = "User";
public static final String PARAMETER_GENERATEMAP_METACREDITS = "metaCredits";
public static final String PARAMETER_GENERATEMAP_METAKEYWORDS = "metaKeywords";
public static final String PARAMETER_CHART_TOPRATING_SAMPLESIZE = "sampleSize";
public static final String PARAMETER_CHART_TOPRATING_VALUEOPERATION = "valueOperation";
public static final String PARAMETER_GEOSPATIAL_CREATE_COORDINATES_LATITUDE = "latitude";
public static final String PARAMETER_GEOSPATIAL_CREATE_COORDINATES_LONGITUDE = "longitude";
public static final String PARAMETER_GEOSPATIAL_CREATE_COORDINATES_FEATURE = "feature";
@ -124,7 +122,7 @@ public class Constants {
public static final String PARAMETER_EXPRESSION_VALIDATION_EXPRESSION = "expression";
public static final String PARAMETER_EXPRESSION_VALIDATION_DESCRIPTION = "description";
public static final String PARAMETER_EXPRESSION_VALIDATION_TITLE = "title";
public static final String PARAMETER_CHANGE_COLUMN_POSITION_ORDER = "order";
}

View File

@ -1,42 +0,0 @@
package org.gcube.portlets.user.td.gwtservice.shared;
/**
* <p>
* FieldVerifier validates that the name the user enters is valid.
* </p>
* <p>
* This class is in the <code>shared</code> 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.
* </p>
* <p>
* 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.
* </p>
*/
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;
}
}