2013-01-10 14:19:53 +01:00
package org.gcube.portal.databook.shared ;
2023-10-28 01:38:25 +02:00
import com.datastax.oss.driver.api.core.cql.Row ;
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException ;
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException ;
2013-01-10 14:19:53 +01:00
import java.io.Serializable ;
import java.util.Date ;
2023-10-28 01:38:25 +02:00
import java.util.Objects ;
import static org.gcube.portal.databook.server.Schema.* ;
2013-01-10 14:19:53 +01:00
/ * *
*
* @author Massimiliano Assante , ISTI - CNR
*
* /
@SuppressWarnings ( " serial " )
public class Notification implements Serializable {
private String key ;
private NotificationType type ;
private String userid ;
private String subjectid ;
private Date time ;
private String uri ;
private String description ;
private boolean read ;
private String senderid ;
private String senderFullName ;
private String senderThumbnail ;
2023-10-28 01:38:25 +02:00
public static NotificationChannelType getChannelType ( String channelName ) throws NotificationChannelTypeNotFoundException {
if ( channelName . compareTo ( " PORTAL " ) = = 0 )
return NotificationChannelType . PORTAL ;
else if ( channelName . compareTo ( " EMAIL " ) = = 0 )
return NotificationChannelType . EMAIL ;
else if ( channelName . compareTo ( " TWITTER " ) = = 0 )
return NotificationChannelType . TWITTER ;
else
throw new NotificationChannelTypeNotFoundException ( " The Notification Channel Type was not recognized should be one of " + NotificationChannelType . values ( ) + " asked for: " + channelName ) ;
}
/ * *
* simply return an enum representing the feed type
* @param type .
* @return correct enum representing the feed type
* @throws NotificationTypeNotFoundException .
* /
public static NotificationType getNotificationType ( String type ) throws NotificationTypeNotFoundException {
if ( type . compareTo ( " WP_FOLDER_SHARE " ) = = 0 ) {
return NotificationType . WP_FOLDER_SHARE ;
}
else if ( type . compareTo ( " WP_FOLDER_UNSHARE " ) = = 0 ) {
return NotificationType . WP_FOLDER_UNSHARE ;
}
else if ( type . compareTo ( " WP_ADMIN_UPGRADE " ) = = 0 ) {
return NotificationType . WP_ADMIN_UPGRADE ;
}
else if ( type . compareTo ( " WP_ADMIN_DOWNGRADE " ) = = 0 ) {
return NotificationType . WP_ADMIN_DOWNGRADE ;
}
else if ( type . compareTo ( " WP_FOLDER_RENAMED " ) = = 0 ) {
return NotificationType . WP_FOLDER_RENAMED ;
}
else if ( type . compareTo ( " WP_FOLDER_ADDEDUSER " ) = = 0 ) {
return NotificationType . WP_FOLDER_ADDEDUSER ;
}
else if ( type . compareTo ( " WP_FOLDER_REMOVEDUSER " ) = = 0 ) {
return NotificationType . WP_FOLDER_REMOVEDUSER ;
}
else if ( type . compareTo ( " WP_ITEM_DELETE " ) = = 0 ) {
return NotificationType . WP_ITEM_DELETE ;
}
else if ( type . compareTo ( " WP_ITEM_UPDATED " ) = = 0 ) {
return NotificationType . WP_ITEM_UPDATED ;
}
else if ( type . compareTo ( " WP_ITEM_NEW " ) = = 0 ) {
return NotificationType . WP_ITEM_NEW ;
}
else if ( type . compareTo ( " WP_ITEM_RENAMED " ) = = 0 ) {
return NotificationType . WP_ITEM_RENAMED ;
}
else if ( type . compareTo ( " OWN_COMMENT " ) = = 0 ) {
return NotificationType . OWN_COMMENT ;
}
else if ( type . compareTo ( " COMMENT " ) = = 0 ) {
return NotificationType . COMMENT ;
}
else if ( type . compareTo ( " MENTION " ) = = 0 ) {
return NotificationType . MENTION ;
}
else if ( type . compareTo ( " LIKE " ) = = 0 ) {
return NotificationType . LIKE ;
}
else if ( type . compareTo ( " CALENDAR_ADDED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_ADDED_EVENT ;
}
else if ( type . compareTo ( " CALENDAR_UPDATED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_UPDATED_EVENT ;
}
else if ( type . compareTo ( " CALENDAR_DELETED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_DELETED_EVENT ;
}
else if ( type . compareTo ( " CALENDAR_ADDED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_ADDED_EVENT ;
}
else if ( type . compareTo ( " CALENDAR_UPDATED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_UPDATED_EVENT ;
}
else if ( type . compareTo ( " CALENDAR_DELETED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_DELETED_EVENT ;
}
else if ( type . compareTo ( " MESSAGE " ) = = 0 ) {
return NotificationType . MESSAGE ;
}
else if ( type . compareTo ( " POST_ALERT " ) = = 0 ) {
return NotificationType . POST_ALERT ;
}
else if ( type . compareTo ( " REQUEST_CONNECTION " ) = = 0 ) {
return NotificationType . REQUEST_CONNECTION ;
}
else if ( type . compareTo ( " JOB_COMPLETED_NOK " ) = = 0 ) {
return NotificationType . JOB_COMPLETED_NOK ;
}
else if ( type . compareTo ( " JOB_COMPLETED_OK " ) = = 0 ) {
return NotificationType . JOB_COMPLETED_OK ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_EDIT " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_EDIT ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_VIEW " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_VIEW ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_STEP_FORWARD_PEER " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_STEP_FORWARD_PEER ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_STEP_REQUEST_TASK " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_STEP_REQUEST_TASK ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER ;
}
else if ( type . compareTo ( " DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT " ) = = 0 ) {
return NotificationType . DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT ;
}
else if ( type . compareTo ( " TDM_TAB_RESOURCE_SHARE " ) = = 0 ) {
return NotificationType . TDM_TAB_RESOURCE_SHARE ;
}
else if ( type . compareTo ( " TDM_RULE_SHARE " ) = = 0 ) {
return NotificationType . TDM_RULE_SHARE ;
}
else if ( type . compareTo ( " TDM_TEMPLATE_SHARE " ) = = 0 ) {
return NotificationType . TDM_TEMPLATE_SHARE ;
}
else if ( type . compareTo ( " CAT_ITEM_SUBMITTED " ) = = 0 ) {
return NotificationType . CAT_ITEM_SUBMITTED ;
}
else if ( type . compareTo ( " CAT_ITEM_REJECTED " ) = = 0 ) {
return NotificationType . CAT_ITEM_REJECTED ;
}
else if ( type . compareTo ( " CAT_ITEM_PUBLISHED " ) = = 0 ) {
return NotificationType . CAT_ITEM_PUBLISHED ;
}
else if ( type . compareTo ( " CAT_ITEM_UPDATED " ) = = 0 ) {
return NotificationType . CAT_ITEM_UPDATED ;
}
else if ( type . compareTo ( " CAT_ITEM_DELETE " ) = = 0 ) {
return NotificationType . CAT_ITEM_DELETE ;
}
else if ( type . compareTo ( " GENERIC " ) = = 0 ) {
return NotificationType . GENERIC ;
}
else
throw new NotificationTypeNotFoundException ( " The Notification Type was not recognized should be one of " + NotificationType . values ( ) + " asked for: " + type ) ;
}
2013-01-10 14:19:53 +01:00
/ * *
* default constructor
* /
public Notification ( ) {
super ( ) ;
}
/ * *
*
* @param key
* @param type
* @param userid
* @param subjectid the subject id of this notification , if is a like on a feed then is the feedid , it is a message then is the messageid and so on
* @param time
* @param uri
* @param description
* @param read
* @param senderid
* @param senderFullName
* @param senderThumbnail
* /
public Notification ( String key , NotificationType type , String userid ,
String subjectid , Date time , String uri , String description ,
boolean read , String senderid , String senderFullName ,
String senderThumbnail ) {
super ( ) ;
this . key = key ;
this . type = type ;
this . userid = userid ;
this . subjectid = subjectid ;
this . time = time ;
this . uri = uri ;
this . description = description ;
this . read = read ;
this . senderid = senderid ;
this . senderFullName = senderFullName ;
this . senderThumbnail = senderThumbnail ;
}
2023-10-28 01:38:25 +02:00
public Notification ( Row record ) throws NotificationTypeNotFoundException {
2016-02-17 17:46:43 +01:00
super ( ) ;
2023-10-28 01:38:25 +02:00
this . key = Objects . requireNonNull ( record . getUuid ( NOT_ID ) ) . toString ( ) ;
this . type = getNotificationType ( Objects . requireNonNull ( record . getString ( TYPE ) ) ) ;
this . userid = record . getString ( USER_ID ) ;
this . subjectid = record . getString ( SUBJECT_ID ) ;
this . time = Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ;
this . uri = record . getString ( URI ) ;
this . description = record . getString ( DESCRIPTION ) ;
this . read = record . getBoolean ( IS_READ ) ;
this . senderid = record . getString ( SENDER_ID ) ;
this . senderFullName = record . getString ( SENDER_FULL_NAME ) ;
this . senderThumbnail = record . getString ( SENDER_THUMBNAIL_URL ) ;
2016-02-17 17:46:43 +01:00
}
2013-01-10 14:19:53 +01:00
/ * *
*
* @return .
* /
public String getKey ( ) {
return key ;
}
public void setKey ( String key ) {
this . key = key ;
}
public NotificationType getType ( ) {
return type ;
}
public void setType ( NotificationType type ) {
this . type = type ;
}
public String getUserid ( ) {
return userid ;
}
public void setUserid ( String userid ) {
this . userid = userid ;
}
public Date getTime ( ) {
return time ;
}
public void setTime ( Date time ) {
this . time = time ;
}
public String getUri ( ) {
return uri ;
}
public void setUri ( String uri ) {
this . uri = uri ;
}
public String getDescription ( ) {
return description ;
}
public void setDescription ( String description ) {
this . description = description ;
}
public boolean isRead ( ) {
return read ;
}
public void setRead ( boolean read ) {
this . read = read ;
}
public String getSenderid ( ) {
return senderid ;
}
public void setSenderid ( String senderid ) {
this . senderid = senderid ;
}
public String getSenderFullName ( ) {
return senderFullName ;
}
public void setSenderFullName ( String senderFullName ) {
this . senderFullName = senderFullName ;
}
public String getSenderThumbnail ( ) {
return senderThumbnail ;
}
public void setSenderThumbnail ( String senderThumbnail ) {
this . senderThumbnail = senderThumbnail ;
}
public String getSubjectid ( ) {
return subjectid ;
}
public void setSubjectid ( String subjectid ) {
this . subjectid = subjectid ;
}
@Override
public String toString ( ) {
return " Notification [key= " + key + " , type= " + type + " , userid= "
+ userid + " , subjectid= " + subjectid + " , time= " + time
+ " , uri= " + uri + " , description= " + description + " , read= "
+ read + " , senderid= " + senderid + " , senderFullName= "
2016-02-17 17:46:43 +01:00
+ senderFullName + " , senderThumbnail= " + senderThumbnail
2023-10-28 01:38:25 +02:00
+ " ] " ;
2016-02-17 17:46:43 +01:00
}
2013-01-10 14:19:53 +01:00
}