Fixed bug returning sendNotification false when a Notification Preference was null for a given Notification Type

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@95317 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-05-05 14:26:18 +00:00
parent a96221d129
commit 750b9b0d4e
6 changed files with 3227 additions and 21 deletions

View File

@ -19,7 +19,7 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

File diff suppressed because it is too large Load Diff

View File

@ -26,4 +26,7 @@
<Change>Added support for notifications retrieval by range</Change> <Change>Added support for notifications retrieval by range</Change>
<Change>Added support for unlike feature</Change> <Change>Added support for unlike feature</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portal.social-networking-library.1-6-1" date="2014-05-05">
<Change>Fixed bug returning sendNotification false when a Notification Preference was null for a given Notification Type</Change>
</Changeset>
</ReleaseNotes> </ReleaseNotes>

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>
<version>1.6.0-SNAPSHOT</version> <version>1.6.1-SNAPSHOT</version>
<name>gCube Social Networking Library</name> <name>gCube Social Networking Library</name>
<description> <description>
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities. The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.

View File

@ -641,20 +641,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
ArrayList<Feed> feedsToReturn = new ArrayList<Feed>(); ArrayList<Feed> feedsToReturn = new ArrayList<Feed>();
ArrayList<String> feedIDs = getVREFeedIds(vreid); ArrayList<String> feedIDs = getVREFeedIds(vreid);
//if from is greater than feeds size return empty //if from is greater than feeds size return empty
if (from >= feedIDs.size()) { if (from >= feedIDs.size()) {
_log.warn("The starting point of the range is greather than the total number of feeds for this timeline: " + from + " >= " + feedIDs.size()); _log.warn("The starting point of the range is greather than the total number of feeds for this timeline: " + from + " >= " + feedIDs.size());
return new RangeFeeds(); return new RangeFeeds();
} }
int rangeStart = feedIDs.size()-from; int rangeStart = feedIDs.size()-from;
int rangeEnd = rangeStart-quantity; int rangeEnd = rangeStart-quantity;
//check that you reached the end //check that you reached the end
if (rangeEnd<1) if (rangeEnd<1)
rangeEnd = 0; rangeEnd = 0;
_log.debug("BEFORE starting Point=" + rangeStart + " rangeEnd= " + rangeEnd); _log.debug("BEFORE starting Point=" + rangeStart + " rangeEnd= " + rangeEnd);
//need them in reverse order //need them in reverse order
int howMany = from; int howMany = from;
@ -885,20 +885,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
ArrayList<Notification> toReturn = new ArrayList<Notification>(); ArrayList<Notification> toReturn = new ArrayList<Notification>();
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid); ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
//if from is greater than feeds size return empty //if from is greater than feeds size return empty
if (from >= notificationsIDs.size()) { if (from >= notificationsIDs.size()) {
_log.warn("The starting point of the range is greather than the total number of feeds for this timeline: " + from + " >= " + notificationsIDs.size()); _log.warn("The starting point of the range is greather than the total number of feeds for this timeline: " + from + " >= " + notificationsIDs.size());
return new ArrayList<Notification>(); return new ArrayList<Notification>();
} }
int rangeStart = notificationsIDs.size()-from; int rangeStart = notificationsIDs.size()-from;
int rangeEnd = rangeStart-quantity; int rangeEnd = rangeStart-quantity;
//check that you reached the end //check that you reached the end
if (rangeEnd<1) if (rangeEnd<1)
rangeEnd = 0; rangeEnd = 0;
_log.debug("BEFORE starting Point=" + rangeStart + " rangeEnd= " + rangeEnd); _log.debug("BEFORE starting Point=" + rangeStart + " rangeEnd= " + rangeEnd);
//need them in reverse order //need them in reverse order
for (int i = rangeStart; i > rangeEnd; i--) { for (int i = rangeStart; i > rangeEnd; i--) {
@ -994,7 +994,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (toProcess == null) { if (toProcess == null) {
_log.warn("Single Notification preference of " + userid + " Type: " + notificationType + " not existing ... creating default"); _log.warn("Single Notification preference of " + userid + " Type: " + notificationType + " not existing ... creating default");
return createNewNotificationType(userid, notificationType); return createNewNotificationType(userid, notificationType);
} else }
else if (toProcess.length == 0)
return toReturn;
else
for (int i = 0; i < toProcess.length; i++) { for (int i = 0; i < toProcess.length; i++) {
toReturn.add(toProcess[i]); toReturn.add(toProcess[i]);
} }
@ -1009,7 +1012,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
MutationBatch m = conn.getKeyspace().prepareMutationBatch(); MutationBatch m = conn.getKeyspace().prepareMutationBatch();
String valueToInsert = ""; String valueToInsert = "";
NotificationChannelType[] wpTypes = NotificationChannelType.values(); NotificationChannelType[] wpTypes = NotificationChannelType.values();
for (int i = 0; i < wpTypes.length; i++) { for (int i = 0; i < wpTypes.length; i++) {
valueToInsert += wpTypes[i]; valueToInsert += wpTypes[i];
if (i < wpTypes.length-1) if (i < wpTypes.length-1)
@ -1094,13 +1097,17 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
for (Row<String, String> row : result.getResult()) for (Row<String, String> row : result.getResult())
for (Column<String> column : row.getColumns()) { for (Column<String> column : row.getColumns()) {
String[] channels = column.getStringValue().split(","); String[] channels = column.getStringValue().split(",");
NotificationChannelType[] toAdd = new NotificationChannelType[channels.length]; if (channels != null && channels.length == 1 && channels[0].toString().equals("") ) { //it is empty, preference is set to no notification at all
for (int i = 0; i < channels.length; i++) { toReturn.put(getNotificationType(column.getName()), new NotificationChannelType[0]);
if (channels[i].compareTo("") != 0) } else {
toAdd[i] = (getChannelType(channels[i])); NotificationChannelType[] toAdd = new NotificationChannelType[channels.length];
for (int i = 0; i < channels.length; i++) {
if (channels[i].compareTo("") != 0) {
toAdd[i] = (getChannelType(channels[i]));
}
}
toReturn.put(getNotificationType(column.getName()), toAdd);
} }
toReturn.put(getNotificationType(column.getName()), toAdd);
} }
} }
return toReturn; return toReturn;
@ -1297,8 +1304,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
m.withRow(cf_Likes, likeid).delete(); m.withRow(cf_Likes, likeid).delete();
//delete the column from UserLikes //delete the column from UserLikes
m.withRow(cf_UserLikedFeeds, userid).deleteColumn(likeid); m.withRow(cf_UserLikedFeeds, userid).deleteColumn(likeid);
try { try {
m.execute(); m.execute();

View File

@ -242,7 +242,7 @@ public interface DatabookStore {
*/ */
List<NotificationChannelType> getUserNotificationChannels(String userid, NotificationType notificationType) throws NotificationChannelTypeNotFoundException, NotificationTypeNotFoundException; List<NotificationChannelType> getUserNotificationChannels(String userid, NotificationType notificationType) throws NotificationChannelTypeNotFoundException, NotificationTypeNotFoundException;
/** /**
* set the notification preferences map (enableor disable the channels to be used for notifying the user) * set the notification preferences map (enable or disable the channels to be used for notifying the user)
* @param userid user identifier * @param userid user identifier
* @param notificationType the type of the notification * @param notificationType the type of the notification
* @param enabledChannels a map of the channels to which reach the user per notification, empty array or null values to set the key notification type off * @param enabledChannels a map of the channels to which reach the user per notification, empty array or null values to set the key notification type off