User Notifications Read now resilient to indices error, see #840
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@119270 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d8948a8580
commit
1dcc8a1478
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
<version>1.8.0-SNAPSHOT</version>
|
||||
<version>1.8.1-SNAPSHOT</version>
|
||||
<name>gCube Social Networking Library</name>
|
||||
<description>
|
||||
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.
|
||||
|
|
|
@ -912,7 +912,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<Notification> getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException {
|
||||
public List<Notification> getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
|
||||
ArrayList<Notification> toReturn = new ArrayList<Notification>();
|
||||
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
|
||||
//check if quantity is greater than user feeds
|
||||
|
@ -920,8 +920,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
|
||||
//need them in reverse order
|
||||
for (int i = notificationsIDs.size()-1; i >= (notificationsIDs.size()-limit); i--) {
|
||||
Notification toAdd = readNotification(notificationsIDs.get(i));
|
||||
toReturn.add(toAdd);
|
||||
Notification toAdd = null;
|
||||
try {
|
||||
toAdd = readNotification(notificationsIDs.get(i));
|
||||
toReturn.add(toAdd);
|
||||
} catch (NotificationIDNotFoundException e) {
|
||||
_log.error("Notification not found id=" + notificationsIDs.get(i));
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
@ -979,18 +984,23 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setAllNotificationReadByUser(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException {
|
||||
public boolean setAllNotificationReadByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
|
||||
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
|
||||
|
||||
//need them in reverse order
|
||||
for (int i = notificationsIDs.size()-1; i >= 0; i--) {
|
||||
Notification toAdd = readNotification(notificationsIDs.get(i));
|
||||
if ((!toAdd.isRead()) && (toAdd.getType() != NotificationType.MESSAGE) ) { //while I encounter unread notifications keep putting them to read, else exit
|
||||
setNotificationRead(toAdd.getKey());
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
Notification toAdd;
|
||||
try {
|
||||
toAdd = readNotification(notificationsIDs.get(i));
|
||||
if ((!toAdd.isRead()) && (toAdd.getType() != NotificationType.MESSAGE) ) { //while I encounter unread notifications keep putting them to read, else exit
|
||||
setNotificationRead(toAdd.getKey());
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} catch (NotificationIDNotFoundException e) {
|
||||
_log.error("Could not set read notification with id =" + notificationsIDs.get(i));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1016,16 +1026,22 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUnreadNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException {
|
||||
public boolean checkUnreadNotifications(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
|
||||
ArrayList<String> notificationsIDs = getUserNotificationsIds(userid);
|
||||
//since #readNotification costs time and newer notifications are iterarate first (with the reverse for below)
|
||||
//i just see if the first non message notification (UserNotifications TimeLine) is read or not and return the value instead of iterating them one by one looking for unread()
|
||||
|
||||
//need them in reverse order
|
||||
for (int i = notificationsIDs.size()-1; i >= 0; i--) {
|
||||
Notification toAdd = readNotification(notificationsIDs.get(i));
|
||||
if (toAdd.getType() != NotificationType.MESSAGE)
|
||||
return ! toAdd.isRead();
|
||||
Notification toAdd;
|
||||
try {
|
||||
toAdd = readNotification(notificationsIDs.get(i));
|
||||
if (toAdd.getType() != NotificationType.MESSAGE)
|
||||
return ! toAdd.isRead();
|
||||
} catch (NotificationIDNotFoundException e) {
|
||||
_log.error("Notification not found with id = " + notificationsIDs.get(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue