2013-01-10 14:19:53 +01:00
package org.gcube.portal.databook.server ;
2023-10-30 18:52:02 +01:00
import java.time.Instant ;
import java.util.* ;
import java.util.stream.Collectors ;
2013-01-10 14:19:53 +01:00
2015-06-25 18:25:37 +02:00
import javax.mail.internet.AddressException ;
import javax.mail.internet.InternetAddress ;
2023-10-30 18:52:02 +01:00
import com.datastax.oss.driver.api.core.CqlSession ;
import com.datastax.oss.driver.api.core.cql.* ;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder ;
2013-01-10 14:19:53 +01:00
import org.apache.commons.lang.NullArgumentException ;
2023-10-30 18:52:02 +01:00
import org.gcube.portal.databook.shared.* ;
import org.gcube.portal.databook.shared.ex.* ;
2013-09-25 15:42:08 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2013-01-10 14:19:53 +01:00
2023-10-30 18:52:02 +01:00
import static org.gcube.portal.databook.server.CassandraClusterConnection.closeSession ;
import static org.gcube.portal.databook.server.Schema.* ;
2013-01-10 14:19:53 +01:00
/ * *
* @author Massimiliano Assante ISTI - CNR
2016-08-02 17:25:27 +02:00
* @author Costantino Perciante ISTI - CNR
2013-01-10 14:19:53 +01:00
* This class is used for querying and adding data to Cassandra via Astyanax High Level API
* /
public final class DBCassandraAstyanaxImpl implements DatabookStore {
/ * *
* logger
* /
2013-09-25 15:42:08 +02:00
private static final Logger _log = LoggerFactory . getLogger ( DBCassandraAstyanaxImpl . class ) ;
2013-06-03 18:12:13 +02:00
2013-01-10 14:19:53 +01:00
/ * *
* connection instance
* /
private CassandraClusterConnection conn ;
2014-10-01 17:08:38 +02:00
2014-05-05 18:52:22 +02:00
protected CassandraClusterConnection getConnection ( ) {
return conn ;
}
2013-01-10 14:19:53 +01:00
/ * *
* use this constructor carefully from test classes
* @param dropSchema set true if you want do drop the current and set up new one
* /
protected DBCassandraAstyanaxImpl ( boolean dropSchema ) {
conn = new CassandraClusterConnection ( dropSchema ) ;
}
/ * *
* public constructor , no dropping schema is allowed
* /
public DBCassandraAstyanaxImpl ( ) {
conn = new CassandraClusterConnection ( false ) ;
}
2016-04-04 12:46:24 +02:00
2016-02-04 16:52:46 +01:00
/ * *
* public constructor , no dropping schema is allowed , infrastructureName is given .
* /
public DBCassandraAstyanaxImpl ( String infrastructureName ) {
conn = new CassandraClusterConnection ( false , infrastructureName ) ;
}
2016-04-04 12:46:24 +02:00
2023-10-30 18:52:02 +01:00
/ *
Utility Functions
* /
private static boolean existRecordbyId ( CqlSession session , String id , String tableName , String colName ) {
PreparedStatement stmt = session . prepare ( QueryBuilder
. selectFrom ( tableName ) . column ( colName )
. whereColumn ( colName )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
return session . execute ( stmt . bind ( id ) ) . getAvailableWithoutFetching ( ) > 0 ;
}
private static boolean existRecordbyCompId ( CqlSession session , String col1 , String col2 , String id1 , String id2 , String tableName ) {
PreparedStatement stmt = session . prepare ( QueryBuilder
. selectFrom ( tableName ) . all ( )
. whereColumn ( col1 )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( col2 )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
return session . execute ( stmt . bind ( id1 , id2 ) ) . getAvailableWithoutFetching ( ) > 0 ;
}
private static PreparedStatement updatePostEntry ( CqlSession session , String colName ) {
return session . prepare ( QueryBuilder . update ( POSTS )
. setColumn ( colName , QueryBuilder . bindMarker ( ) )
. whereColumn ( POST_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static Optional < Post > findPostById ( String postid , CqlSession session ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException {
PreparedStatement stmtFindPost = session . prepare ( QueryBuilder
. selectFrom ( POSTS ) . all ( )
. whereColumn ( POST_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet rs = session . execute ( stmtFindPost . bind ( UUID . fromString ( postid ) ) ) ;
// We query by the primary key ensuring unicity
Row record = rs . one ( ) ;
return ( null ! = record ) ? Optional . of ( readPostFromRow ( record ) ) : Optional . empty ( ) ;
}
private static Attachment readAttachmentFromRow ( Row record ) {
Attachment a = new Attachment ( ) ;
a . setId ( Objects . requireNonNull ( record . getUuid ( ATTACH_ID ) ) . toString ( ) ) ;
a . setUri ( record . getString ( URI ) ) ;
a . setName ( record . getString ( NAME ) ) ;
a . setDescription ( record . getString ( DESCRIPTION ) ) ;
a . setThumbnailURL ( record . getString ( URI_THUMBNAIL ) ) ;
a . setMimeType ( record . getString ( MIME_TYPE ) ) ;
return a ;
}
private static Notification readNotificationFromRow ( Row record ) throws NotificationTypeNotFoundException {
Notification a = new Notification ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( NOT_ID ) ) . toString ( ) ) ;
a . setType ( getNotificationType ( Objects . requireNonNull ( record . getString ( TYPE ) ) ) ) ;
a . setUserid ( record . getString ( USER_ID ) ) ;
a . setSubjectid ( record . getString ( SUBJECT_ID ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setUri ( record . getString ( URI ) ) ;
a . setDescription ( record . getString ( DESCRIPTION ) ) ;
a . setRead ( record . getBoolean ( IS_READ ) ) ;
a . setSenderid ( record . getString ( SENDER_ID ) ) ;
a . setSenderFullName ( record . getString ( SENDER_FULL_NAME ) ) ;
a . setSenderThumbnail ( record . getString ( SENDER_THUMBNAIL_URL ) ) ;
return a ;
}
private static Post readPostFromRow ( Row record ) throws FeedTypeNotFoundException , PrivacyLevelTypeNotFoundException {
Post a = new Post ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( POST_ID ) ) . toString ( ) ) ;
a . setType ( getPostType ( Objects . requireNonNull ( record . getString ( TYPE ) ) ) ) ;
a . setEntityId ( record . getString ( ENTITY_ID ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setVreid ( record . getString ( VRE_ID ) ) ;
a . setUri ( record . getString ( URI ) ) ;
a . setUriThumbnail ( record . getString ( URI_THUMBNAIL ) ) ;
a . setDescription ( record . getString ( DESCRIPTION ) ) ;
a . setPrivacy ( getPrivacyLevel ( Objects . requireNonNull ( record . getString ( PRIVACY ) ) ) ) ;
a . setFullName ( record . getString ( FULL_NAME ) ) ;
a . setEmail ( record . getString ( EMAIL ) ) ;
a . setThumbnailURL ( record . getString ( THUMBNAIL_URL ) ) ;
a . setCommentsNo ( String . valueOf ( record . getLong ( COMMENTS_NO ) ) ) ;
a . setLikesNo ( String . valueOf ( record . getLong ( LIKES_NO ) ) ) ;
a . setLinkDescription ( record . getString ( LINK_DESCRIPTION ) ) ;
a . setLinkTitle ( record . getString ( LINK_TITLE ) ) ;
a . setLinkHost ( record . getString ( LINK_HOST ) ) ;
a . setApplicationFeed ( record . getBoolean ( IS_APPLICATION_POST ) ) ;
a . setMultiFileUpload ( record . getBoolean ( MULTI_FILE_UPLOAD ) ) ;
return a ;
}
private static Like readLikeFromRow ( Row record ) {
Like a = new Like ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( LIKE_ID ) ) . toString ( ) ) ;
a . setUserid ( record . getString ( USER_ID ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setFeedid ( Objects . requireNonNull ( record . getUuid ( POST_ID ) ) . toString ( ) ) ;
a . setFullName ( record . getString ( FULL_NAME ) ) ;
a . setThumbnailURL ( record . getString ( THUMBNAIL_URL ) ) ;
return a ;
}
private static Comment readCommentFromRow ( Row record ) {
Comment a = new Comment ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( COMMENT_ID ) ) . toString ( ) ) ;
a . setUserid ( record . getString ( USER_ID ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setFeedid ( Objects . requireNonNull ( record . getUuid ( POST_ID ) ) . toString ( ) ) ;
a . setFullName ( record . getString ( FULL_NAME ) ) ;
a . setThumbnailURL ( record . getString ( THUMBNAIL_URL ) ) ;
a . setText ( record . getString ( COMMENT ) ) ;
a . setEdit ( ! record . isNull ( IS_EDIT ) & & record . getBoolean ( IS_EDIT ) ) ;
a . setLastEditTime ( record . isNull ( LAST_EDIT_TIME ) ? null : Date . from ( Objects . requireNonNull ( record . getInstant ( LAST_EDIT_TIME ) ) ) ) ;
return a ;
}
private static Invite readAInviteFromRow ( Row record ) throws InviteStatusNotFoundException {
Invite a = new Invite ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( INVITE_ID ) ) . toString ( ) ) ;
a . setSenderUserId ( record . getString ( SENDER_USER_ID ) ) ;
a . setVreid ( record . getString ( VRE_ID ) ) ;
a . setInvitedEmail ( record . getString ( EMAIL ) ) ;
a . setControlCode ( record . getString ( CONTROL_CODE ) ) ;
a . setStatus ( getInviteStatusType ( Objects . requireNonNull ( record . getString ( STATUS ) ) ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setSenderFullName ( record . getString ( SENDER_FULL_NAME ) ) ;
return a ;
}
private static Feed readFeedFromRow ( Row record ) throws FeedTypeNotFoundException , PrivacyLevelTypeNotFoundException {
Feed a = new Feed ( ) ;
a . setKey ( Objects . requireNonNull ( record . getUuid ( POST_ID ) ) . toString ( ) ) ;
a . setType ( getFeedType ( Objects . requireNonNull ( record . getString ( TYPE ) ) ) ) ;
a . setEntityId ( record . getString ( ENTITY_ID ) ) ;
a . setTime ( Date . from ( Objects . requireNonNull ( record . getInstant ( TIMESTAMP ) ) ) ) ;
a . setVreid ( record . getString ( VRE_ID ) ) ;
a . setUri ( record . getString ( URI ) ) ;
a . setUriThumbnail ( record . getString ( URI_THUMBNAIL ) ) ;
a . setDescription ( record . getString ( DESCRIPTION ) ) ;
a . setPrivacy ( getPrivacyLevel ( Objects . requireNonNull ( record . getString ( PRIVACY ) ) ) ) ;
a . setFullName ( record . getString ( FULL_NAME ) ) ;
a . setEmail ( record . getString ( EMAIL ) ) ;
a . setThumbnailURL ( record . getString ( THUMBNAIL_URL ) ) ;
a . setCommentsNo ( String . valueOf ( record . getLong ( COMMENTS_NO ) ) ) ;
a . setLikesNo ( String . valueOf ( record . getLong ( LIKES_NO ) ) ) ;
a . setLinkDescription ( record . getString ( LINK_DESCRIPTION ) ) ;
a . setLinkTitle ( record . getString ( LINK_TITLE ) ) ;
a . setLinkHost ( record . getString ( LINK_HOST ) ) ;
a . setApplicationFeed ( record . getBoolean ( IS_APPLICATION_POST ) ) ;
a . setMultiFileUpload ( record . getBoolean ( MULTI_FILE_UPLOAD ) ) ;
return a ;
}
private static Optional < Feed > findFeedById ( String postid , CqlSession session ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException {
PreparedStatement stmtFindPost = session . prepare ( QueryBuilder
. selectFrom ( POSTS ) . all ( )
. whereColumn ( POST_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet rs = session . execute ( stmtFindPost . bind ( UUID . fromString ( postid ) ) ) ;
// We query by the primary key ensuring unicity
Row record = rs . one ( ) ;
return ( null ! = record ) ? Optional . of ( readFeedFromRow ( record ) ) : Optional . empty ( ) ;
}
private static Optional < Notification > findNotById ( String notid , CqlSession session ) throws NotificationTypeNotFoundException {
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( NOTIFICATIONS ) . all ( )
. whereColumn ( NOT_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet rs = session . execute ( stmtFind . bind ( UUID . fromString ( notid ) ) ) ;
// We query by the primary key ensuring unicity
Row record = rs . one ( ) ;
return ( null ! = record ) ? Optional . of ( readNotificationFromRow ( record ) ) : Optional . empty ( ) ;
}
private static PreparedStatement updateInviteEntry ( CqlSession session , String colName ) {
return session . prepare ( QueryBuilder . update ( INVITES )
. setColumn ( colName , QueryBuilder . bindMarker ( ) )
. whereColumn ( INVITE_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement updateVreInviteEntry ( CqlSession session , String colName ) {
return session . prepare ( QueryBuilder . update ( VRE_INVITES )
. setColumn ( colName , QueryBuilder . bindMarker ( ) )
. whereColumn ( VRE_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( INVITE_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteHashtagEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( HASHTAGGED_POSTS )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( POST_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteHashtagCommentEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( HASHTAGGED_COMMENTS )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( COMMENT_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteLikeEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( LIKES )
. whereColumn ( LIKE_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteUserLikeEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( USER_LIKED_POSTS )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( LIKE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement updateCommentEntry ( CqlSession session , String colName ) {
return session . prepare ( QueryBuilder . update ( COMMENTS )
. setColumn ( colName , QueryBuilder . bindMarker ( ) )
. whereColumn ( COMMENT_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteCommentEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( COMMENTS )
. whereColumn ( COMMENT_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement updateNotificationEntry ( CqlSession session , String colName ) {
return session . prepare ( QueryBuilder . update ( NOTIFICATIONS )
. setColumn ( colName , QueryBuilder . bindMarker ( ) )
. whereColumn ( NOT_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement deleteUnreadNotEntry ( CqlSession session ) {
return session . prepare ( QueryBuilder . deleteFrom ( USER_NOTIFICATIONS_UNREAD )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( TIMESTAMP )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static BatchStatement getBatch ( ) {
return BatchStatement . builder ( BatchType . LOGGED ) . build ( ) ;
}
private static PreparedStatement createPostEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( POSTS )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. value ( LINK_HOST , QueryBuilder . bindMarker ( ) )
. value ( DESCRIPTION , QueryBuilder . bindMarker ( ) )
. value ( EMAIL , QueryBuilder . bindMarker ( ) )
. value ( LIKES_NO , QueryBuilder . bindMarker ( ) )
. value ( THUMBNAIL_URL , QueryBuilder . bindMarker ( ) )
. value ( LINK_DESCRIPTION , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( URI , QueryBuilder . bindMarker ( ) )
. value ( IS_APPLICATION_POST , QueryBuilder . bindMarker ( ) )
. value ( ENTITY_ID , QueryBuilder . bindMarker ( ) )
. value ( PRIVACY , QueryBuilder . bindMarker ( ) )
. value ( TYPE , QueryBuilder . bindMarker ( ) )
. value ( URI_THUMBNAIL , QueryBuilder . bindMarker ( ) )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( MULTI_FILE_UPLOAD , QueryBuilder . bindMarker ( ) )
. value ( FULL_NAME , QueryBuilder . bindMarker ( ) )
. value ( COMMENTS_NO , QueryBuilder . bindMarker ( ) )
. value ( LINK_TITLE , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createUserTimelineEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( USER_TIMELINE_POSTS )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createVreTimelineEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( VRE_TIMELINE_POSTS )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createAppTimelineEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( APP_TIMELINE_POSTS )
. value ( APP_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNotificationEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( NOTIFICATIONS )
. value ( NOT_ID , QueryBuilder . bindMarker ( ) )
. value ( TYPE , QueryBuilder . bindMarker ( ) )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( SUBJECT_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( DESCRIPTION , QueryBuilder . bindMarker ( ) )
. value ( URI , QueryBuilder . bindMarker ( ) )
. value ( SENDER_ID , QueryBuilder . bindMarker ( ) )
. value ( SENDER_FULL_NAME , QueryBuilder . bindMarker ( ) )
. value ( SENDER_THUMBNAIL_URL , QueryBuilder . bindMarker ( ) )
. value ( IS_READ , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createUserNotificationsEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( USER_NOTIFICATIONS )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( NOT_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createUnreadNotificationEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( USER_NOTIFICATIONS_UNREAD )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( NOT_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNotificationPreferenceEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( USER_NOTIFICATIONS_PREFERENCES )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( TYPE , QueryBuilder . bindMarker ( ) )
. value ( PREFERENCE , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewCommentEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( COMMENTS )
. value ( COMMENT_ID , QueryBuilder . bindMarker ( ) )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( FULL_NAME , QueryBuilder . bindMarker ( ) )
. value ( THUMBNAIL_URL , QueryBuilder . bindMarker ( ) )
. value ( COMMENT , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( IS_EDIT , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewLikeEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( LIKES )
. value ( LIKE_ID , QueryBuilder . bindMarker ( ) )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( FULL_NAME , QueryBuilder . bindMarker ( ) )
. value ( THUMBNAIL_URL , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewUserLikesEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( USER_LIKED_POSTS )
. value ( USER_ID , QueryBuilder . bindMarker ( ) )
. value ( LIKE_ID , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewHashtagTimelineEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( HASHTAGGED_POSTS )
. value ( HASHTAG , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewHashtagCommentEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( HASHTAGGED_COMMENTS )
. value ( HASHTAG , QueryBuilder . bindMarker ( ) )
. value ( COMMENT_ID , QueryBuilder . bindMarker ( ) )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewEmailInviteEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( EMAIL_INVITES )
. value ( EMAIL , QueryBuilder . bindMarker ( ) )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( INVITE_ID , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewInviteEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( INVITES )
. value ( INVITE_ID , QueryBuilder . bindMarker ( ) )
. value ( SENDER_USER_ID , QueryBuilder . bindMarker ( ) )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( EMAIL , QueryBuilder . bindMarker ( ) )
. value ( CONTROL_CODE , QueryBuilder . bindMarker ( ) )
. value ( STATUS , QueryBuilder . bindMarker ( ) )
. value ( TIMESTAMP , QueryBuilder . bindMarker ( ) )
. value ( SENDER_FULL_NAME , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewVreInviteEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( VRE_INVITES )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( INVITE_ID , QueryBuilder . bindMarker ( ) )
. value ( STATUS , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewaAttachEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( ATTACHMENTS )
. value ( ATTACH_ID , QueryBuilder . bindMarker ( ) )
. value ( POST_ID , QueryBuilder . bindMarker ( ) )
. value ( URI , QueryBuilder . bindMarker ( ) )
. value ( NAME , QueryBuilder . bindMarker ( ) )
. value ( DESCRIPTION , QueryBuilder . bindMarker ( ) )
. value ( URI_THUMBNAIL , QueryBuilder . bindMarker ( ) )
. value ( MIME_TYPE , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
}
private static PreparedStatement createNewUHashtagCounterEntry ( CqlSession session ) {
return session . prepare (
QueryBuilder . insertInto ( HASHTAGS_COUNTER )
. value ( VRE_ID , QueryBuilder . bindMarker ( ) )
. value ( HASHTAG , QueryBuilder . bindMarker ( ) )
. value ( COUNT , QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
2013-01-10 14:19:53 +01:00
/ *
2023-10-30 18:52:02 +01:00
*
2013-01-10 14:19:53 +01:00
* * * * * * * * * * * * * * * * * * * * * * FRIENDSHIPS ( CONNECTIONS ) * * * * * * * * * * * * * * * * * * * * * * *
*
* /
/ * *
* { @inheritDoc }
* /
@Override
public boolean requestFriendship ( String from , String to ) {
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean approveFriendship ( String from , String to ) {
2023-10-30 18:52:02 +01:00
return true ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean denyFriendship ( String from , String to ) {
2023-10-30 18:52:02 +01:00
return true ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
public List < String > getFriends ( String userid ) {
ArrayList < String > toReturn = new ArrayList < String > ( ) ;
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Override
public List < String > getPendingFriendRequests ( String userid ) {
ArrayList < String > toReturn = new ArrayList < String > ( ) ;
return toReturn ;
}
/ *
2023-10-30 18:52:02 +01:00
*
2013-01-10 14:19:53 +01:00
* * * * * * * * * * * * * * * * * * * * * * FEEDS * * * * * * * * * * * * * * * * * * * * * * *
*
* /
2023-10-30 18:52:02 +01:00
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
@Override
2023-10-30 18:52:02 +01:00
public boolean saveUserFeed ( Feed post ) {
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
//an entry in posts
PreparedStatement stmt1 = createPostEntry ( session ) ;
writeBatch . add ( stmt1 . bind ( UUID . fromString ( post . getKey ( ) ) ,
post . getLinkHost ( ) ,
post . getDescription ( ) ,
post . getEmail ( ) ,
post . getLikesNo ( ) ! = null ? Long . parseLong ( post . getLikesNo ( ) ) : null ,
post . getThumbnailURL ( ) ,
post . getLinkDescription ( ) ,
post . getTime ( ) ! = null ? post . getTime ( ) . toInstant ( ) : null ,
post . getUri ( ) ,
post . isApplicationFeed ( ) ,
post . getEntityId ( ) ,
post . getPrivacy ( ) ! = null ? post . getPrivacy ( ) . toString ( ) : null ,
post . getType ( ) ! = null ? post . getType ( ) . toString ( ) : null ,
post . getUriThumbnail ( ) ,
post . getVreid ( ) ,
post . isMultiFileUpload ( ) ,
post . getFullName ( ) ,
post . getCommentsNo ( ) ! = null ? Long . parseLong ( post . getCommentsNo ( ) ) : null ,
post . getLinkTitle ( ) ) ) ;
//an entry in the user Timeline
PreparedStatement stmt2 = createUserTimelineEntry ( session ) ;
writeBatch . add ( stmt2 . bind ( post . getEntityId ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2013-01-10 14:19:53 +01:00
//an entry in the VRES Timeline iff vreid field is not empty
2023-10-30 18:52:02 +01:00
if ( post . getVreid ( ) ! = null & & post . getVreid ( ) . compareTo ( " " ) ! = 0 ) {
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( post . getVreid ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
}
Boolean result = session . execute ( writeBatch ) . wasApplied ( ) ;
if ( result ) {
_log . info ( " Wrote user post with id " + post . getKey ( ) ) ;
2013-01-10 14:19:53 +01:00
}
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return result ;
2013-01-10 14:19:53 +01:00
}
2016-01-14 18:37:03 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public boolean saveUserPost ( Post post ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
//an entry in posts
PreparedStatement stmt1 = createPostEntry ( session ) ;
writeBatch . add ( stmt1 . bind ( UUID . fromString ( post . getKey ( ) ) ,
post . getLinkHost ( ) ,
post . getDescription ( ) ,
post . getEmail ( ) ,
post . getLikesNo ( ) ! = null ? Long . parseLong ( post . getLikesNo ( ) ) : null ,
post . getThumbnailURL ( ) ,
post . getLinkDescription ( ) ,
post . getTime ( ) ! = null ? post . getTime ( ) . toInstant ( ) : null ,
post . getUri ( ) ,
post . isApplicationFeed ( ) ,
post . getEntityId ( ) ,
post . getPrivacy ( ) ! = null ? post . getPrivacy ( ) . toString ( ) : null ,
post . getType ( ) ! = null ? post . getType ( ) . toString ( ) : null ,
post . getUriThumbnail ( ) ,
post . getVreid ( ) ,
post . isMultiFileUpload ( ) ,
post . getFullName ( ) ,
post . getCommentsNo ( ) ! = null ? Long . parseLong ( post . getCommentsNo ( ) ) : null ,
post . getLinkTitle ( ) ) ) ;
//an entry in the user Timeline
PreparedStatement stmt2 = createUserTimelineEntry ( session ) ;
writeBatch . add ( stmt2 . bind ( post . getEntityId ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2022-09-20 17:00:25 +02:00
//an entry in the VRES Timeline iff vreid field is not empty
2023-10-30 18:52:02 +01:00
if ( post . getVreid ( ) ! = null & & post . getVreid ( ) . compareTo ( " " ) ! = 0 ) {
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( post . getVreid ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
}
Boolean result = session . execute ( writeBatch ) . wasApplied ( ) ;
if ( result ) {
_log . info ( " Wrote user post with id " + post . getKey ( ) ) ;
2022-09-20 17:00:25 +02:00
}
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return result ;
2022-09-20 17:00:25 +02:00
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2016-01-14 18:37:03 +01:00
public boolean saveUserFeed ( Feed feed , List < Attachment > attachments ) {
if ( attachments ! = null & & ! attachments . isEmpty ( ) )
feed . setMultiFileUpload ( true ) ;
boolean saveFeedResult = saveUserFeed ( feed ) ;
if ( saveFeedResult ) {
String feedKey = feed . getKey ( ) ;
for ( Attachment attachment : attachments ) {
boolean attachSaveResult = saveAttachmentEntry ( feedKey , attachment ) ;
if ( ! attachSaveResult )
_log . warn ( " Some of the attachments failed to me saved: " + attachment . getName ( ) ) ;
}
return true ;
}
else return false ;
}
2022-09-20 17:00:25 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean saveUserPost ( Post post , List < Attachment > attachments ) {
if ( attachments ! = null & & ! attachments . isEmpty ( ) )
post . setMultiFileUpload ( true ) ;
2023-10-30 18:52:02 +01:00
boolean savePostResult = saveUserPost ( post ) ;
if ( savePostResult ) {
2022-09-20 17:00:25 +02:00
String postkey = post . getKey ( ) ;
for ( Attachment attachment : attachments ) {
boolean attachSaveResult = saveAttachmentEntry ( postkey , attachment ) ;
if ( ! attachSaveResult )
_log . warn ( " Some of the attachments failed to be saved: " + attachment . getName ( ) ) ;
}
return true ;
}
else return false ;
}
2016-02-02 15:19:10 +01:00
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
@Deprecated
2023-10-30 18:52:02 +01:00
public boolean saveAppFeed ( Feed post ) {
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
//an entry to posts
PreparedStatement stmt1 = createPostEntry ( session ) ;
writeBatch . add ( stmt1 . bind ( UUID . fromString ( post . getKey ( ) ) ,
post . getLinkHost ( ) ,
post . getDescription ( ) ,
post . getEmail ( ) ,
post . getLikesNo ( ) ! = null ? Long . parseLong ( post . getLikesNo ( ) ) : null ,
post . getThumbnailURL ( ) ,
post . getLinkDescription ( ) ,
post . getTime ( ) ! = null ? post . getTime ( ) . toInstant ( ) : null ,
post . getUri ( ) ,
post . isApplicationFeed ( ) ,
post . getEntityId ( ) ,
post . getPrivacy ( ) ! = null ? post . getPrivacy ( ) . toString ( ) : null ,
post . getType ( ) ! = null ? post . getType ( ) . toString ( ) : null ,
post . getUriThumbnail ( ) ,
post . getVreid ( ) ,
post . isMultiFileUpload ( ) ,
post . getFullName ( ) ,
post . getCommentsNo ( ) ! = null ? Long . parseLong ( post . getCommentsNo ( ) ) : null ,
post . getLinkTitle ( ) ) ) ;
//an entry in the Applications Timeline
PreparedStatement stmt2 = createAppTimelineEntry ( session ) ;
writeBatch . add ( stmt2 . bind ( post . getEntityId ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2013-01-10 14:19:53 +01:00
//an entry in the VRES Timeline iff vreid field is not empty
2023-10-30 18:52:02 +01:00
if ( post . getVreid ( ) ! = null & & post . getVreid ( ) . compareTo ( " " ) ! = 0 ) {
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( post . getVreid ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
boolean result = session . execute ( writeBatch ) . wasApplied ( ) ;
2013-02-08 11:56:28 +01:00
if ( result )
2023-10-30 18:52:02 +01:00
_log . info ( " Wrote app post with id " + post . getKey ( ) ) ;
2023-11-15 18:14:57 +01:00
2013-02-08 11:56:28 +01:00
return result ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public boolean saveAppPost ( Post post ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
//an entry to posts
PreparedStatement stmt1 = createPostEntry ( session ) ;
writeBatch . add ( stmt1 . bind ( UUID . fromString ( post . getKey ( ) ) ,
post . getLinkHost ( ) ,
post . getDescription ( ) ,
post . getEmail ( ) ,
post . getLikesNo ( ) ! = null ? Long . parseLong ( post . getLikesNo ( ) ) : null ,
post . getThumbnailURL ( ) ,
post . getLinkDescription ( ) ,
post . getTime ( ) ! = null ? post . getTime ( ) . toInstant ( ) : null ,
post . getUri ( ) ,
post . isApplicationFeed ( ) ,
post . getEntityId ( ) ,
post . getPrivacy ( ) ! = null ? post . getPrivacy ( ) . toString ( ) : null ,
post . getType ( ) ! = null ? post . getType ( ) . toString ( ) : null ,
post . getUriThumbnail ( ) ,
post . getVreid ( ) ,
post . isMultiFileUpload ( ) ,
post . getFullName ( ) ,
post . getCommentsNo ( ) ! = null ? Long . parseLong ( post . getCommentsNo ( ) ) : null ,
post . getLinkTitle ( ) ) ) ;
//an entry in the Applications Timeline
PreparedStatement stmt2 = createAppTimelineEntry ( session ) ;
writeBatch . add ( stmt2 . bind ( post . getEntityId ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2022-09-20 17:00:25 +02:00
//an entry in the VRES Timeline iff vreid field is not empty
2023-10-30 18:52:02 +01:00
if ( post . getVreid ( ) ! = null & & post . getVreid ( ) . compareTo ( " " ) ! = 0 ) {
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( post . getVreid ( ) , post . getTime ( ) . toInstant ( ) , UUID . fromString ( post . getKey ( ) ) ) ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
boolean result = session . execute ( writeBatch ) . wasApplied ( ) ;
2022-09-20 17:00:25 +02:00
if ( result )
2023-10-30 18:52:02 +01:00
_log . info ( " Wrote app post with id " + post . getKey ( ) ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
return result ;
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2016-01-15 17:07:44 +01:00
public boolean saveAppFeed ( Feed feed , List < Attachment > attachments ) {
if ( attachments ! = null & & ! attachments . isEmpty ( ) )
feed . setMultiFileUpload ( true ) ;
boolean saveFeedResult = saveAppFeed ( feed ) ;
if ( saveFeedResult ) {
String feedKey = feed . getKey ( ) ;
for ( Attachment attachment : attachments ) {
boolean attachSaveResult = saveAttachmentEntry ( feedKey , attachment ) ;
if ( ! attachSaveResult )
_log . warn ( " Some of the attachments failed to me saved: " + attachment . getName ( ) ) ;
}
return true ;
}
else return false ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public boolean saveAppPost ( Post post , List < Attachment > attachments ) {
if ( attachments ! = null & & ! attachments . isEmpty ( ) )
post . setMultiFileUpload ( true ) ;
boolean saveFeedResult = saveAppPost ( post ) ;
if ( saveFeedResult ) {
String feedKey = post . getKey ( ) ;
for ( Attachment attachment : attachments ) {
boolean attachSaveResult = saveAttachmentEntry ( feedKey , attachment ) ;
if ( ! attachSaveResult )
_log . warn ( " Some of the attachments failed to be saved: " + attachment . getName ( ) ) ;
}
return true ;
}
else return false ;
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2013-01-10 14:19:53 +01:00
public boolean saveFeedToVRETimeline ( String feedKey , String vreid ) throws FeedIDNotFoundException {
2023-10-30 18:52:02 +01:00
Feed toCheck ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
toCheck = readFeed ( feedKey ) ;
2013-01-10 14:19:53 +01:00
if ( toCheck = = null )
2023-10-30 18:52:02 +01:00
throw new FeedIDNotFoundException ( " Could not find Post with id " + feedKey , feedKey ) ;
2013-01-10 14:19:53 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
2023-10-30 18:52:02 +01:00
}
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( vreid , toCheck . getTime ( ) . toInstant ( ) , UUID . fromString ( toCheck . getKey ( ) ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
try {
boolean res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return res ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public boolean savePostToVRETimeline ( String postKey , String vreid ) throws FeedIDNotFoundException {
2023-10-30 18:52:02 +01:00
Post toCheck ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
toCheck = readPost ( postKey ) ;
2022-09-20 17:00:25 +02:00
if ( toCheck = = null )
2023-10-30 18:52:02 +01:00
throw new FeedIDNotFoundException ( " Could not find Post with id " + postKey , postKey ) ;
2022-09-20 17:00:25 +02:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
2023-10-30 18:52:02 +01:00
}
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
PreparedStatement stmt3 = createVreTimelineEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( vreid , toCheck . getTime ( ) . toInstant ( ) , UUID . fromString ( toCheck . getKey ( ) ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
try {
boolean res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return res ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
2022-09-20 17:00:25 +02:00
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2013-01-10 14:19:53 +01:00
public Feed readFeed ( String feedid )
throws PrivacyLevelTypeNotFoundException ,
FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
Feed post ;
try {
post = findFeedById ( feedid , session ) . get ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
return null ;
2023-10-30 18:52:02 +01:00
}
return post ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public Post readPost ( String postid )
throws PrivacyLevelTypeNotFoundException ,
FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
Post post ;
try {
post = findPostById ( postid , session ) . get ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
return null ;
2023-10-30 18:52:02 +01:00
}
return post ;
2022-09-20 17:00:25 +02:00
}
/ * *
* { @inheritDoc }
* /
@Override
@Deprecated
2015-12-02 16:50:26 +01:00
public List < Feed > getRecentFeedsByUserAndDate ( String userid , long timeInMillis ) throws IllegalArgumentException {
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
2016-01-14 18:37:03 +01:00
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
2015-12-02 16:50:26 +01:00
try {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_TIMELINE_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-12-02 16:50:26 +01:00
e . printStackTrace ( ) ;
}
2023-10-30 18:52:02 +01:00
List < Feed > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
Instant postTime = row . getInstant ( TIMESTAMP ) ;
if ( Date . from ( postTime ) . getTime ( ) > timeInMillis ) {
try {
Feed toCheck = readFeed ( row . getUuid ( POST_ID ) . toString ( ) ) ;
2015-12-02 16:50:26 +01:00
if ( toCheck . getType ( ) ! = FeedType . DISABLED )
2023-10-30 18:52:02 +01:00
return toCheck ;
} catch ( ColumnNameNotFoundException |
PrivacyLevelTypeNotFoundException e ) {
throw new RuntimeException ( e ) ;
} catch ( FeedIDNotFoundException e ) {
throw new RuntimeException ( e ) ;
} catch ( FeedTypeNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
}
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2015-12-02 16:50:26 +01:00
}
2023-10-30 18:52:02 +01:00
return null ;
} ) . collect ( Collectors . toList ( ) ) ;
2015-12-02 16:50:26 +01:00
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public List < Post > getRecentPostsByUserAndDate ( String userid , long timeInMillis ) throws IllegalArgumentException {
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_TIMELINE_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
}
2023-10-30 18:52:02 +01:00
List < Post > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
Instant postTime = row . getInstant ( TIMESTAMP ) ;
if ( Date . from ( postTime ) . getTime ( ) > timeInMillis ) {
try {
Post toCheck = readPost ( row . getUuid ( POST_ID ) . toString ( ) ) ;
2022-09-20 17:00:25 +02:00
if ( toCheck . getType ( ) ! = PostType . DISABLED )
2023-10-30 18:52:02 +01:00
return toCheck ;
} catch ( ColumnNameNotFoundException |
PrivacyLevelTypeNotFoundException e ) {
throw new RuntimeException ( e ) ;
} catch ( FeedIDNotFoundException e ) {
throw new RuntimeException ( e ) ;
} catch ( FeedTypeNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
}
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
return null ;
} ) . collect ( Collectors . toList ( ) ) ;
2022-09-20 17:00:25 +02:00
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2013-01-10 14:19:53 +01:00
public boolean deleteFeed ( String feedId ) throws FeedIDNotFoundException , PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException {
Feed toDelete = readFeed ( feedId ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
PreparedStatement stmt1 = updatePostEntry ( session , TYPE ) ;
writeBatch . add ( stmt1 . bind ( FeedType . DISABLED . toString ( ) , UUID . fromString ( toDelete . getKey ( ) ) ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
_log . error ( " Delete Post ERROR for postid " + feedId ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
return false ;
}
2023-10-30 18:52:02 +01:00
_log . info ( " Delete Post OK " ) ;
2013-01-10 14:19:53 +01:00
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public boolean deletePost ( String postid ) throws FeedIDNotFoundException , PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException {
Post toDelete = readPost ( postid ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
PreparedStatement stmt1 = updatePostEntry ( session , TYPE ) ;
writeBatch . add ( stmt1 . bind ( PostType . DISABLED . toString ( ) , UUID . fromString ( toDelete . getKey ( ) ) ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
_log . error ( " Delete Post ERROR for postid " + postid ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
return false ;
}
_log . info ( " Delete Post OK " ) ;
return true ;
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2013-01-10 14:19:53 +01:00
public List < Feed > getAllFeedsByUser ( String userid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getFeedsByIds ( getUserFeedIds ( userid ) ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public List < Post > getAllPostsByUser ( String userid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getPostsByIds ( getUserPostIds ( userid ) ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
2013-01-10 14:19:53 +01:00
public List < Feed > getAllFeedsByApp ( String appid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getFeedsByIds ( getAppFeedIds ( appid ) ) ;
}
2022-09-20 17:00:25 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public List < Post > getAllPostsByApp ( String appid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getPostsByIds ( getAppPostIds ( appid ) ) ;
}
2016-08-02 20:15:50 +02:00
/ * *
* { @inheritDoc }
2023-10-30 18:52:02 +01:00
* @throws Exception
2016-08-02 20:15:50 +02:00
* /
2022-09-20 17:00:25 +02:00
@Deprecated
2016-08-02 20:15:50 +02:00
@Override
public List < Feed > getRecentCommentedFeedsByUserAndDate ( String userid ,
long timeInMillis ) throws Exception {
List < Feed > toReturn = new ArrayList < Feed > ( ) ;
2016-08-03 10:08:51 +02:00
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
if ( userid = = null | | userid . isEmpty ( ) )
throw new IllegalArgumentException ( " the userId parameter cannot be null/empty " ) ;
// get the last comments by the user (it is not needed to get them sorted)
List < Comment > lastComments = getRecentCommentsByUserAndDateBody ( userid , timeInMillis , false ) ;
2016-08-02 20:15:50 +02:00
// evaluate unique feeds' ids
2023-10-30 18:52:02 +01:00
HashSet < String > postIds = new HashSet < String > ( ) ;
2016-08-02 20:15:50 +02:00
for ( Comment comment : lastComments ) {
2023-10-30 18:52:02 +01:00
String postId = comment . getFeedid ( ) ;
2016-08-02 20:15:50 +02:00
try {
2023-10-30 18:52:02 +01:00
if ( ! postIds . contains ( postId ) ) {
postIds . add ( postId ) ;
toReturn . add ( readFeed ( postId ) ) ;
2016-08-02 20:15:50 +02:00
}
} catch ( Exception e ) {
2023-10-30 18:52:02 +01:00
_log . error ( " Unable to retrieve feed with id " + postId , e ) ;
2016-08-02 20:15:50 +02:00
}
}
2016-08-03 10:08:51 +02:00
Collections . sort ( toReturn , Collections . reverseOrder ( ) ) ;
2016-08-02 20:15:50 +02:00
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ * *
2022-09-20 17:00:25 +02:00
* { @inheritDoc }
2023-10-30 18:52:02 +01:00
* @throws Exception
2022-09-20 17:00:25 +02:00
* /
@Override
public List < Post > getRecentCommentedPostsByUserAndDate ( String userid ,
long timeInMillis ) throws Exception {
List < Post > toReturn = new ArrayList < Post > ( ) ;
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
if ( userid = = null | | userid . isEmpty ( ) )
throw new IllegalArgumentException ( " the userId parameter cannot be null/empty " ) ;
// get the last comments by the user (it is not needed to get them sorted)
List < Comment > lastComments = getRecentCommentsByUserAndDateBody ( userid , timeInMillis , false ) ;
// evaluate unique feeds' ids
HashSet < String > postIds = new HashSet < String > ( ) ;
for ( Comment comment : lastComments ) {
String postId = comment . getFeedid ( ) ;
try {
if ( ! postIds . contains ( postId ) ) {
postIds . add ( postId ) ;
toReturn . add ( readPost ( postId ) ) ;
}
} catch ( Exception e ) {
_log . error ( " Unable to retrieve feed with id " + postId , e ) ;
}
}
Collections . sort ( toReturn , Collections . reverseOrder ( ) ) ;
return toReturn ;
}
/ * *
* @deprecated
2013-01-10 14:19:53 +01:00
* helper method that retrieve all the feeds belongin to a list of Ids
* @param feedIds
* @return
2023-10-30 18:52:02 +01:00
* @throws ColumnNameNotFoundException
* @throws FeedIDNotFoundException
* @throws FeedTypeNotFoundException
* @throws PrivacyLevelTypeNotFoundException
2013-01-10 14:19:53 +01:00
* /
private List < Feed > getFeedsByIds ( List < String > feedIds ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
ArrayList < Feed > toReturn = new ArrayList < Feed > ( ) ;
for ( String feedid : feedIds ) {
Feed toAdd = readFeed ( feedid ) ;
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH )
toReturn . add ( toAdd ) ;
}
return toReturn ;
}
2022-09-20 17:00:25 +02:00
/ * *
* helper method that retrieve all the feeds belongin to a list of Ids
* @param postIds
* @return
2023-10-30 18:52:02 +01:00
* @throws ColumnNameNotFoundException
* @throws FeedIDNotFoundException
* @throws FeedTypeNotFoundException
* @throws PrivacyLevelTypeNotFoundException
2022-09-20 17:00:25 +02:00
* /
private List < Post > getPostsByIds ( List < String > postIds ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
ArrayList < Post > toReturn = new ArrayList < Post > ( ) ;
for ( String feedid : postIds ) {
Post toAdd = readPost ( feedid ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH )
toReturn . add ( toAdd ) ;
}
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ * *
* helper method that retrieve all the feed Ids belonging to a user
* @param userid user identifier
* @return simply return a list of user feed UUID in chronological order from the oldest to the more recent
* /
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
private ArrayList < String > getUserFeedIds ( String userid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_TIMELINE_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2013-01-10 14:19:53 +01:00
}
2022-09-20 17:00:25 +02:00
/ * *
* helper method that retrieve all the post Ids belonging to a user
* @param userid user identifier
* @return simply return a list of user post UUID in chronological order from the oldest to the more recent
* /
private ArrayList < String > getUserPostIds ( String userid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_TIMELINE_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2022-09-20 17:00:25 +02:00
}
2015-07-16 16:27:33 +02:00
/ * *
2023-10-30 18:52:02 +01:00
* helper method that return whether the user
2015-07-16 16:27:33 +02:00
* @param userid user identifier
2023-10-30 18:52:02 +01:00
* @param postid the feed identifier
2015-07-16 16:27:33 +02:00
* @return true if the feed id liked already
* /
2023-10-30 18:52:02 +01:00
private boolean isPostLiked ( String userid , String postid ) {
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_LIKED_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2015-07-16 16:27:33 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-07-16 16:27:33 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2015-07-16 16:27:33 +02:00
}
2023-10-30 18:52:02 +01:00
for ( Row row : result . all ( ) ) {
if ( row . getUuid ( POST_ID ) . toString ( ) . equals ( postid ) ) {
return true ;
2015-07-16 16:27:33 +02:00
}
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
2022-09-20 17:00:25 +02:00
return false ;
}
/ * *
* helper method that retrieve all the feed Ids belonging to an application
* @param appid application identifier
* @return simply return a list of app feed UUID in chronological order from the oldest to the more recent
* /
@Deprecated
private ArrayList < String > getAppFeedIds ( String appid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( APP_TIMELINE_POSTS ) . all ( )
. whereColumn ( APP_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( appid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2022-09-20 17:00:25 +02:00
}
/ * *
* helper method that retrieve all the post Ids belonging to an application
* @param appid application identifier
* @return simply return a list of app post UUID in chronological order from the oldest to the more recent
* /
private ArrayList < String > getAppPostIds ( String appid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( APP_TIMELINE_POSTS ) . all ( )
. whereColumn ( APP_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( appid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
2022-09-20 17:00:25 +02:00
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
public List < Feed > getAllPortalPrivacyLevelFeeds ( ) throws FeedTypeNotFoundException , ColumnNameNotFoundException , PrivacyLevelTypeNotFoundException {
2023-10-30 18:52:02 +01:00
//possible error index
2022-09-20 17:00:25 +02:00
ArrayList < Feed > toReturn = new ArrayList < Feed > ( ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( POSTS ) . all ( )
. whereColumn ( PRIVACY ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. limit ( 20 )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( PrivacyLevel . PORTAL . toString ( ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
for ( Row row : result . all ( ) ) {
Feed toAdd = readFeedFromRow ( row ) ;
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH )
toReturn . add ( toAdd ) ;
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
@Override
2022-09-20 17:00:25 +02:00
public List < Post > getAllPortalPrivacyLevelPosts ( ) throws FeedTypeNotFoundException , ColumnNameNotFoundException , PrivacyLevelTypeNotFoundException {
2023-10-30 18:52:02 +01:00
//possible error index
2022-09-20 17:00:25 +02:00
ArrayList < Post > toReturn = new ArrayList < Post > ( ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( POSTS ) . all ( )
. whereColumn ( PRIVACY ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. limit ( 20 )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( PrivacyLevel . PORTAL . toString ( ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
for ( Row row : result . all ( ) ) {
Post toAdd = readPostFromRow ( row ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH )
toReturn . add ( toAdd ) ;
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
public List < Feed > getRecentFeedsByUser ( String userid , int quantity ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
ArrayList < Feed > toReturn = new ArrayList < Feed > ( ) ;
ArrayList < String > feedIDs = getUserFeedIds ( userid ) ;
//check if quantity is greater than user feeds
quantity = ( quantity > feedIDs . size ( ) ) ? feedIDs . size ( ) : quantity ;
//need them in reverse order
for ( int i = feedIDs . size ( ) - 1 ; i > = ( feedIDs . size ( ) - quantity ) ; i - - ) {
Feed toAdd = readFeed ( feedIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH ) {
toReturn . add ( toAdd ) ;
_log . trace ( " Read recent feed: " + feedIDs . get ( i ) ) ;
2013-01-16 23:59:09 +01:00
} else {
2013-01-10 14:19:53 +01:00
_log . trace ( " Read and skipped feed: " + feedIDs . get ( i ) + " (Removed Feed) " ) ;
2013-01-16 23:59:09 +01:00
quantity + = 1 ; //increase the quantity in case of removed feed
//check if quantity is greater than user feeds
quantity = ( quantity > feedIDs . size ( ) ) ? feedIDs . size ( ) : quantity ;
}
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
2022-09-20 17:00:25 +02:00
@Override
public List < Post > getRecentPostsByUser ( String userid , int quantity ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
ArrayList < Post > toReturn = new ArrayList < Post > ( ) ;
ArrayList < String > postIDs = getUserPostIds ( userid ) ;
//check if quantity is greater than user feeds
quantity = ( quantity > postIDs . size ( ) ) ? postIDs . size ( ) : quantity ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2022-09-20 17:00:25 +02:00
for ( int i = postIDs . size ( ) - 1 ; i > = ( postIDs . size ( ) - quantity ) ; i - - ) {
Post toAdd = readPost ( postIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH ) {
toReturn . add ( toAdd ) ;
_log . trace ( " Read recent post: " + postIDs . get ( i ) ) ;
} else {
_log . trace ( " Read and skipped post: " + postIDs . get ( i ) + " (Removed Post) " ) ;
quantity + = 1 ; //increase the quantity in case of removed post
//check if quantity is greater than user feeds
quantity = ( quantity > postIDs . size ( ) ) ? postIDs . size ( ) : quantity ;
}
}
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
2023-10-30 18:52:02 +01:00
@Override
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
public List < Feed > getAllFeedsByVRE ( String vreid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getFeedsByIds ( getVREFeedIds ( vreid ) ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
public List < Post > getAllPostsByVRE ( String vreid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
return getPostsByIds ( getVREPostIds ( vreid ) ) ;
}
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
2013-01-10 14:19:53 +01:00
public List < Feed > getRecentFeedsByVRE ( String vreid , int quantity ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
ArrayList < Feed > toReturn = new ArrayList < Feed > ( ) ;
ArrayList < String > feedIDs = getVREFeedIds ( vreid ) ;
//check if quantity is greater than user feeds
quantity = ( quantity > feedIDs . size ( ) ) ? feedIDs . size ( ) : quantity ;
//need them in reverse order
for ( int i = feedIDs . size ( ) - 1 ; i > = ( feedIDs . size ( ) - quantity ) ; i - - ) {
Feed toAdd = readFeed ( feedIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH ) {
toReturn . add ( toAdd ) ;
_log . trace ( " Read recent feed: " + feedIDs . get ( i ) ) ;
2013-01-16 23:59:09 +01:00
} else {
_log . trace ( " Read and skipped feed: " + feedIDs . get ( i ) + " (Removed Feed) . " ) ;
quantity + = 1 ; //increase the quantity in case of removed feed
//check if quantity is greater than user feeds
quantity = ( quantity > feedIDs . size ( ) ) ? feedIDs . size ( ) : quantity ;
}
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
2022-09-20 17:00:25 +02:00
@Override
public List < Post > getRecentPostsByVRE ( String vreid , int quantity ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
ArrayList < Post > toReturn = new ArrayList < Post > ( ) ;
ArrayList < String > postIDs = getVREPostIds ( vreid ) ;
//check if quantity is greater than user posts
quantity = ( quantity > postIDs . size ( ) ) ? postIDs . size ( ) : quantity ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2022-09-20 17:00:25 +02:00
for ( int i = postIDs . size ( ) - 1 ; i > = ( postIDs . size ( ) - quantity ) ; i - - ) {
Post toAdd = readPost ( postIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH ) {
toReturn . add ( toAdd ) ;
_log . trace ( " Read recent Post: " + postIDs . get ( i ) ) ;
} else {
_log . trace ( " Read and skipped Post: " + postIDs . get ( i ) + " (Removed Post) . " ) ;
quantity + = 1 ; //increase the quantity in case of removed Post
//check if quantity is greater than user Posts
quantity = ( quantity > postIDs . size ( ) ) ? postIDs . size ( ) : quantity ;
}
}
return toReturn ;
}
2014-03-11 16:03:57 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2014-03-13 16:08:00 +01:00
public RangeFeeds getRecentFeedsByVREAndRange ( String vreid , int from , int quantity ) throws IllegalArgumentException , PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
2014-03-11 16:03:57 +01:00
if ( from < 1 ) {
throw new IllegalArgumentException ( " From must be greather than 0 " ) ;
2023-10-30 18:52:02 +01:00
}
2014-03-13 16:08:00 +01:00
ArrayList < Feed > feedsToReturn = new ArrayList < Feed > ( ) ;
2014-03-11 16:03:57 +01:00
ArrayList < String > feedIDs = getVREFeedIds ( vreid ) ;
2014-05-05 16:26:18 +02:00
2014-03-11 16:03:57 +01:00
//if from is greater than feeds size return empty
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 ( ) ) ;
2014-03-13 16:08:00 +01:00
return new RangeFeeds ( ) ;
2014-03-11 16:03:57 +01:00
}
2014-05-05 16:26:18 +02:00
2014-03-13 16:08:00 +01:00
int rangeStart = feedIDs . size ( ) - from ;
int rangeEnd = rangeStart - quantity ;
2014-05-05 16:26:18 +02:00
2014-03-13 16:08:00 +01:00
//check that you reached the end
if ( rangeEnd < 1 )
rangeEnd = 0 ;
2014-05-05 16:26:18 +02:00
2014-03-13 16:08:00 +01:00
_log . debug ( " BEFORE starting Point= " + rangeStart + " rangeEnd= " + rangeEnd ) ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2014-03-13 16:08:00 +01:00
int howMany = from ;
for ( int i = rangeStart ; i > rangeEnd ; i - - ) {
2014-03-11 16:03:57 +01:00
Feed toAdd = readFeed ( feedIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH ) {
2014-03-13 16:08:00 +01:00
feedsToReturn . add ( toAdd ) ;
2023-10-30 18:52:02 +01:00
_log . trace ( " Read recent post, i= " + i + " id= " + feedIDs . get ( i ) ) ;
2014-03-11 16:03:57 +01:00
} else {
2023-10-30 18:52:02 +01:00
_log . trace ( " Read and skipped post, i= " + i + " id=: " + feedIDs . get ( i ) + " (Removed post) . " ) ;
2014-03-13 16:08:00 +01:00
rangeEnd - = 1 ; //increase the upTo in case of removed feed
2014-03-11 16:03:57 +01:00
//check if quantity is greater than user feeds
2014-03-13 16:08:00 +01:00
rangeEnd = ( rangeEnd > 0 ) ? rangeEnd : 0 ;
2014-03-11 16:03:57 +01:00
}
2014-03-13 16:08:00 +01:00
howMany + + ;
2014-03-11 16:03:57 +01:00
}
2014-03-13 16:08:00 +01:00
_log . debug ( " AFTER: starting Point== " + rangeStart + " rangeEnd= " + rangeEnd ) ;
return new RangeFeeds ( howMany + 1 , feedsToReturn ) ;
2014-03-11 16:03:57 +01:00
}
2013-01-10 14:19:53 +01:00
/ * *
2022-09-20 17:00:25 +02:00
* { @inheritDoc }
* /
@Override
public RangePosts getRecentPostsByVREAndRange ( String vreid , int from , int quantity ) throws IllegalArgumentException , PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
if ( from < 1 ) {
throw new IllegalArgumentException ( " From must be greather than 0 " ) ;
2023-10-30 18:52:02 +01:00
}
2022-09-20 17:00:25 +02:00
ArrayList < Post > feedsToReturn = new ArrayList < Post > ( ) ;
ArrayList < String > feedIDs = getVREPostIds ( vreid ) ;
//if from is greater than feeds size return empty
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 ( ) ) ;
return new RangePosts ( ) ;
}
int rangeStart = feedIDs . size ( ) - from ;
int rangeEnd = rangeStart - quantity ;
//check that you reached the end
if ( rangeEnd < 1 )
rangeEnd = 0 ;
_log . debug ( " BEFORE starting Point= " + rangeStart + " rangeEnd= " + rangeEnd ) ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2022-09-20 17:00:25 +02:00
int howMany = from ;
for ( int i = rangeStart ; i > rangeEnd ; i - - ) {
Post toAdd = readPost ( feedIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH ) {
feedsToReturn . add ( toAdd ) ;
_log . trace ( " Read recent post, i= " + i + " id= " + feedIDs . get ( i ) ) ;
} else {
_log . trace ( " Read and skipped post, i= " + i + " id=: " + feedIDs . get ( i ) + " (Removed post) . " ) ;
rangeEnd - = 1 ; //increase the upTo in case of removed feed
//check if quantity is greater than user feeds
rangeEnd = ( rangeEnd > 0 ) ? rangeEnd : 0 ;
}
howMany + + ;
}
_log . debug ( " AFTER: starting Point== " + rangeStart + " rangeEnd= " + rangeEnd ) ;
return new RangePosts ( howMany + 1 , feedsToReturn ) ;
}
/ * *
* @deprecated
2013-01-10 14:19:53 +01:00
* get a list of user vre feed UUIDs in chronological order from the oldest to the more recent
* @param vreid vreid identifier ( scope )
* @return simply return a list of user vre feed UUIDs in chronological order from the oldest to the more recent
* /
private ArrayList < String > getVREFeedIds ( String vreid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( VRE_TIMELINE_POSTS ) . all ( )
. whereColumn ( VRE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( vreid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2013-01-10 14:19:53 +01:00
}
2022-09-20 17:00:25 +02:00
/ * *
* get a list of user vre post UUIDs in chronological order from the oldest to the more recent
* @param vreid vreid identifier ( scope )
* @return simply return a list of user vre post UUIDs in chronological order from the oldest to the more recent
* /
private ArrayList < String > getVREPostIds ( String vreid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( VRE_TIMELINE_POSTS ) . all ( )
. whereColumn ( VRE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( vreid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
List < String > toReturn = result . all ( ) . stream ( ) . map ( row - > {
try {
String postid = row . getUuid ( POST_ID ) . toString ( ) ;
return postid ;
} catch ( RuntimeException e ) {
throw new RuntimeException ( e ) ;
2022-09-20 17:00:25 +02:00
}
2023-10-30 18:52:02 +01:00
} ) . collect ( Collectors . toList ( ) ) ;
return ( ArrayList < String > ) toReturn ;
2022-09-20 17:00:25 +02:00
}
2013-01-10 14:19:53 +01:00
/ *
2023-10-30 18:52:02 +01:00
*
2013-01-10 14:19:53 +01:00
* * * * * * * * * * * * * * * * * * * * * * NOTIFICATIONS * * * * * * * * * * * * * * * * * * * * * * *
*
* /
/ * *
* { @inheritDoc }
* /
@Override
public boolean saveNotification ( Notification n ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
//notification entry
PreparedStatement stmt1 = createNotificationEntry ( session ) ;
writeBatch . add ( stmt1 . bind ( UUID . fromString ( n . getKey ( ) ) ,
n . getType ( ) . toString ( ) ,
n . getUserid ( ) ,
n . getSubjectid ( ) ,
n . getTime ( ) . toInstant ( ) ,
n . getDescription ( ) ,
n . getUri ( ) ,
n . getSenderid ( ) ,
n . getSenderFullName ( ) ,
n . getSenderThumbnail ( ) ,
n . isRead ( ) ) ) ;
//an entry in the user Notifications Timeline
PreparedStatement stmt2 = createUserNotificationsEntry ( session ) ;
writeBatch . add ( stmt2 . bind ( n . getUserid ( ) , n . getTime ( ) . toInstant ( ) , UUID . fromString ( n . getKey ( ) ) ) ) ;
2016-04-04 12:46:24 +02:00
2016-04-04 18:02:46 +02:00
// save key in the unread notifications column family too
2023-10-30 18:52:02 +01:00
PreparedStatement stmt3 = createUnreadNotificationEntry ( session ) ;
writeBatch . add ( stmt3 . bind ( n . getUserid ( ) , n . getTime ( ) . toInstant ( ) , UUID . fromString ( n . getKey ( ) ) ) ) ;
try {
boolean res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return res ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
}
2013-01-10 14:19:53 +01:00
}
2014-10-01 17:08:38 +02:00
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
public Notification readNotification ( String notificationid ) throws NotificationIDNotFoundException , NotificationTypeNotFoundException , ColumnNameNotFoundException {
Notification toReturn = new Notification ( ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
toReturn = findNotById ( notificationid , session ) . get ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2013-01-10 14:19:53 +01:00
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean setNotificationRead ( String notificationidToSet ) throws NotificationIDNotFoundException , NotificationTypeNotFoundException , ColumnNameNotFoundException {
Notification toSet = readNotification ( notificationidToSet ) ;
if ( toSet = = null )
throw new NotificationIDNotFoundException ( " The specified notification to set Read with id: " + notificationidToSet + " does not exist " ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
2016-04-04 18:02:46 +02:00
2023-10-30 18:52:02 +01:00
//update the entry in notifications
writeBatch . add ( updateNotificationEntry ( session , IS_READ ) . bind ( UUID . fromString ( notificationidToSet ) , true ) ) ;
2016-04-04 12:46:24 +02:00
2016-04-04 18:02:46 +02:00
// delete the notification's key from the unread notifications column family
2023-10-30 18:52:02 +01:00
writeBatch . add ( deleteUnreadNotEntry ( session ) . bind ( toSet . getUserid ( ) , toSet . getTime ( ) . toInstant ( ) ) ) ;
2016-04-04 12:46:24 +02:00
// execute the operations
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
boolean res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
return res ;
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
_log . error ( " ERROR while setting Notification " + notificationidToSet + " to read. " ) ;
return false ;
}
}
/ * *
2023-10-30 18:52:02 +01:00
*
2013-01-10 14:19:53 +01:00
* @param userid user identifier
* @return simply return a list of user notifications UUID in chronological order from the oldest to the more recent
* /
private ArrayList < String > getUserNotificationsIds ( String userid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_NOTIFICATIONS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
ArrayList < String > toReturn = new ArrayList < String > ( ) ;
2023-10-30 18:52:02 +01:00
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
toReturn . add ( row . getUuid ( NOT_ID ) . toString ( ) ) ;
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
2016-04-04 12:46:24 +02:00
/ * *
2016-04-04 18:02:46 +02:00
* Return a list of not read notifications by user userid ( messages as well as other notifications )
2016-04-04 12:46:24 +02:00
* @param userid user identifier
* @return simply return a list of not read user notifications UUID in chronological order from the oldest to the more recent
* /
private ArrayList < String > getUnreadUserNotificationsIds ( String userid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_NOTIFICATIONS_UNREAD ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2016-04-04 12:46:24 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2016-04-04 12:46:24 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2016-04-04 12:46:24 +02:00
}
ArrayList < String > toReturn = new ArrayList < String > ( ) ;
2023-10-30 18:52:02 +01:00
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
toReturn . add ( row . getUuid ( NOT_ID ) . toString ( ) ) ;
2016-04-04 12:46:24 +02:00
}
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2015-09-30 17:26:58 +02:00
public List < Notification > getAllNotificationByUser ( String userid , int limit ) throws NotificationTypeNotFoundException , ColumnNameNotFoundException {
2013-01-10 14:19:53 +01:00
ArrayList < Notification > toReturn = new ArrayList < Notification > ( ) ;
ArrayList < String > notificationsIDs = getUserNotificationsIds ( userid ) ;
//check if quantity is greater than user feeds
limit = ( limit > notificationsIDs . size ( ) ) ? notificationsIDs . size ( ) : limit ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2013-01-10 14:19:53 +01:00
for ( int i = notificationsIDs . size ( ) - 1 ; i > = ( notificationsIDs . size ( ) - limit ) ; i - - ) {
2015-09-30 17:26:58 +02:00
Notification toAdd = null ;
try {
toAdd = readNotification ( notificationsIDs . get ( i ) ) ;
toReturn . add ( toAdd ) ;
} catch ( NotificationIDNotFoundException e ) {
_log . error ( " Notification not found id= " + notificationsIDs . get ( i ) ) ;
}
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
return toReturn ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
public List < Notification > getUnreadNotificationsByUser ( String userid ) throws NotificationTypeNotFoundException , ColumnNameNotFoundException , NotificationIDNotFoundException {
ArrayList < Notification > toReturn = new ArrayList < Notification > ( ) ;
2016-04-04 12:46:24 +02:00
ArrayList < String > notificationsIDs = getUnreadUserNotificationsIds ( userid ) ;
2013-01-10 14:19:53 +01:00
2023-10-30 18:52:02 +01:00
//need them in reverse order
2013-01-10 14:19:53 +01:00
for ( int i = notificationsIDs . size ( ) - 1 ; i > = 0 ; i - - ) {
2016-04-04 12:46:24 +02:00
try {
toReturn . add ( readNotification ( notificationsIDs . get ( i ) ) ) ;
} catch ( Exception e ) {
_log . error ( " Unable to read notification with key " + notificationsIDs . get ( i ) ) ;
2013-01-10 14:19:53 +01:00
}
}
2016-04-04 12:46:24 +02:00
2023-10-30 18:52:02 +01:00
return toReturn ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2014-04-02 18:03:42 +02:00
public List < Notification > getRangeNotificationsByUser ( String userid , int from , int quantity ) throws NotificationTypeNotFoundException , ColumnNameNotFoundException , NotificationIDNotFoundException {
if ( from < 1 ) {
throw new IllegalArgumentException ( " From must be greather than 0 " ) ;
2023-10-30 18:52:02 +01:00
}
2014-04-02 18:03:42 +02:00
ArrayList < Notification > toReturn = new ArrayList < Notification > ( ) ;
ArrayList < String > notificationsIDs = getUserNotificationsIds ( userid ) ;
2014-05-05 16:26:18 +02:00
2014-04-02 18:03:42 +02:00
//if from is greater than feeds size return empty
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 ( ) ) ;
return new ArrayList < Notification > ( ) ;
}
2014-05-05 16:26:18 +02:00
2014-04-02 18:03:42 +02:00
int rangeStart = notificationsIDs . size ( ) - from ;
int rangeEnd = rangeStart - quantity ;
2014-05-05 16:26:18 +02:00
2014-04-02 18:03:42 +02:00
//check that you reached the end
if ( rangeEnd < 1 )
rangeEnd = 0 ;
2014-05-05 16:26:18 +02:00
2014-04-02 18:03:42 +02:00
_log . debug ( " BEFORE starting Point= " + rangeStart + " rangeEnd= " + rangeEnd ) ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2014-04-02 18:03:42 +02:00
for ( int i = rangeStart ; i > rangeEnd ; i - - ) {
Notification toAdd = readNotification ( notificationsIDs . get ( i ) ) ;
toReturn . add ( toAdd ) ;
}
2023-10-30 18:52:02 +01:00
return toReturn ;
2014-04-02 18:03:42 +02:00
}
/ * *
* { @inheritDoc }
* /
@Override
2015-09-30 17:26:58 +02:00
public boolean setAllNotificationReadByUser ( String userid ) throws NotificationTypeNotFoundException , ColumnNameNotFoundException {
2013-01-30 00:54:50 +01:00
2016-04-04 12:46:24 +02:00
// get the list of unread notifications
ArrayList < String > notificationsIDs = getUnreadUserNotificationsIds ( userid ) ;
2013-01-30 00:54:50 +01:00
for ( int i = notificationsIDs . size ( ) - 1 ; i > = 0 ; i - - ) {
2016-04-04 12:46:24 +02:00
try {
2016-04-04 18:02:46 +02:00
2016-04-04 12:46:24 +02:00
// set to read (and automatically remove from the unread column family)
setNotificationRead ( notificationsIDs . get ( i ) ) ;
2016-04-04 18:02:46 +02:00
2015-09-30 17:26:58 +02:00
} catch ( NotificationIDNotFoundException e ) {
_log . error ( " Could not set read notification with id = " + notificationsIDs . get ( i ) ) ;
2023-10-30 18:52:02 +01:00
}
2013-01-30 00:54:50 +01:00
}
2023-10-30 18:52:02 +01:00
return true ;
2013-01-30 00:54:50 +01:00
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2023-10-30 18:52:02 +01:00
public boolean checkUnreadNotifications ( String userid ) throws NotificationTypeNotFoundException , ColumnNameNotFoundException {
2013-01-10 14:19:53 +01:00
2016-04-04 18:02:46 +02:00
ArrayList < String > unreadNotifications = getUnreadUserNotificationsIds ( userid ) ;
for ( int i = unreadNotifications . size ( ) - 1 ; i > = 0 ; i - - ) {
Notification toAdd ;
try {
toAdd = readNotification ( unreadNotifications . get ( i ) ) ;
if ( toAdd . getType ( ) ! = NotificationType . MESSAGE )
return true ;
} catch ( NotificationIDNotFoundException e ) {
_log . error ( " Notification not found with id = " + unreadNotifications . get ( i ) ) ;
}
}
return false ;
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean checkUnreadMessagesNotifications ( String userid ) throws NotificationIDNotFoundException , NotificationTypeNotFoundException , ColumnNameNotFoundException {
2016-04-04 18:02:46 +02:00
ArrayList < String > unreadNotifications = getUnreadUserNotificationsIds ( userid ) ;
for ( int i = unreadNotifications . size ( ) - 1 ; i > = 0 ; i - - ) {
Notification toAdd ;
try {
toAdd = readNotification ( unreadNotifications . get ( i ) ) ;
if ( toAdd . getType ( ) = = NotificationType . MESSAGE )
return true ;
} catch ( NotificationIDNotFoundException e ) {
_log . error ( " Notification not found with id = " + unreadNotifications . get ( i ) ) ;
}
}
return false ;
2013-01-10 14:19:53 +01:00
}
2013-01-30 17:58:23 +01:00
/ *
2023-10-30 18:52:02 +01:00
*
2013-01-30 17:58:23 +01:00
* * * * * * * * * * * * * * * * * * * * * * NOTIFICATION SETTINGS * * * * * * * * * * * * * * * * * * * * * * *
*
* /
/ * *
* { @inheritDoc }
* /
@Override
2013-06-06 18:52:39 +02:00
public List < NotificationChannelType > getUserNotificationChannels ( String userid , NotificationType notificationType ) throws NotificationChannelTypeNotFoundException , NotificationTypeNotFoundException {
_log . trace ( " Asking for Single Notification preference of " + userid + " Type: " + notificationType ) ;
2013-01-30 17:58:23 +01:00
List < NotificationChannelType > toReturn = new ArrayList < NotificationChannelType > ( ) ;
2013-06-06 18:52:39 +02:00
NotificationChannelType [ ] toProcess = getUserNotificationPreferences ( userid ) . get ( notificationType ) ;
2013-06-10 16:38:35 +02:00
if ( toProcess = = null ) {
_log . warn ( " Single Notification preference of " + userid + " Type: " + notificationType + " not existing ... creating default " ) ;
return createNewNotificationType ( userid , notificationType ) ;
2014-05-05 16:26:18 +02:00
}
2023-10-30 18:52:02 +01:00
else if ( toProcess . length = = 0 )
2014-05-05 16:26:18 +02:00
return toReturn ;
else
2013-06-10 16:38:35 +02:00
for ( int i = 0 ; i < toProcess . length ; i + + ) {
toReturn . add ( toProcess [ i ] ) ;
}
return toReturn ;
}
/ * *
* called when you add new notification types where the setting does not exist yet
2014-03-05 00:39:43 +01:00
* please note : by default we set all notifications
2013-06-10 16:38:35 +02:00
* /
private List < NotificationChannelType > createNewNotificationType ( String userid , NotificationType notificationType ) {
List < NotificationChannelType > toReturn = new ArrayList < NotificationChannelType > ( ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2013-06-10 16:38:35 +02:00
String valueToInsert = " " ;
2014-03-05 00:39:43 +01:00
NotificationChannelType [ ] wpTypes = NotificationChannelType . values ( ) ;
2014-05-05 16:26:18 +02:00
2013-07-12 15:38:06 +02:00
for ( int i = 0 ; i < wpTypes . length ; i + + ) {
valueToInsert + = wpTypes [ i ] ;
if ( i < wpTypes . length - 1 )
2013-06-10 16:38:35 +02:00
valueToInsert + = " , " ;
2013-07-12 15:38:06 +02:00
toReturn . add ( wpTypes [ i ] ) ; //add the new added notification type
2013-06-10 16:38:35 +02:00
}
2023-10-30 18:52:02 +01:00
BatchStatement writeBatch = getBatch ( ) . add (
createNotificationPreferenceEntry ( session ) . bind ( userid , notificationType . toString ( ) , valueToInsert )
) ;
boolean res = false ;
try {
res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
if ( res ) {
2013-06-10 16:38:35 +02:00
_log . trace ( " Set New Notification Setting for " + userid + " OK " ) ;
2013-07-12 15:38:06 +02:00
return toReturn ;
}
return new ArrayList < NotificationChannelType > ( ) ; //no notification if sth fails
2013-01-30 17:58:23 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2013-06-06 18:52:39 +02:00
public boolean setUserNotificationPreferences ( String userid , Map < NotificationType , NotificationChannelType [ ] > enabledChannels ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
2013-01-30 17:58:23 +01:00
2013-06-03 18:12:13 +02:00
for ( NotificationType nType : enabledChannels . keySet ( ) ) {
String valueToInsert = " " ;
int channelsNo = ( enabledChannels . get ( nType ) ! = null ) ? enabledChannels . get ( nType ) . length : 0 ;
for ( int i = 0 ; i < channelsNo ; i + + ) {
valueToInsert + = enabledChannels . get ( nType ) [ i ] ;
if ( i < channelsNo - 1 )
valueToInsert + = " , " ;
}
2013-06-07 17:40:46 +02:00
if ( channelsNo = = 0 ) { //in case no channels were selected
valueToInsert = " " ;
_log . trace ( " No Channels selected for " + nType + " by " + userid ) ;
}
2023-10-30 18:52:02 +01:00
writeBatch . add ( createNotificationPreferenceEntry ( session ) . bind ( userid , nType . toString ( ) , valueToInsert ) ) ;
2013-01-30 17:58:23 +01:00
}
2013-06-07 12:28:09 +02:00
2023-10-30 18:52:02 +01:00
boolean overAllresult = session . execute ( writeBatch ) . wasApplied ( ) ;
2013-01-30 17:58:23 +01:00
if ( overAllresult )
2013-06-03 18:12:13 +02:00
_log . trace ( " Set Notification Map for " + userid + " OK " ) ;
2013-01-30 17:58:23 +01:00
else
2013-06-03 18:12:13 +02:00
_log . trace ( " Set Notification Map for " + userid + " FAILED " ) ;
2023-10-30 18:52:02 +01:00
return overAllresult ;
2013-01-30 17:58:23 +01:00
}
2013-06-06 18:52:39 +02:00
/ * *
* { @inheritDoc }
2023-10-30 18:52:02 +01:00
*
2013-07-11 17:26:20 +02:00
* by default Workspace and Calendar Notifications are set to Portal
2013-06-06 18:52:39 +02:00
* /
@Override
public Map < NotificationType , NotificationChannelType [ ] > getUserNotificationPreferences ( String userid ) throws NotificationTypeNotFoundException , NotificationChannelTypeNotFoundException {
_log . trace ( " Asking for Notification preferences of " + userid ) ;
Map < NotificationType , NotificationChannelType [ ] > toReturn = new HashMap < NotificationType , NotificationChannelType [ ] > ( ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_NOTIFICATIONS_PREFERENCES ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-06-06 18:52:39 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-06-06 18:52:39 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-06-06 18:52:39 +02:00
}
2023-10-30 18:52:02 +01:00
2013-06-06 18:52:39 +02:00
//if there are no settings for this user create an entry and put all of them at true
2023-10-30 18:52:02 +01:00
if ( result . all ( ) . isEmpty ( ) ) {
2013-06-06 18:52:39 +02:00
_log . info ( " Userid " + userid + " settings not found, initiating its preferences... " ) ;
HashMap < NotificationType , NotificationChannelType [ ] > toCreate = new HashMap < NotificationType , NotificationChannelType [ ] > ( ) ;
for ( int i = 0 ; i < NotificationType . values ( ) . length ; i + + ) {
2013-06-07 12:28:09 +02:00
//TODO: Potential bug in NotificationType for workspace are refactored
2014-03-05 00:39:43 +01:00
//create a map with all notification enabled except for workspace notifications (They start with WP_) it was the only quick way
2014-04-02 11:39:19 +02:00
if ( NotificationType . values ( ) [ i ] . toString ( ) . startsWith ( " WP_ " ) ) {
NotificationChannelType [ ] wpTypes = { NotificationChannelType . PORTAL } ;
toCreate . put ( NotificationType . values ( ) [ i ] , wpTypes ) ;
}
else
2013-06-07 12:28:09 +02:00
toCreate . put ( NotificationType . values ( ) [ i ] , NotificationChannelType . values ( ) ) ;
2013-06-06 18:52:39 +02:00
}
setUserNotificationPreferences ( userid , toCreate ) ; //commit the map
return toCreate ;
}
else {
_log . trace ( " Notification preferences Found for " + userid ) ;
2023-10-30 18:52:02 +01:00
for ( Row row : result . all ( ) ) {
String [ ] channels = row . getString ( PREFERENCE ) . split ( " , " ) ;
if ( channels ! = null & & channels . length = = 1 & & channels [ 0 ] . toString ( ) . equals ( " " ) ) { //it is empty, preference is set to no notification at all
toReturn . put ( getNotificationType ( row . getString ( TYPE ) ) , new NotificationChannelType [ 0 ] ) ;
} else {
NotificationChannelType [ ] toAdd = new NotificationChannelType [ channels . length ] ;
for ( int i = 0 ; i < channels . length ; i + + ) {
if ( channels [ i ] . compareTo ( " " ) ! = 0 ) {
toAdd [ i ] = ( getChannelType ( channels [ i ] ) ) ;
2014-05-05 16:26:18 +02:00
}
2013-06-06 18:52:39 +02:00
}
2023-10-30 18:52:02 +01:00
toReturn . put ( getNotificationType ( row . getString ( TYPE ) ) , toAdd ) ;
2013-06-06 18:52:39 +02:00
}
2023-10-30 18:52:02 +01:00
}
2013-06-06 18:52:39 +02:00
}
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ *
2023-10-30 18:52:02 +01:00
*
2013-01-10 14:19:53 +01:00
* * * * * * * * * * * * * * * * * * * * * * COMMENTS * * * * * * * * * * * * * * * * * * * * * * *
*
* /
/ * *
* { @inheritDoc }
* /
@Override
public boolean addComment ( Comment comment ) throws FeedIDNotFoundException {
Feed toComment = null ;
if ( comment = = null )
throw new NullArgumentException ( " Comment must be not null " ) ;
if ( comment . getFeedid ( ) = = null )
throw new NullArgumentException ( " Comment feed id must be not null " ) ;
2023-10-30 18:52:02 +01:00
String postid = comment . getFeedid ( ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
toComment = readFeed ( postid ) ;
2013-01-10 14:19:53 +01:00
if ( toComment = = null )
2023-10-30 18:52:02 +01:00
throw new FeedIDNotFoundException ( " Could not find Feed with id " + postid + " to associate this comment " , postid ) ;
2013-01-10 14:19:53 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
2023-10-30 18:52:02 +01:00
}
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
writeBatch . add ( createNewCommentEntry ( session ) . bind (
UUID . fromString ( comment . getKey ( ) ) ,
comment . getUserid ( ) ,
comment . getFullName ( ) ,
comment . getThumbnailURL ( ) ,
comment . getText ( ) ,
UUID . fromString ( comment . getFeedid ( ) ) ,
comment . getTime ( ) . toInstant ( ) ,
null
) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
return false ;
}
//update the comment count
boolean updateCommentNoResult = updateFeedCommentsCount ( toComment , true ) ;
return updateCommentNoResult ;
}
2016-02-02 11:57:17 +01:00
/ * *
* { @inheritDoc }
* /
public Comment readCommentById ( String commentId ) throws CommentIDNotFoundException {
2023-10-30 18:52:02 +01:00
Comment toReturn = null ;
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( COMMENTS ) . all ( )
. whereColumn ( COMMENT_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2016-02-02 11:57:17 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( UUID . fromString ( commentId ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
if ( result . all ( ) . isEmpty ( ) ) {
2016-02-02 11:57:17 +01:00
throw new CommentIDNotFoundException ( " The requested commentId: " + commentId + " is not existing " ) ;
}
2023-10-30 18:52:02 +01:00
toReturn = readCommentFromRow ( result . one ( ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
2016-02-02 11:57:17 +01:00
return toReturn ;
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
public List < Comment > getAllCommentByFeed ( String feedid ) {
2022-09-20 17:00:25 +02:00
return getAllCommentByPost ( feedid ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
public List < Comment > getAllCommentByPost ( String postid ) {
2023-10-30 18:52:02 +01:00
//possible error index
2013-01-10 14:19:53 +01:00
List < Comment > toReturn = new ArrayList < Comment > ( ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
2023-11-15 18:14:57 +01:00
PreparedStatement stmtFind = session . prepare ( " SELECT * FROM comments WHERE postid=? " ) ;
/ * PreparedStatement stmtFind = session . prepare ( QueryBuilder
2023-10-30 18:52:02 +01:00
. selectFrom ( COMMENTS ) . all ( )
2023-11-15 18:14:57 +01:00
. where
2023-10-30 18:52:02 +01:00
. whereColumn ( POST_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
2023-11-15 18:14:57 +01:00
. build ( ) ) ; * /
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( UUID . fromString ( postid ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
for ( Row row : result . all ( ) ) {
Comment toAdd = readCommentFromRow ( row ) ;
2013-01-10 14:19:53 +01:00
toReturn . add ( toAdd ) ;
}
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
2023-10-30 18:52:02 +01:00
2013-01-10 14:19:53 +01:00
return toReturn ;
}
2016-01-14 18:37:03 +01:00
2016-08-02 17:25:27 +02:00
/ * *
* { @inheritDoc }
2023-10-30 18:52:02 +01:00
* @throws Exception
2016-08-02 17:25:27 +02:00
* /
@Override
public List < Comment > getRecentCommentsByUserAndDate ( final String userid ,
final long timeInMillis ) throws Exception {
2016-08-03 10:08:51 +02:00
final List < Comment > commentsByUser ;
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
if ( userid = = null | | userid . isEmpty ( ) )
throw new IllegalArgumentException ( " the userId parameter cannot be null/empty " ) ;
commentsByUser = getRecentCommentsByUserAndDateBody ( userid , timeInMillis , true ) ;
2023-10-30 18:52:02 +01:00
return commentsByUser ; }
2016-08-03 10:08:51 +02:00
/ * *
* Private method that allows also to specify if the returned list must be sorted or not
* @param userid the user id
* @param timeInMillis the initial time to consider
* @param sort a boolean value to specify if the returned list must be sorted ( from the most recent to the oldest comment )
* @return a list of comments recently made by the user
* /
private List < Comment > getRecentCommentsByUserAndDateBody ( final String userid ,
2023-10-30 18:52:02 +01:00
final long timeInMillis , boolean sort ) {
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
//possible error
2016-08-02 17:25:27 +02:00
final List < Comment > commentsByUser = new ArrayList < Comment > ( ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( COMMENTS )
. all ( )
. build ( ) ) ;
try {
result = session . execute ( stmtFind . bind ( ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
if ( ! result . all ( ) . isEmpty ( ) ) {
result . all ( ) . parallelStream ( ) . forEach ( row - > {
if ( row . getString ( USER_ID ) . equals ( userid ) ) {
2016-08-06 08:19:53 +02:00
try {
2023-10-30 18:52:02 +01:00
Comment c = readCommentById ( row . getUuid ( COMMENT_ID ) . toString ( ) ) ;
Post p = readPost ( c . getFeedid ( ) ) ;
if ( c . getTime ( ) . getTime ( ) > = timeInMillis & &
( p . getType ( ) = = PostType . TWEET | | p . getType ( ) = = PostType . SHARE | | p . getType ( ) = = PostType . PUBLISH ) )
commentsByUser . add ( c ) ;
2016-08-06 08:19:53 +02:00
} catch ( Exception e ) {
2023-10-30 18:52:02 +01:00
_log . error ( " Unable to read comment with id " + row . getString ( COMMENT_ID ) , e ) ;
2016-08-02 17:25:27 +02:00
}
2016-08-05 15:44:29 +02:00
}
2016-08-06 08:19:53 +02:00
}
2023-10-30 18:52:02 +01:00
) ;
2016-08-02 17:25:27 +02:00
}
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2016-08-02 17:25:27 +02:00
2016-08-03 10:08:51 +02:00
if ( sort )
Collections . sort ( commentsByUser , Collections . reverseOrder ( ) ) ;
2016-08-02 17:25:27 +02:00
return commentsByUser ;
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean editComment ( Comment comment2Edit ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , CommentIDNotFoundException , FeedIDNotFoundException {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
writeBatch . add ( updateCommentEntry ( session , COMMENT ) . bind ( comment2Edit . getText ( ) , UUID . fromString ( comment2Edit . getKey ( ) ) ) )
. add ( updateCommentEntry ( session , IS_EDIT ) . bind ( comment2Edit . isEdit ( ) , UUID . fromString ( comment2Edit . getKey ( ) ) ) )
. add ( updateCommentEntry ( session , LAST_EDIT_TIME ) . bind ( comment2Edit . getTime ( ) . toInstant ( ) , UUID . fromString ( comment2Edit . getKey ( ) ) ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
boolean res = session . execute ( writeBatch ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
_log . info ( " Comments update OK to: " + comment2Edit . getText ( ) ) ;
return res ;
} catch ( Exception e ) {
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
_log . error ( " Comments update NOT OK " ) ;
return false ;
}
}
2016-01-14 18:37:03 +01:00
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean deleteComment ( String commentid , String feedid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , CommentIDNotFoundException , FeedIDNotFoundException {
Feed toUpdate = readFeed ( feedid ) ;
boolean updateCommentNoResult = false ;
updateCommentNoResult = updateFeedCommentsCount ( toUpdate , false ) ;
if ( updateCommentNoResult ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) . add ( deleteCommentEntry ( session ) . bind ( UUID . fromString ( commentid ) ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
_log . error ( " Comment Delete FAILED for " + commentid + " from Feed " + feedid ) ;
e . printStackTrace ( ) ;
}
_log . trace ( " Comment Deleted " + commentid + " from Feed " + feedid ) ;
}
return updateCommentNoResult ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean like ( Like like ) throws FeedIDNotFoundException {
Feed toLike = null ;
if ( like = = null )
throw new NullArgumentException ( " Like must be not null " ) ;
if ( like . getFeedid ( ) = = null )
throw new NullArgumentException ( " Like feed id must be not null " ) ;
String feedId = like . getFeedid ( ) ;
try {
toLike = readFeed ( feedId ) ;
if ( toLike = = null )
2017-01-25 16:38:50 +01:00
throw new FeedIDNotFoundException ( " Could not find Feed with id " + feedId + " to associate this like " , feedId ) ;
2013-01-10 14:19:53 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return false ;
2023-10-30 18:52:02 +01:00
}
if ( isPostLiked ( like . getUserid ( ) , feedId ) ) {
2015-07-16 16:27:33 +02:00
_log . info ( " User " + like . getUserid ( ) + " already liked Feed " + feedId ) ;
return true ;
}
else {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2015-07-16 16:27:33 +02:00
// Inserting data
//an entry in the feed CF
//and an entry in the UserLikesCF
2023-10-30 18:52:02 +01:00
BatchStatement writeBatch = getBatch ( )
. add ( createNewLikeEntry ( session ) . bind ( UUID . fromString ( like . getKey ( ) ) ,
like . getUserid ( ) ,
like . getFullName ( ) ,
like . getThumbnailURL ( ) ,
UUID . fromString ( like . getFeedid ( ) ) ,
like . getTime ( ) . toInstant ( ) ) )
. add ( createNewUserLikesEntry ( session ) . bind ( like . getUserid ( ) ,
UUID . fromString ( like . getKey ( ) ) ,
UUID . fromString ( like . getFeedid ( ) ) ) ) ;
2015-07-16 16:27:33 +02:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-07-16 16:27:33 +02:00
e . printStackTrace ( ) ;
return false ;
2023-10-30 18:52:02 +01:00
}
2015-07-16 16:27:33 +02:00
return updateFeedLikesCount ( toLike , true ) ;
}
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2014-04-08 23:36:51 +02:00
public boolean unlike ( String userid , String likeid , String feedid ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , LikeIDNotFoundException , FeedIDNotFoundException {
2013-01-10 14:19:53 +01:00
Feed toUpdate = readFeed ( feedid ) ;
boolean updateLikeNoResult = false ;
updateLikeNoResult = updateFeedLikesCount ( toUpdate , false ) ; //this remove 1 from the Feed CF LikeNO
if ( updateLikeNoResult ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) . add ( deleteLikeEntry ( session ) . bind ( UUID . fromString ( likeid ) ) )
. add ( deleteUserLikeEntry ( session ) . bind ( userid , UUID . fromString ( likeid ) ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
_log . error ( " Like Delete FAILED for " + likeid + " from Feed " + feedid ) ;
e . printStackTrace ( ) ;
}
_log . trace ( " Unlike ok for " + likeid + " from Feed " + feedid ) ;
}
return updateLikeNoResult ;
2023-10-30 18:52:02 +01:00
2013-01-10 14:19:53 +01:00
}
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 17:00:25 +02:00
@Deprecated
2013-01-10 14:19:53 +01:00
public List < String > getAllLikedFeedIdsByUser ( String userid ) {
2022-09-20 17:00:25 +02:00
return getAllLikedPostIdsByUser ( userid ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
public List < String > getAllLikedPostIdsByUser ( String userid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( USER_LIKED_POSTS ) . all ( )
. whereColumn ( USER_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( userid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
ArrayList < String > toReturn = new ArrayList < String > ( ) ;
2023-10-30 18:52:02 +01:00
for ( Row row : result ) {
toReturn . add ( row . getUuid ( POST_ID ) . toString ( ) ) ;
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
2013-02-02 18:21:56 +01:00
/ * *
2023-10-30 18:52:02 +01:00
* { @inheritDoc }
2013-02-02 18:21:56 +01:00
* /
@Override
public List < Feed > getAllLikedFeedsByUser ( String userid , int limit ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
2023-10-30 18:52:02 +01:00
ArrayList < Feed > toReturn = new ArrayList < > ( ) ;
List < String > likedPostIDs = getAllLikedPostIdsByUser ( userid ) ;
2013-02-02 18:21:56 +01:00
//check if quantity is greater than user feeds
2023-10-30 18:52:02 +01:00
limit = ( limit > likedPostIDs . size ( ) ) ? likedPostIDs . size ( ) : limit ;
2013-02-02 18:21:56 +01:00
2023-10-30 18:52:02 +01:00
//need them in reverse order
for ( int i = likedPostIDs . size ( ) - 1 ; i > = ( likedPostIDs . size ( ) - limit ) ; i - - ) {
Feed toAdd = readFeed ( likedPostIDs . get ( i ) ) ;
2013-02-02 18:21:56 +01:00
if ( toAdd . getType ( ) = = FeedType . TWEET | | toAdd . getType ( ) = = FeedType . SHARE | | toAdd . getType ( ) = = FeedType . PUBLISH ) {
toReturn . add ( toAdd ) ;
2023-10-30 18:52:02 +01:00
_log . trace ( " Read recent post: " + likedPostIDs . get ( i ) ) ;
2013-02-02 18:21:56 +01:00
} else {
2023-10-30 18:52:02 +01:00
_log . trace ( " Read and skipped post: " + likedPostIDs . get ( i ) + " (Removed post) " ) ;
2013-02-02 18:21:56 +01:00
limit + = 1 ; //increase the quantity in case of removed feed
//check if quantity is greater than user feeds
2023-10-30 18:52:02 +01:00
limit = ( limit > likedPostIDs . size ( ) ) ? likedPostIDs . size ( ) : limit ;
2013-02-02 18:21:56 +01:00
}
}
return toReturn ;
}
2022-09-20 17:00:25 +02:00
/ * *
2023-10-30 18:52:02 +01:00
* { @inheritDoc }
2022-09-20 17:00:25 +02:00
* /
@Override
public List < Post > getAllLikedPostsByUser ( String userid , int limit ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , ColumnNameNotFoundException , FeedIDNotFoundException {
ArrayList < Post > toReturn = new ArrayList < Post > ( ) ;
List < String > likedPostIDs = getAllLikedPostIdsByUser ( userid ) ;
//check if quantity is greater than user feeds
limit = ( limit > likedPostIDs . size ( ) ) ? likedPostIDs . size ( ) : limit ;
2023-10-30 18:52:02 +01:00
//need them in reverse order
2022-09-20 17:00:25 +02:00
for ( int i = likedPostIDs . size ( ) - 1 ; i > = ( likedPostIDs . size ( ) - limit ) ; i - - ) {
Post toAdd = readPost ( likedPostIDs . get ( i ) ) ;
if ( toAdd . getType ( ) = = PostType . TWEET | | toAdd . getType ( ) = = PostType . SHARE | | toAdd . getType ( ) = = PostType . PUBLISH ) {
toReturn . add ( toAdd ) ;
_log . trace ( " Read recent post: " + likedPostIDs . get ( i ) ) ;
} else {
_log . trace ( " Read and skipped post: " + likedPostIDs . get ( i ) + " (Removed post) " ) ;
limit + = 1 ; //increase the quantity in case of removed feed
//check if quantity is greater than user feeds
limit = ( limit > likedPostIDs . size ( ) ) ? likedPostIDs . size ( ) : limit ;
}
}
return toReturn ;
}
2013-02-02 18:21:56 +01:00
2016-08-02 17:25:27 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public List < Feed > getRecentLikedFeedsByUserAndDate ( String userid ,
long timeInMillis ) throws IllegalArgumentException {
2023-10-30 18:52:02 +01:00
List < Feed > toReturn = new ArrayList < > ( ) ;
2016-08-02 17:25:27 +02:00
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
if ( userid = = null | | userid . isEmpty ( ) )
throw new IllegalArgumentException ( " the userId parameter cannot be null/empty " ) ;
// get the list of liked feeds
2023-10-30 18:52:02 +01:00
List < String > likedPostsIdsByUser = getAllLikedFeedIdsByUser ( userid ) ;
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
if ( likedPostsIdsByUser ! = null & & ! likedPostsIdsByUser . isEmpty ( ) ) {
for ( int i = likedPostsIdsByUser . size ( ) - 1 ; i > = 0 ; i - - ) {
String postid = likedPostsIdsByUser . get ( i ) ;
2016-08-02 17:25:27 +02:00
try {
2023-10-30 18:52:02 +01:00
// retrieve the Post
Feed toCheck = readFeed ( postid ) ;
boolean isPostOk = ( toCheck . getType ( ) = = FeedType . TWEET | | toCheck . getType ( ) = = FeedType . SHARE | | toCheck . getType ( ) = = FeedType . PUBLISH ) ;
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
// retrieve the like of the user for the post
if ( isPostOk ) {
List < Like > likes = getAllLikesByFeed ( postid ) ;
2016-08-02 17:25:27 +02:00
for ( Like like : likes ) {
if ( like . getTime ( ) . getTime ( ) > = timeInMillis & & like . getUserid ( ) . equals ( userid ) )
toReturn . add ( toCheck ) ;
}
}
} catch ( Exception e ) {
2023-10-30 18:52:02 +01:00
_log . error ( " Skipped post with id " + postid , e ) ;
2016-08-02 17:25:27 +02:00
}
}
}
2023-10-30 18:52:02 +01:00
// please check consider that if a user made like recently to an old post, well it could happen that this
2016-08-02 17:25:27 +02:00
// post comes first than a newer post in the toReturn list. Thus we need to sort it.
Collections . sort ( toReturn , Collections . reverseOrder ( ) ) ;
return toReturn ;
2023-10-30 18:52:02 +01:00
2016-08-02 17:25:27 +02:00
}
2022-09-20 17:00:25 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public List < Post > getRecentLikedPostsByUserAndDate ( String userid ,
long timeInMillis ) throws IllegalArgumentException {
List < Post > toReturn = new ArrayList < > ( ) ;
Date now = new Date ( ) ;
if ( timeInMillis > now . getTime ( ) )
throw new IllegalArgumentException ( " the timeInMillis must be before today " ) ;
if ( userid = = null | | userid . isEmpty ( ) )
throw new IllegalArgumentException ( " the userId parameter cannot be null/empty " ) ;
// get the list of liked feeds
List < String > likedPostsIdsByUser = getAllLikedPostIdsByUser ( userid ) ;
if ( likedPostsIdsByUser ! = null & & ! likedPostsIdsByUser . isEmpty ( ) ) {
for ( int i = likedPostsIdsByUser . size ( ) - 1 ; i > = 0 ; i - - ) {
String postid = likedPostsIdsByUser . get ( i ) ;
try {
// retrieve the Post
Post toCheck = readPost ( postid ) ;
boolean isPostOk = ( toCheck . getType ( ) = = PostType . TWEET | | toCheck . getType ( ) = = PostType . SHARE | | toCheck . getType ( ) = = PostType . PUBLISH ) ;
// retrieve the like of the user for the post
if ( isPostOk ) {
List < Like > likes = getAllLikesByPost ( postid ) ;
for ( Like like : likes ) {
if ( like . getTime ( ) . getTime ( ) > = timeInMillis & & like . getUserid ( ) . equals ( userid ) )
toReturn . add ( toCheck ) ;
}
}
} catch ( Exception e ) {
_log . error ( " Skipped post with id " + postid , e ) ;
}
}
}
2023-10-30 18:52:02 +01:00
// please check consider that if a user made like recently to an old post, well it could happen that this
2022-09-20 17:00:25 +02:00
// post comes first than a newer post in the toReturn list. Thus we need to sort it.
Collections . sort ( toReturn , Collections . reverseOrder ( ) ) ;
return toReturn ;
}
2016-08-02 17:25:27 +02:00
2022-09-20 18:39:38 +02:00
/ * *
* { @inheritDoc }
* /
@Deprecated
@Override
public List < Like > getAllLikesByFeed ( String feedid ) {
return getAllLikesByPost ( feedid ) ;
}
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2022-09-20 18:39:38 +02:00
public List < Like > getAllLikesByPost ( String postid ) {
2023-10-30 18:52:02 +01:00
//possible error index
2013-01-10 14:19:53 +01:00
List < Like > toReturn = new ArrayList < Like > ( ) ;
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( LIKES ) . all ( )
. whereColumn ( POST_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2013-01-10 14:19:53 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( UUID . fromString ( postid ) ) ) ;
for ( Row row : result ) {
Like toAdd = readLikeFromRow ( row ) ;
2013-01-10 14:19:53 +01:00
toReturn . add ( toAdd ) ;
}
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
}
return toReturn ;
}
2014-10-01 17:27:03 +02:00
/ *
2023-10-30 18:52:02 +01:00
*
2014-10-01 17:27:03 +02:00
* * * * * * * * * * * * * * * * * * * * * * HASHTAGS * * * * * * * * * * * * * * * * * * * * * * *
*
* /
2013-01-10 14:19:53 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2014-10-01 17:08:38 +02:00
public boolean saveHashTags ( String feedid , String vreid , List < String > hashtags ) throws FeedIDNotFoundException {
2014-10-06 18:23:16 +02:00
Set < String > noduplicatesHashtags = null ;
if ( hashtags ! = null & & ! hashtags . isEmpty ( ) ) {
noduplicatesHashtags = new HashSet < String > ( hashtags ) ;
}
2014-10-01 17:08:38 +02:00
// Inserting data
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2014-10-06 18:23:16 +02:00
for ( String hashtag : noduplicatesHashtags ) {
2014-10-15 18:48:12 +02:00
String lowerCaseHashtag = hashtag . toLowerCase ( ) ;
2023-10-30 18:52:02 +01:00
boolean firstInsert = session . execute ( ( createNewHashtagTimelineEntry ( session ) . bind ( lowerCaseHashtag , UUID . fromString ( feedid ) , vreid ) ) ) . wasApplied ( ) ;
2014-10-15 18:48:12 +02:00
boolean secondInsert = updateVREHashtagCount ( vreid , lowerCaseHashtag , true ) ;
2014-10-01 17:08:38 +02:00
if ( ! ( firstInsert & & secondInsert ) ) {
2014-10-01 17:27:03 +02:00
_log . error ( " saveHashTags: Could not save the hashtag(s) " ) ;
2023-11-15 18:14:57 +01:00
2014-10-01 17:27:03 +02:00
return false ;
}
}
2023-11-15 18:14:57 +01:00
2014-10-01 17:27:03 +02:00
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean deleteHashTags ( String feedid , String vreid , List < String > hashtags ) throws FeedIDNotFoundException {
2014-10-06 18:23:16 +02:00
Set < String > noduplicatesHashtags = null ;
if ( hashtags ! = null & & ! hashtags . isEmpty ( ) ) {
noduplicatesHashtags = new HashSet < String > ( hashtags ) ;
}
2014-10-01 17:27:03 +02:00
// Inserting data
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2014-10-06 18:23:16 +02:00
for ( String hashtag : noduplicatesHashtags ) {
2014-10-15 18:48:12 +02:00
String lowerCaseHashtag = hashtag . toLowerCase ( ) ;
2023-10-30 18:52:02 +01:00
boolean firstDelete = session . execute ( deleteHashtagEntry ( session ) . bind ( lowerCaseHashtag , UUID . fromString ( feedid ) ) ) . wasApplied ( ) ;
2014-10-15 18:48:12 +02:00
boolean secondInsert = updateVREHashtagCount ( vreid , lowerCaseHashtag , false ) ;
2014-10-01 17:27:03 +02:00
if ( ! ( firstDelete & & secondInsert ) ) {
_log . error ( " deleteHashTags: Could not delete the hashtag(s) " ) ;
2023-11-15 18:14:57 +01:00
2014-10-01 17:08:38 +02:00
return false ;
2023-10-30 18:52:02 +01:00
2014-10-01 17:08:38 +02:00
}
}
2023-11-15 18:14:57 +01:00
2014-10-01 17:08:38 +02:00
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
2017-05-16 16:07:37 +02:00
public boolean saveHashTagsComment ( String commentId , String vreid , List < String > hashtags ) throws CommentIDNotFoundException {
Set < String > noduplicatesHashtags = null ;
if ( hashtags ! = null & & ! hashtags . isEmpty ( ) ) {
noduplicatesHashtags = new HashSet < String > ( hashtags ) ;
}
// Inserting datacommentIdcommentId
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2017-05-16 16:07:37 +02:00
for ( String hashtag : noduplicatesHashtags ) {
String lowerCaseHashtag = hashtag . toLowerCase ( ) ;
2023-10-30 18:52:02 +01:00
boolean firstInsert = session . execute ( createNewHashtagCommentEntry ( session ) . bind ( hashtag , UUID . fromString ( commentId ) , vreid ) ) . wasApplied ( ) ;
2017-05-16 16:07:37 +02:00
boolean secondInsert = false ;
if ( firstInsert )
secondInsert = updateVREHashtagCount ( vreid , lowerCaseHashtag , true ) ;
if ( ! ( firstInsert & & secondInsert ) ) {
_log . error ( " saveHashTags: Could not save the hashtag(s) " ) ;
2023-11-15 18:14:57 +01:00
2017-05-16 16:07:37 +02:00
return false ;
}
}
2023-11-15 18:14:57 +01:00
2017-05-16 16:07:37 +02:00
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean deleteHashTagsComment ( String commentId , String vreid , List < String > hashtags ) throws CommentIDNotFoundException {
Set < String > noduplicatesHashtags = null ;
if ( hashtags ! = null & & ! hashtags . isEmpty ( ) ) {
noduplicatesHashtags = new HashSet < String > ( hashtags ) ;
}
// Inserting data
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2017-05-16 16:07:37 +02:00
for ( String hashtag : noduplicatesHashtags ) {
String lowerCaseHashtag = hashtag . toLowerCase ( ) ;
2023-10-30 18:52:02 +01:00
boolean firstDelete = session . execute ( deleteHashtagCommentEntry ( session ) . bind ( lowerCaseHashtag , UUID . fromString ( commentId ) ) ) . wasApplied ( ) ;
2017-05-16 16:07:37 +02:00
if ( firstDelete ) {
boolean secondInsert = updateVREHashtagCount ( vreid , lowerCaseHashtag , false ) ;
if ( ! ( firstDelete & & secondInsert ) ) {
_log . error ( " deleteHashTags: Could not delete the hashtag(s) " ) ;
2023-11-15 18:14:57 +01:00
2017-05-16 16:07:37 +02:00
return false ;
}
} else {
_log . error ( " deleteHashTags: Could not delete the hashtag(s) " ) ;
2023-11-15 18:14:57 +01:00
2017-05-16 16:07:37 +02:00
return false ;
}
}
2023-11-15 18:14:57 +01:00
2017-05-16 16:07:37 +02:00
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
2014-10-01 17:08:38 +02:00
public Map < String , Integer > getVREHashtagsWithOccurrence ( String vreid ) {
2023-10-30 18:52:02 +01:00
ResultSet result = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGS_COUNTER ) . all ( )
. whereColumn ( VRE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2014-10-01 17:08:38 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( vreid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2014-10-01 17:08:38 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2014-10-01 17:08:38 +02:00
}
2023-10-30 18:52:02 +01:00
2014-10-01 17:08:38 +02:00
HashMap < String , Integer > toReturn = new HashMap < String , Integer > ( ) ;
2023-10-30 18:52:02 +01:00
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
Integer curValue = ( int ) row . getLong ( COUNT ) ;
if ( curValue > 0 )
toReturn . put ( row . getString ( HASHTAG ) , curValue ) ;
2014-10-01 17:08:38 +02:00
}
2023-10-30 18:52:02 +01:00
2014-10-01 17:08:38 +02:00
return toReturn ;
}
2016-05-10 12:14:46 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public Map < String , Integer > getVREHashtagsWithOccurrenceFilteredByTime ( String vreid , long timestamp ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGS_COUNTER ) . all ( )
. whereColumn ( VRE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2016-05-10 12:14:46 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( vreid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2016-05-10 12:14:46 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2016-05-10 12:14:46 +02:00
}
HashMap < String , Integer > toReturn = new HashMap < String , Integer > ( ) ;
2023-10-30 18:52:02 +01:00
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
// retrieve the feeds list for this hashtag
List < Post > feeds = null ;
try {
feeds = getVREPostsByHashtag ( vreid , row . getString ( HASHTAG ) ) ;
} catch ( Exception e ) {
_log . error ( " Unable to retrieve the list of feeds for hashtag " + row . getString ( HASHTAG ) + " in vre " + vreid ) ;
continue ;
}
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
if ( feeds . isEmpty ( ) ) {
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
_log . info ( " There are no feeds containing hashtag " + row . getString ( HASHTAG ) + " in vre " + vreid ) ;
continue ;
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
}
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
// retrieve the most recent one among these feeds
Collections . sort ( feeds , Collections . reverseOrder ( ) ) ;
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
if ( feeds . get ( 0 ) . getTime ( ) . getTime ( ) < timestamp ) {
continue ;
}
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
// else..
int curValue = ( int ) row . getLong ( COUNT ) ;
2016-08-02 17:25:27 +02:00
2023-10-30 18:52:02 +01:00
if ( curValue > 0 )
toReturn . put ( row . getString ( HASHTAG ) , curValue ) ;
2016-05-10 12:14:46 +02:00
}
return toReturn ;
}
2014-10-01 17:08:38 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public List < Feed > getVREFeedsByHashtag ( String vreid , String hashtag ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
2023-10-30 18:52:02 +01:00
List < Feed > toReturn = new ArrayList < > ( ) ;
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet resultPost = null ;
PreparedStatement stmtFind1 = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGGED_POSTS ) . all ( )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2014-10-01 17:08:38 +02:00
try {
2023-10-30 18:52:02 +01:00
resultPost = session . execute ( stmtFind1 . bind ( hashtag ) ) ;
} catch ( Exception e ) {
2014-10-01 17:08:38 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
PreparedStatement stmtFind2 = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGGED_COMMENTS ) . all ( )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet resultComment = null ;
2017-05-16 16:07:37 +02:00
try {
2023-10-30 18:52:02 +01:00
resultComment = session . execute ( stmtFind2 . bind ( hashtag ) ) ;
} catch ( Exception e ) {
2017-05-16 16:07:37 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
Set < String > postIds = new HashSet < > ( ) ;
2017-05-16 16:07:37 +02:00
// Iterate rows and their columns (feed)
2023-10-30 18:52:02 +01:00
for ( Row row : resultPost . all ( ) ) {
if ( row . getString ( VRE_ID ) . compareTo ( vreid ) = = 0 )
postIds . add ( row . getUuid ( POST_ID ) . toString ( ) ) ;
2014-10-01 17:08:38 +02:00
}
2017-05-16 16:07:37 +02:00
// Iterate rows and their columns (comments)
2023-10-30 18:52:02 +01:00
for ( Row row : resultComment . all ( ) ) {
if ( row . getString ( VRE_ID ) . compareTo ( vreid ) = = 0 ) {
try {
Comment c = readCommentById ( row . getUuid ( COMMENT_ID ) . toString ( ) ) ;
postIds . add ( c . getFeedid ( ) ) ;
} catch ( CommentIDNotFoundException e ) {
_log . warn ( " Failed to fetch comment with id " + row . getString ( COMMENT_ID ) ) ;
2017-05-16 16:07:37 +02:00
}
}
}
2023-10-30 18:52:02 +01:00
toReturn = getFeedsByIds ( new ArrayList < > ( postIds ) ) ;
2014-10-01 17:08:38 +02:00
return toReturn ;
}
2022-09-20 17:00:25 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public List < Post > getVREPostsByHashtag ( String vreid , String hashtag ) throws PrivacyLevelTypeNotFoundException , FeedTypeNotFoundException , FeedIDNotFoundException , ColumnNameNotFoundException {
List < Post > toReturn = new ArrayList < > ( ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet resultPost = null ;
PreparedStatement stmtFind1 = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGGED_POSTS ) . all ( )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
resultPost = session . execute ( stmtFind1 . bind ( hashtag ) ) ;
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
PreparedStatement stmtFind2 = session . prepare ( QueryBuilder
. selectFrom ( HASHTAGGED_COMMENTS ) . all ( )
. whereColumn ( HASHTAG )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet resultComment = null ;
2022-09-20 17:00:25 +02:00
try {
2023-10-30 18:52:02 +01:00
resultComment = session . execute ( stmtFind2 . bind ( hashtag ) ) ;
} catch ( Exception e ) {
2022-09-20 17:00:25 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2022-09-20 17:00:25 +02:00
Set < String > postIds = new HashSet < > ( ) ;
// Iterate rows and their columns (feed)
2023-10-30 18:52:02 +01:00
for ( Row row : resultPost . all ( ) ) {
if ( row . getString ( VRE_ID ) . compareTo ( vreid ) = = 0 )
postIds . add ( row . getUuid ( POST_ID ) . toString ( ) ) ;
2022-09-20 17:00:25 +02:00
}
// Iterate rows and their columns (comments)
2023-10-30 18:52:02 +01:00
for ( Row row : resultComment . all ( ) ) {
if ( row . getString ( VRE_ID ) . compareTo ( vreid ) = = 0 ) {
try {
Comment c = readCommentById ( row . getUuid ( COMMENT_ID ) . toString ( ) ) ;
postIds . add ( c . getFeedid ( ) ) ;
} catch ( CommentIDNotFoundException e ) {
_log . warn ( " Failed to fetch comment with id " + row . getString ( COMMENT_ID ) ) ;
2022-09-20 17:00:25 +02:00
}
}
}
2023-10-30 18:52:02 +01:00
toReturn = getPostsByIds ( new ArrayList < > ( postIds ) ) ;
2022-09-20 17:00:25 +02:00
return toReturn ;
}
2015-06-25 18:25:37 +02:00
/ *
2023-10-30 18:52:02 +01:00
*
2015-06-25 18:25:37 +02:00
* * * * * * * * * * * * * * * * * * * * * * Invites * * * * * * * * * * * * * * * * * * * * * * *
*
* /
/ * *
2016-01-14 18:37:03 +01:00
* common part to save a invite
* @param invite
2015-06-25 18:25:37 +02:00
* @return the partial mutation batch instance
* /
2023-10-30 18:52:02 +01:00
private BatchStatement initSaveInvite ( Invite invite , CqlSession session ) {
BatchStatement writeBatch = getBatch ( ) ;
2015-06-25 18:25:37 +02:00
if ( invite = = null )
throw new NullArgumentException ( " Invite instance is null " ) ;
// Inserting data
2023-10-30 18:52:02 +01:00
writeBatch . add ( createNewInviteEntry ( session ) . bind (
UUID . fromString ( invite . getKey ( ) ) ,
invite . getSenderUserId ( ) ,
invite . getVreid ( ) ,
invite . getInvitedEmail ( ) ,
invite . getControlCode ( ) ,
invite . getStatus ( ) . toString ( ) ,
invite . getTime ( ) . toInstant ( ) ,
invite . getSenderFullName ( )
) ) ;
return writeBatch ;
2015-06-25 18:25:37 +02:00
}
2015-06-29 17:49:49 +02:00
2015-06-25 18:25:37 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public String isExistingInvite ( String vreid , String email ) {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind1 = session . prepare ( QueryBuilder
. selectFrom ( EMAIL_INVITES ) . all ( )
. whereColumn ( EMAIL )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2015-06-25 18:25:37 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind1 . bind ( email ) ) ;
} catch ( Exception e ) {
2015-06-25 18:25:37 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
if ( row . getString ( VRE_ID ) . compareTo ( vreid ) = = 0 )
return row . getUuid ( INVITE_ID ) . toString ( ) ;
2015-06-25 18:25:37 +02:00
}
return null ;
}
/ * *
* { @inheritDoc }
* /
@Override
2015-06-30 12:15:18 +02:00
public InviteOperationResult saveInvite ( Invite invite ) throws AddressException {
2015-06-25 18:25:37 +02:00
if ( invite = = null )
throw new NullArgumentException ( " Invite instance is null " ) ;
String email = invite . getInvitedEmail ( ) ;
if ( ! verifyEmail ( email ) )
throw new AddressException ( " Email is not valid -> " + email ) ;
if ( invite . getVreid ( ) = = null | | invite . getVreid ( ) . equals ( " " ) )
throw new NullArgumentException ( " VREId is null or empty " ) ;
_log . debug ( " isExistingInvite? " + invite . getInvitedEmail ( ) + " in " + invite . getVreid ( ) ) ;
if ( isExistingInvite ( invite . getVreid ( ) , invite . getInvitedEmail ( ) ) ! = null )
return InviteOperationResult . ALREADY_INVITED ;
_log . debug ( " Invite not found, proceed to save it ... " ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement m = initSaveInvite ( invite , session ) ;
//an entry in the VRE Invites
m . add ( createNewVreInviteEntry ( session ) . bind ( invite . getVreid ( ) , UUID . fromString ( invite . getKey ( ) ) , InviteStatus . PENDING . toString ( ) ) ) ;
//an entry in the EMAIL Invites
m . add ( createNewEmailInviteEntry ( session ) . bind ( email , invite . getVreid ( ) , UUID . fromString ( invite . getKey ( ) ) ) ) ;
boolean result = session . execute ( m ) . wasApplied ( ) ;
2023-11-15 18:14:57 +01:00
2015-06-25 18:25:37 +02:00
return result ? InviteOperationResult . SUCCESS : InviteOperationResult . FAILED ;
}
/ * *
* { @inheritDoc }
* /
@Override
public Invite readInvite ( String inviteid ) throws InviteIDNotFoundException , InviteStatusNotFoundException {
2023-10-30 18:52:02 +01:00
Invite toReturn = null ;
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( INVITES ) . all ( )
. whereColumn ( INVITE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2015-06-25 18:25:37 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( UUID . fromString ( inviteid ) ) ) ;
if ( result . one ( ) = = null ) {
2015-06-25 18:25:37 +02:00
throw new InviteStatusNotFoundException ( " The requested inviteid: " + inviteid + " is not existing " ) ;
}
2023-10-30 18:52:02 +01:00
toReturn = readAInviteFromRow ( result . one ( ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-06-25 18:25:37 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2015-06-25 18:25:37 +02:00
return toReturn ;
}
2015-06-29 17:49:49 +02:00
/ * *
* helper method that retrieve all the Invites belonging to a list of Ids
* @param inviteIds the lisf of invites UUID
* @return all the invites belonging to a list of Ids
2023-10-30 18:52:02 +01:00
* @throws InviteIDNotFoundException
* @throws InviteStatusNotFoundException
2015-06-29 17:49:49 +02:00
* /
private List < Invite > getInvitesById ( List < String > inviteIds ) throws InviteIDNotFoundException , InviteStatusNotFoundException {
ArrayList < Invite > toReturn = new ArrayList < Invite > ( ) ;
2023-10-30 18:52:02 +01:00
for ( String inviteid : inviteIds )
2015-06-29 17:49:49 +02:00
toReturn . add ( readInvite ( inviteid ) ) ;
return toReturn ;
}
2015-06-25 18:25:37 +02:00
/ * *
* { @inheritDoc }
2023-10-30 18:52:02 +01:00
* @throws InviteStatusNotFoundException
2015-06-25 18:25:37 +02:00
* /
@Override
public boolean setInviteStatus ( String vreid , String email , InviteStatus status ) throws InviteIDNotFoundException , InviteStatusNotFoundException {
String inviteid = isExistingInvite ( vreid , email ) ;
Invite toSet = readInvite ( inviteid ) ;
if ( toSet = = null )
throw new InviteIDNotFoundException ( " The specified invite to set with id: " + inviteid + " does not exist " ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
BatchStatement writeBatch = getBatch ( ) ;
2015-06-25 18:25:37 +02:00
//update in the Invites Static CF
//updated in the VREInvites Dynamic CF
2023-10-30 18:52:02 +01:00
writeBatch . add ( updateInviteEntry ( session , STATUS ) . bind ( status . toString ( ) , UUID . fromString ( inviteid ) ) )
. add ( updateVreInviteEntry ( session , STATUS ) . bind ( status . toString ( ) , vreid , UUID . fromString ( inviteid ) ) ) ;
2015-06-25 18:25:37 +02:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-06-25 18:25:37 +02:00
_log . error ( " ERROR while setting Invite " + inviteid + " to " + status . toString ( ) ) ;
2023-11-15 18:14:57 +01:00
2015-06-25 18:25:37 +02:00
return false ;
}
_log . trace ( " Invite Status Set to " + status . toString ( ) + " OK " ) ;
return true ;
}
/ * *
* { @inheritDoc }
* /
@Override
2015-06-29 17:49:49 +02:00
public List < Invite > getInvitedEmailsByVRE ( String vreid , InviteStatus . . . status ) throws InviteIDNotFoundException , InviteStatusNotFoundException {
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( VRE_INVITES ) . all ( )
. whereColumn ( VRE_ID )
. isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
2015-06-29 17:49:49 +02:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( vreid ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2015-06-29 17:49:49 +02:00
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2015-06-29 17:49:49 +02:00
ArrayList < String > invitesIds = new ArrayList < String > ( ) ;
2023-10-30 18:52:02 +01:00
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
2015-06-29 17:49:49 +02:00
if ( status ! = null ) {
2023-10-30 18:52:02 +01:00
for ( int i = 0 ; i < status . length ; i + + ) {
if ( row . getString ( STATUS ) . compareTo ( status [ i ] . toString ( ) ) = = 0 )
invitesIds . add ( row . getUuid ( INVITE_ID ) . toString ( ) ) ;
2015-06-29 17:49:49 +02:00
}
}
else {
2023-10-30 18:52:02 +01:00
invitesIds . add ( row . getUuid ( INVITE_ID ) . toString ( ) ) ;
2015-06-29 17:49:49 +02:00
}
}
return getInvitesById ( invitesIds ) ;
2015-06-25 18:25:37 +02:00
}
2014-10-01 17:08:38 +02:00
/ * *
* { @inheritDoc }
* /
@Override
2016-01-15 17:07:44 +01:00
public List < Attachment > getAttachmentsByFeedId ( String feedId ) throws FeedIDNotFoundException {
2023-10-30 18:52:02 +01:00
//index error
Post toCheck = null ;
2016-01-15 17:07:44 +01:00
try {
2023-10-30 18:52:02 +01:00
toCheck = readPost ( feedId ) ;
2016-01-15 17:07:44 +01:00
if ( toCheck = = null )
2017-01-25 16:38:50 +01:00
throw new FeedIDNotFoundException ( " Could not find Feed with id " + feedId , feedId ) ;
2016-01-15 17:07:44 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return null ;
2023-10-30 18:52:02 +01:00
}
2016-01-15 17:07:44 +01:00
List < Attachment > toReturn = new ArrayList < Attachment > ( ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( ATTACHMENTS ) . all ( )
. whereColumn ( POST_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
ResultSet result = null ;
2016-01-15 17:07:44 +01:00
try {
2023-10-30 18:52:02 +01:00
result = session . execute ( stmtFind . bind ( UUID . fromString ( feedId ) ) ) ;
// Iterate rows and their columns
for ( Row row : result . all ( ) ) {
_log . trace ( " Reading attachment if feed= " + row . getUuid ( POST_ID ) . toString ( ) ) ;
Attachment toAdd = readAttachmentFromRow ( row ) ;
2016-01-15 17:07:44 +01:00
toReturn . add ( toAdd ) ;
}
2023-11-15 18:14:57 +01:00
2016-01-15 17:07:44 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2016-01-15 17:07:44 +01:00
return null ;
}
return toReturn ;
}
/ * *
* { @inheritDoc }
* /
@Override
2013-01-10 14:19:53 +01:00
public void closeConnection ( ) {
2016-07-09 17:54:33 +02:00
conn . closeConnection ( ) ;
2013-01-10 14:19:53 +01:00
}
/ *
*
* * * * * * * * * * * * * * * * * * * * * * Helper methods * * * * * * * * * * * * * * * * * * * * * * *
*
* /
2016-01-14 18:37:03 +01:00
/ * *
* @param feedId the feedId to which the attachment is attached
* @param toSave the instance to save
* @return true if the attachemnt entry is saved in the Attachments CF
* /
private boolean saveAttachmentEntry ( String feedId , Attachment toSave ) {
// Inserting data
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2016-01-14 18:37:03 +01:00
//an entry in the Attachment CF
try {
2023-10-30 18:52:02 +01:00
session . execute ( createNewaAttachEntry ( session ) . bind (
UUID . fromString ( toSave . getId ( ) ) ,
UUID . fromString ( feedId ) ,
toSave . getUri ( ) ,
toSave . getName ( ) ,
toSave . getDescription ( ) ,
toSave . getThumbnailURL ( ) ,
toSave . getMimeType ( )
) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2023-11-15 18:14:57 +01:00
2016-01-14 18:37:03 +01:00
e . printStackTrace ( ) ;
return false ;
}
return true ;
}
2013-01-10 14:19:53 +01:00
2013-01-30 17:58:23 +01:00
/ * *
* simply return an enum representing the privacy level
* @return correct enum representing the privacy level
* @throws NotificationChannelTypeNotFoundException
* @throws FeedTypeNotFoundException
* /
private 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
2013-01-31 01:31:42 +01:00
throw new NotificationChannelTypeNotFoundException ( " The Notification Channel Type was not recognized should be one of " + NotificationChannelType . values ( ) + " asked for: " + channelName ) ;
2013-01-30 17:58:23 +01:00
}
2013-02-02 18:21:56 +01:00
2013-01-10 14:19:53 +01:00
/ * *
* simply return an enum representing the privacy level
* @param privacyLevel .
* @return correct enum representing the privacy level
* @throws FeedTypeNotFoundException
* /
2023-10-30 18:52:02 +01:00
private static PrivacyLevel getPrivacyLevel ( String privacyLevel ) throws PrivacyLevelTypeNotFoundException {
2013-01-10 14:19:53 +01:00
if ( privacyLevel . compareTo ( " CONNECTION " ) = = 0 )
return PrivacyLevel . CONNECTION ;
else if ( privacyLevel . compareTo ( " PRIVATE " ) = = 0 )
return PrivacyLevel . PRIVATE ;
else if ( privacyLevel . compareTo ( " PUBLIC " ) = = 0 )
return PrivacyLevel . PUBLIC ;
else if ( privacyLevel . compareTo ( " VRES " ) = = 0 )
return PrivacyLevel . VRES ;
else if ( privacyLevel . compareTo ( " SINGLE_VRE " ) = = 0 )
return PrivacyLevel . SINGLE_VRE ;
else if ( privacyLevel . compareTo ( " PORTAL " ) = = 0 )
return PrivacyLevel . PORTAL ;
else
throw new PrivacyLevelTypeNotFoundException ( " The Privacy Level was not recognized should be one of " + PrivacyLevel . values ( ) + " asked for: " + privacyLevel ) ;
}
/ * *
* simply return an enum representing the feed type
* @param type .
* @return correct enum representing the feed type
2023-10-30 18:52:02 +01:00
* @throws FeedTypeNotFoundException .
2013-01-10 14:19:53 +01:00
* /
2023-10-30 18:52:02 +01:00
private static FeedType getFeedType ( String type ) throws FeedTypeNotFoundException {
2013-01-10 14:19:53 +01:00
if ( type . compareTo ( " TWEET " ) = = 0 ) {
return FeedType . TWEET ;
}
else if ( type . compareTo ( " JOIN " ) = = 0 ) {
return FeedType . JOIN ;
}
else if ( type . compareTo ( " PUBLISH " ) = = 0 ) {
return FeedType . PUBLISH ;
}
else if ( type . compareTo ( " SHARE " ) = = 0 ) {
return FeedType . SHARE ;
}
else if ( type . compareTo ( " ACCOUNTING " ) = = 0 ) {
return FeedType . ACCOUNTING ;
}
else if ( type . compareTo ( " DISABLED " ) = = 0 ) {
return FeedType . DISABLED ;
}
else
throw new FeedTypeNotFoundException ( " The Feed Type was not recognized should be one of " + FeedType . values ( ) + " asked for: " + type ) ;
}
2022-09-20 17:00:25 +02:00
/ * *
* simply return an enum representing the feed type
* @param type .
* @return correct enum representing the feed type
2023-10-30 18:52:02 +01:00
* @throws FeedTypeNotFoundException .
2022-09-20 17:00:25 +02:00
* /
2023-10-30 18:52:02 +01:00
private static PostType getPostType ( String type ) throws FeedTypeNotFoundException {
2022-09-20 17:00:25 +02:00
if ( type . compareTo ( " TWEET " ) = = 0 ) {
return PostType . TWEET ;
}
else if ( type . compareTo ( " JOIN " ) = = 0 ) {
return PostType . JOIN ;
}
else if ( type . compareTo ( " PUBLISH " ) = = 0 ) {
return PostType . PUBLISH ;
}
else if ( type . compareTo ( " SHARE " ) = = 0 ) {
return PostType . SHARE ;
}
else if ( type . compareTo ( " ACCOUNTING " ) = = 0 ) {
return PostType . ACCOUNTING ;
}
else if ( type . compareTo ( " DISABLED " ) = = 0 ) {
return PostType . DISABLED ;
}
else
throw new FeedTypeNotFoundException ( " The Feed Type was not recognized should be one of " + PostType . values ( ) + " asked for: " + type ) ;
}
2015-06-29 17:49:49 +02:00
2015-06-25 18:25:37 +02:00
/ * *
* simply return an enum representing the invite status type
* @param type .
* @return correct enum representing the feed type
2023-10-30 18:52:02 +01:00
* @throws InviteStatusNotFoundException .
2015-06-25 18:25:37 +02:00
* /
2023-10-30 18:52:02 +01:00
private static InviteStatus getInviteStatusType ( String type ) throws InviteStatusNotFoundException {
2015-06-29 17:49:49 +02:00
switch ( type ) {
case " PENDING " :
2015-06-25 18:25:37 +02:00
return InviteStatus . PENDING ;
2015-06-29 17:49:49 +02:00
case " ACCEPTED " :
2015-06-25 18:25:37 +02:00
return InviteStatus . ACCEPTED ;
2015-06-29 17:49:49 +02:00
case " REJECTED " :
2015-06-25 18:25:37 +02:00
return InviteStatus . REJECTED ;
2015-06-29 17:49:49 +02:00
case " RETRACTED " :
return InviteStatus . RETRACTED ;
default :
2015-06-25 18:25:37 +02:00
throw new InviteStatusNotFoundException ( " The Invite Status was not recognized should be one of " + InviteStatus . values ( ) + " asked for: " + type ) ;
2015-06-29 17:49:49 +02:00
}
2015-06-25 18:25:37 +02:00
}
2013-01-10 14:19:53 +01:00
/ * *
* simply return an enum representing the feed type
* @param type .
* @return correct enum representing the feed type
2023-10-30 18:52:02 +01:00
* @throws NotificationTypeNotFoundException .
2013-01-10 14:19:53 +01:00
* /
2023-10-30 18:52:02 +01:00
private static NotificationType getNotificationType ( String type ) throws NotificationTypeNotFoundException {
2013-01-10 14:19:53 +01:00
if ( type . compareTo ( " WP_FOLDER_SHARE " ) = = 0 ) {
return NotificationType . WP_FOLDER_SHARE ;
}
2014-09-29 16:45:48 +02:00
else if ( type . compareTo ( " WP_FOLDER_UNSHARE " ) = = 0 ) {
return NotificationType . WP_FOLDER_UNSHARE ;
}
2014-09-30 12:36:27 +02:00
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 ;
}
2013-03-27 11:02:24 +01:00
else if ( type . compareTo ( " WP_FOLDER_RENAMED " ) = = 0 ) {
return NotificationType . WP_FOLDER_RENAMED ;
}
2013-01-10 14:19:53 +01:00
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 ;
}
2013-03-27 11:02:24 +01:00
else if ( type . compareTo ( " WP_ITEM_RENAMED " ) = = 0 ) {
return NotificationType . WP_ITEM_RENAMED ;
}
2013-01-10 14:19:53 +01:00
else if ( type . compareTo ( " OWN_COMMENT " ) = = 0 ) {
return NotificationType . OWN_COMMENT ;
}
else if ( type . compareTo ( " COMMENT " ) = = 0 ) {
return NotificationType . COMMENT ;
}
2013-04-18 11:16:04 +02:00
else if ( type . compareTo ( " MENTION " ) = = 0 ) {
return NotificationType . MENTION ;
}
2013-01-10 14:19:53 +01:00
else if ( type . compareTo ( " LIKE " ) = = 0 ) {
return NotificationType . LIKE ;
}
2013-07-11 17:26:20 +02:00
else if ( type . compareTo ( " CALENDAR_ADDED_EVENT " ) = = 0 ) {
return NotificationType . CALENDAR_ADDED_EVENT ;
2013-07-12 15:38:06 +02:00
}
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 ;
2013-07-11 17:26:20 +02:00
}
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 ;
}
2013-01-10 14:19:53 +01:00
else if ( type . compareTo ( " MESSAGE " ) = = 0 ) {
return NotificationType . MESSAGE ;
}
2014-03-05 00:39:43 +01:00
else if ( type . compareTo ( " POST_ALERT " ) = = 0 ) {
return NotificationType . POST_ALERT ;
}
2013-01-10 14:19:53 +01:00
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 ;
}
2016-09-26 14:14:35 +02:00
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 ;
}
2015-06-15 14:05:18 +02:00
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 ;
}
2015-06-16 16:58:06 +02:00
else if ( type . compareTo ( " TDM_TEMPLATE_SHARE " ) = = 0 ) {
2015-06-15 14:05:18 +02:00
return NotificationType . TDM_TEMPLATE_SHARE ;
}
2022-05-06 17:15:00 +02:00
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 ;
}
2013-01-10 14:19:53 +01:00
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 ) ;
}
/ * *
*
* @param time in milliseconds
* @return a Date object
* /
private Date getDateFromTimeInMillis ( String time ) {
Long timeInMillis = Long . parseLong ( time ) ;
Calendar toSet = Calendar . getInstance ( ) ;
toSet . setTimeInMillis ( timeInMillis ) ;
return toSet . getTime ( ) ;
}
/ * *
* update the feed by incrementing or decrementing by ( 1 ) the CommentsNo
* used when adding or removing a comment to a feed
* @param toUpdate the feedid
* @param increment set true if you want to add 1 , false to subtract 1 .
* /
private boolean updateFeedCommentsCount ( Feed toUpdate , boolean increment ) {
int newCount = 0 ;
2023-10-30 18:52:02 +01:00
try {
2013-01-10 14:19:53 +01:00
int current = Integer . parseInt ( toUpdate . getCommentsNo ( ) ) ;
newCount = increment ? current + 1 : current - 1 ;
}
catch ( NumberFormatException e ) {
_log . error ( " Comments Number found is not a number: " + toUpdate . getCommentsNo ( ) ) ;
}
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2013-01-10 14:19:53 +01:00
//an entry in the feed CF
try {
2023-10-30 18:52:02 +01:00
session . execute ( updatePostEntry ( session , COMMENTS_NO ) . bind ( ( long ) newCount , UUID . fromString ( toUpdate . getKey ( ) ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
_log . error ( " CommentsNo update NOT OK " ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
return false ;
}
_log . info ( " CommentsNo update OK to: " + newCount ) ;
return true ;
}
/ * *
* update the feed by incrementing or decrementing by ( 1 ) the LikesNo
* used when adding or removing a comment to a feed
* @param toUpdate the feedid
* @param increment set true if you want to add 1 , false to subtract 1 .
* /
private boolean updateFeedLikesCount ( Feed toUpdate , boolean increment ) {
int newCount = 0 ;
2023-10-30 18:52:02 +01:00
try {
2013-01-10 14:19:53 +01:00
int current = Integer . parseInt ( toUpdate . getLikesNo ( ) ) ;
newCount = increment ? current + 1 : current - 1 ;
}
catch ( NumberFormatException e ) {
_log . error ( " Likes Number found is not a number: " + toUpdate . getLikesNo ( ) ) ;
}
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
2013-01-10 14:19:53 +01:00
//an entry in the feed CF
try {
2023-10-30 18:52:02 +01:00
session . execute ( updatePostEntry ( session , LIKES_NO ) . bind ( ( long ) newCount , UUID . fromString ( toUpdate . getKey ( ) ) ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2013-01-10 14:19:53 +01:00
_log . error ( " LikesNo update NOT OK " ) ;
2023-11-15 18:14:57 +01:00
2013-01-10 14:19:53 +01:00
return false ;
}
_log . info ( " LikesNo update OK to: " + newCount ) ;
return true ;
}
2013-06-07 12:28:09 +02:00
2014-10-01 17:08:38 +02:00
/ * *
2023-10-30 18:52:02 +01:00
* update the hashtag count by incrementing or decrementing it by ( 1 )
2014-10-01 17:08:38 +02:00
* used when adding or removing a hashtag in a feed
* @param vreid the vreid
* @param hashtag the hashtag
* @param increment set true if you want to add 1 , false to subtract 1 .
* /
private boolean updateVREHashtagCount ( String vreid , String hashtag , boolean increment ) {
Map < String , Integer > vreHashtags = getVREHashtagsWithOccurrence ( vreid ) ;
2023-10-30 18:52:02 +01:00
//if the hashtag not yet exist
2014-10-01 17:08:38 +02:00
int newCount = 0 ;
if ( ! vreHashtags . containsKey ( hashtag ) ) {
newCount = 1 ;
}
else {
2023-10-30 18:52:02 +01:00
try {
2014-10-01 17:08:38 +02:00
int current = vreHashtags . get ( hashtag ) ;
newCount = increment ? current + 1 : current - 1 ;
}
catch ( NumberFormatException e ) {
_log . error ( " Hashtag Number found is not a number: " + newCount ) ;
}
}
2014-10-06 18:53:11 +02:00
_log . debug ( " Updating counter for " + hashtag + " to " + newCount ) ;
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
PreparedStatement stmt ;
BatchStatement writeBatch = getBatch ( ) ;
if ( existRecordbyCompId ( session , HASHTAG , VRE_ID , hashtag , vreid , HASHTAGS_COUNTER ) ) {
stmt = session . prepare ( QueryBuilder . update ( HASHTAGS_COUNTER )
. setColumn ( COUNT , QueryBuilder . bindMarker ( ) )
. whereColumn ( HASHTAG ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. whereColumn ( VRE_ID ) . isEqualTo ( QueryBuilder . bindMarker ( ) )
. build ( ) ) ;
writeBatch . add ( stmt . bind ( ( long ) newCount , hashtag , vreid ) ) ;
}
else {
stmt = createNewUHashtagCounterEntry ( session ) ;
writeBatch . add ( stmt . bind ( vreid , hashtag , ( long ) newCount ) ) ;
}
2014-10-01 17:08:38 +02:00
try {
2023-10-30 18:52:02 +01:00
session . execute ( writeBatch ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
2014-10-01 17:08:38 +02:00
_log . error ( " Hashtag Count update NOT OK " ) ;
2023-11-15 18:14:57 +01:00
2014-10-01 17:08:38 +02:00
return false ;
}
2014-10-06 18:53:11 +02:00
_log . debug ( " Hashtag Count update OK to: " + newCount ) ;
2014-10-01 17:08:38 +02:00
return true ;
}
2015-06-25 18:25:37 +02:00
/ * *
* verify an email address
* @param email
* @return true or false
* /
private boolean verifyEmail ( String email ) {
boolean isValid = false ;
try {
InternetAddress internetAddress = new InternetAddress ( email ) ;
internetAddress . validate ( ) ;
isValid = true ;
} catch ( AddressException e ) {
_log . error ( " Validation Exception Occurred for email: " + email ) ;
}
return isValid ;
}
2016-01-14 18:37:03 +01:00
2015-06-29 17:49:49 +02:00
2016-02-02 15:19:10 +01:00
@Override
2023-10-30 18:52:02 +01:00
public List < String > getAllVREIds ( ) {
2015-06-29 17:49:49 +02:00
2016-02-02 15:19:10 +01:00
List < String > ids = new ArrayList < > ( ) ;
2013-01-30 17:58:23 +01:00
2023-10-30 18:52:02 +01:00
CqlSession session = conn . getKeyspaceSession ( ) ;
ResultSet result = null ;
PreparedStatement stmtFind = session . prepare ( QueryBuilder
. selectFrom ( VRE_TIMELINE_POSTS ) . column ( VRE_ID ) . all ( )
. build ( ) ) ;
try {
result = session . execute ( stmtFind . getQuery ( ) ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
2023-11-15 18:14:57 +01:00
2023-10-30 18:52:02 +01:00
}
2014-04-02 18:03:42 +02:00
2023-10-30 18:52:02 +01:00
for ( Row row : result . all ( ) ) {
ids . add ( row . getString ( VRE_ID ) ) ;
2016-02-02 15:19:10 +01:00
}
_log . debug ( " VRE ids are " + ids ) ;
2016-02-02 18:19:13 +01:00
2016-02-02 15:19:10 +01:00
return ids ;
}
2013-01-10 14:19:53 +01:00
}