diff --git a/CHANGELOG.md b/CHANGELOG.md
index da288de..163fe37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [v2.0.0] - 2023-10-30
+## [v2.0.0] - 2023-11-15
- Feature #25901-fix, same as feature 25901 but with minor fixes related to deprecated methods and classes
+## [v1.17.1] - 2023-10-30
+
+- Implementation of databookstore using rest api of social service client
+
## [v1.17.0] - 2022-05-13
- Added support for Catalogue notifications
diff --git a/pom.xml b/pom.xml
index f47acac..0d4ab68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
org.gcube.portal
social-networking-library
- 2.0.0-SNAPSHOT
+ 1.17.1-SNAPSHOT
gCube Social Networking Library
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.
@@ -44,14 +44,9 @@
- com.datastax.oss
- java-driver-query-builder
- ${cassandra.driver.oss.version}
-
-
- com.datastax.oss
- java-driver-mapper-runtime
- ${cassandra.driver.oss.version}
+ org.gcube.social-networking
+ social-service-client
+ [1.1.0, 2.0.0)
com.google
diff --git a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java
index 4a55ba9..a205562 100644
--- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java
+++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java
@@ -1,24 +1,18 @@
package org.gcube.portal.databook.server;
-import java.time.Instant;
import java.util.*;
-import java.util.stream.Collectors;
import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import com.datastax.oss.driver.api.core.CqlSession;
-import com.datastax.oss.driver.api.core.cql.*;
-import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
-import org.apache.commons.lang.NullArgumentException;
import org.gcube.portal.databook.shared.*;
import org.gcube.portal.databook.shared.ex.*;
+import org.gcube.social_networking.social_networking_client_library.*;
+
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.gcube.portal.databook.server.CassandraClusterConnection.closeSession;
-import static org.gcube.portal.databook.server.Schema.*;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Costantino Perciante ISTI-CNR
@@ -30,6 +24,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* logger
*/
private static final Logger _log = LoggerFactory.getLogger(DBCassandraAstyanaxImpl.class);
+ private static PostClient postClient;
+ private static NotificationClient notificationClient;
+ private static HashTagClient hashTagClient;
+ private static InviteClient inviteClient;
+ private static CommentClient commentClient;
+ private static LikeClient likeClient;
+
/**
* connection instance
@@ -44,13 +45,36 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* @param dropSchema set true if you want do drop the current and set up new one
*/
protected DBCassandraAstyanaxImpl(boolean dropSchema) {
+
conn = new CassandraClusterConnection(dropSchema);
+ try {
+ postClient = new PostClient();
+ notificationClient = new NotificationClient();
+ hashTagClient = new HashTagClient();
+ commentClient = new CommentClient();
+ inviteClient = new InviteClient();
+ likeClient = new LikeClient();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
}
/**
* public constructor, no dropping schema is allowed
*/
public DBCassandraAstyanaxImpl() {
conn = new CassandraClusterConnection(false);
+ try {
+ postClient = new PostClient();
+ notificationClient = new NotificationClient();
+ hashTagClient = new HashTagClient();
+ commentClient = new CommentClient();
+ inviteClient = new InviteClient();
+ likeClient = new LikeClient();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
}
/**
@@ -58,449 +82,18 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
public DBCassandraAstyanaxImpl(String infrastructureName) {
conn = new CassandraClusterConnection(false, infrastructureName);
+ try {
+ postClient = new PostClient();
+ notificationClient = new NotificationClient();
+ hashTagClient = new HashTagClient();
+ commentClient = new CommentClient();
+ inviteClient = new InviteClient();
+ likeClient = new LikeClient();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- /*
- 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());
- }
-
-
/*
*
********************** FRIENDSHIPS (CONNECTIONS) ***********************
@@ -555,96 +148,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
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())));
-
- //an entry in the VRES Timeline iff vreid field is not empty
- 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());
- }
-
-
- return result;
+ return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean saveUserPost(Post 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())));
-
- //an entry in the VRES Timeline iff vreid field is not empty
- 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());
- }
-
-
- return result;
+ return postClient.saveUserPostLib(post);
}
/**
* {@inheritDoc}
@@ -652,19 +163,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public boolean saveUserFeed(Feed feed, List 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;
+ return true;
}
/**
* {@inheritDoc}
@@ -677,7 +176,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (savePostResult) {
String postkey = post.getKey();
for (Attachment attachment : attachments) {
- boolean attachSaveResult = saveAttachmentEntry(postkey, attachment);
+ boolean attachSaveResult = postClient.saveAttachmentEntryLib(postkey, attachment);
if (!attachSaveResult)
_log.warn("Some of the attachments failed to be saved: " + attachment.getName());
}
@@ -692,96 +191,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
@Deprecated
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())));
-
- //an entry in the VRES Timeline iff vreid field is not empty
- 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 app post with id " + post.getKey());
-
- return result;
+ return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean saveAppPost(Post 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())));
-
- //an entry in the VRES Timeline iff vreid field is not empty
- 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 app post with id " + post.getKey());
-
- return result;
+ return postClient.saveAppPostLib(post);
}
/**
* {@inheritDoc}
@@ -789,19 +206,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public boolean saveAppFeed(Feed feed, List 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;
+ return true;
}
/**
* {@inheritDoc}
@@ -814,7 +219,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (saveFeedResult) {
String feedKey = post.getKey();
for (Attachment attachment : attachments) {
- boolean attachSaveResult = saveAttachmentEntry(feedKey, attachment);
+ boolean attachSaveResult = postClient.saveAttachmentEntryLib(feedKey, attachment);
if (!attachSaveResult)
_log.warn("Some of the attachments failed to be saved: " + attachment.getName());
}
@@ -828,58 +233,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public boolean saveFeedToVRETimeline(String feedKey, String vreid) throws FeedIDNotFoundException {
- Feed toCheck;
- try {
- toCheck = readFeed(feedKey);
- if (toCheck == null)
- throw new FeedIDNotFoundException("Could not find Post with id " + feedKey, feedKey);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- PreparedStatement stmt3 = createVreTimelineEntry(session);
- writeBatch.add(stmt3.bind(vreid, toCheck.getTime().toInstant(), UUID.fromString(toCheck.getKey())));
-
- try{
- boolean res = session.execute(writeBatch).wasApplied();
-
- return res;
- }catch (Exception e) {
- e.printStackTrace();
- return false;
- }
+ return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean savePostToVRETimeline(String postKey, String vreid) throws FeedIDNotFoundException {
- Post toCheck;
- try {
- toCheck = readPost(postKey);
- if (toCheck == null)
- throw new FeedIDNotFoundException("Could not find Post with id " + postKey, postKey);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- PreparedStatement stmt3 = createVreTimelineEntry(session);
- writeBatch.add(stmt3.bind(vreid, toCheck.getTime().toInstant(), UUID.fromString(toCheck.getKey())));
-
- try{
- boolean res = session.execute(writeBatch).wasApplied();
-
- return res;
- }catch (Exception e) {
- e.printStackTrace();
- return false;
- }
+ return postClient.savePostToVRETimelineLib(postKey, vreid);
}
/**
* {@inheritDoc}
@@ -889,17 +250,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public Feed readFeed(String feedid)
throws PrivacyLevelTypeNotFoundException,
FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- CqlSession session = conn.getKeyspaceSession();
- Feed post;
- try{
- post = findFeedById(feedid, session).get();
- } catch (Exception e){
- e.printStackTrace();
-
- return null;
- }
- return post;
+ return null;
}
/**
* {@inheritDoc}
@@ -908,17 +260,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public Post readPost(String postid)
throws PrivacyLevelTypeNotFoundException,
FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- CqlSession session = conn.getKeyspaceSession();
- Post post;
- try{
- post = findPostById(postid, session).get();
-
- } catch (Exception e){
- e.printStackTrace();
-
- return null;
- }
- return post;
+ return postClient.readPostLib(postid);
}
/**
* {@inheritDoc}
@@ -930,43 +272,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (timeInMillis > now.getTime())
throw new IllegalArgumentException("the timeInMillis must be before today");
- ResultSet result = null;
- try {
- 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));
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- List 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());
- if (toCheck.getType() != FeedType.DISABLED)
- 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);
- }
- return null;
- }).collect(Collectors.toList());
-
- return toReturn;
+ return null;
}
/**
* {@inheritDoc}
@@ -977,43 +283,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (timeInMillis > now.getTime())
throw new IllegalArgumentException("the timeInMillis must be before today");
- ResultSet result = null;
- try {
- 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));
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- List 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());
- if (toCheck.getType() != PostType.DISABLED)
- 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);
- }
- return null;
- }).collect(Collectors.toList());
-
- return toReturn;
+ return postClient.getRecentPostsByUserAndDateLib(userid, timeInMillis);
}
/**
* {@inheritDoc}
@@ -1021,22 +291,6 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public boolean deleteFeed(String feedId) throws FeedIDNotFoundException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException {
- Feed toDelete = readFeed(feedId);
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- PreparedStatement stmt1 = updatePostEntry(session, TYPE);
- writeBatch.add(stmt1.bind(FeedType.DISABLED.toString(), UUID.fromString(toDelete.getKey())));
-
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- _log.error("Delete Post ERROR for postid " + feedId);
-
- return false;
- }
- _log.info("Delete Post OK");
return true;
}
/**
@@ -1044,23 +298,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public boolean deletePost(String postid) throws FeedIDNotFoundException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException {
- Post toDelete = readPost(postid);
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- PreparedStatement stmt1 = updatePostEntry(session, TYPE);
- writeBatch.add(stmt1.bind(PostType.DISABLED.toString(), UUID.fromString(toDelete.getKey())));
-
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- _log.error("Delete Post ERROR for postid " + postid);
-
- return false;
- }
- _log.info("Delete Post OK");
- return true;
+ return postClient.deletePostLib(postid);
}
/**
* {@inheritDoc}
@@ -1068,28 +306,28 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public List getAllFeedsByUser(String userid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getFeedsByIds(getUserFeedIds(userid));
+ return null;
}
/**
* {@inheritDoc}
*/
@Override
public List getAllPostsByUser(String userid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getPostsByIds(getUserPostIds(userid));
+ return postClient.getAllPostsByUserLib(userid);
}
/**
* {@inheritDoc}
*/
@Override
public List getAllFeedsByApp(String appid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getFeedsByIds(getAppFeedIds(appid));
+ return null;
}
/**
* {@inheritDoc}
*/
@Override
public List getAllPostsByApp(String appid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getPostsByIds(getAppPostIds(appid));
+ return postClient.getAllPostsByAppLib(appid);
}
/**
* {@inheritDoc}
@@ -1099,36 +337,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
public List getRecentCommentedFeedsByUserAndDate(String userid,
long timeInMillis) throws Exception {
-
- List 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 last comments by the user (it is not needed to get them sorted)
- List lastComments = getRecentCommentsByUserAndDateBody(userid, timeInMillis, false);
-
- // evaluate unique feeds' ids
- HashSet postIds = new HashSet();
-
- for (Comment comment : lastComments) {
- String postId = comment.getFeedid();
- try{
- if(!postIds.contains(postId)){
- postIds.add(postId);
- toReturn.add(readFeed(postId));
- }
- }catch(Exception e){
- _log.error("Unable to retrieve feed with id " + postId, e);
- }
- }
-
- Collections.sort(toReturn, Collections.reverseOrder());
- return toReturn;
+ return null;
}
/**
* {@inheritDoc}
@@ -1137,292 +346,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
public List getRecentCommentedPostsByUserAndDate(String userid,
long timeInMillis) throws Exception {
-
- List 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 last comments by the user (it is not needed to get them sorted)
- List lastComments = getRecentCommentsByUserAndDateBody(userid, timeInMillis, false);
-
- // evaluate unique feeds' ids
- HashSet postIds = new HashSet();
-
- 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;
+ return postClient.getRecentCommentedPostsByUserAndDateLib(userid, timeInMillis);
}
- /**
- * @deprecated
- * helper method that retrieve all the feeds belongin to a list of Ids
- * @param feedIds
- * @return
- * @throws ColumnNameNotFoundException
- * @throws FeedIDNotFoundException
- * @throws FeedTypeNotFoundException
- * @throws PrivacyLevelTypeNotFoundException
- */
- private List getFeedsByIds(List feedIds) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- ArrayList toReturn = new ArrayList();
- 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;
- }
- /**
- * helper method that retrieve all the feeds belongin to a list of Ids
- * @param postIds
- * @return
- * @throws ColumnNameNotFoundException
- * @throws FeedIDNotFoundException
- * @throws FeedTypeNotFoundException
- * @throws PrivacyLevelTypeNotFoundException
- */
- private List getPostsByIds(List postIds) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- ArrayList toReturn = new ArrayList();
- 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;
- }
- /**
- * 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
- */
- @Deprecated
- private ArrayList getUserFeedIds(String userid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_TIMELINE_POSTS).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
- /**
- * 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 getUserPostIds(String userid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_TIMELINE_POSTS).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
-
- /**
- * helper method that return whether the user
- * @param userid user identifier
- * @param postid the feed identifier
- * @return true if the feed id liked already
- */
- 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());
-
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
- for (Row row: result.all()){
- if (row.getUuid(POST_ID).toString().equals(postid)){
- return true;
- }
- }
-
- 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 getAppFeedIds(String appid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(APP_TIMELINE_POSTS).all()
- .whereColumn(APP_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(appid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
- /**
- * 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 getAppPostIds(String appid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(APP_TIMELINE_POSTS).all()
- .whereColumn(APP_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(appid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
-
/**
* {@inheritDoc}
*/
@Deprecated
@Override
public List getAllPortalPrivacyLevelFeeds() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException {
- //possible error index
- ArrayList toReturn = new ArrayList();
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(POSTS).all()
- .whereColumn(PRIVACY).isEqualTo(QueryBuilder.bindMarker())
- .limit(20)
- .build());
- try {
- result = session.execute(stmtFind.bind(PrivacyLevel.PORTAL.toString()));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
- 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);
- }
- return toReturn;
+ return null;
}
@Override
public List getAllPortalPrivacyLevelPosts() throws FeedTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException {
- //possible error index
- ArrayList toReturn = new ArrayList();
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(POSTS).all()
- .whereColumn(PRIVACY).isEqualTo(QueryBuilder.bindMarker())
- .limit(20)
- .build());
- try {
- result = session.execute(stmtFind.bind(PrivacyLevel.PORTAL.toString()));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
- 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);
- }
- return toReturn;
+ return postClient.getAllPortalPrivacyLevelPostsLib();
}
/**
* {@inheritDoc}
@@ -1430,47 +366,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
@Deprecated
public List getRecentFeedsByUser(String userid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList 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));
- } 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;
- }
- }
- return toReturn;
+ return null;
}
@Override
public List getRecentPostsByUser(String userid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList postIDs = getUserPostIds(userid);
- //check if quantity is greater than user feeds
- quantity = (quantity > postIDs.size()) ? postIDs.size() : quantity;
-
- //need them in reverse order
- 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;
+ return postClient.getRecentPostsByUserLib(userid, quantity);
}
/**
* {@inheritDoc}
@@ -1478,14 +378,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
@Deprecated
public List getAllFeedsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getFeedsByIds(getVREFeedIds(vreid));
+ return null;
}
/**
* {@inheritDoc}
*/
@Override
public List getAllPostsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- return getPostsByIds(getVREPostIds(vreid));
+ return postClient.getAllPostsByVRELib(vreid);
}
/**
* {@inheritDoc}
@@ -1493,199 +393,27 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Deprecated
@Override
public List getRecentFeedsByVRE(String vreid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList 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));
- } 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;
- }
- }
- return toReturn;
+ return null;
}
@Override
public List getRecentPostsByVRE(String vreid, int quantity) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList postIDs = getVREPostIds(vreid);
- //check if quantity is greater than user posts
- quantity = (quantity > postIDs.size()) ? postIDs.size() : quantity;
-
- //need them in reverse order
- 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;
+ return postClient.getRecentPostsByVRELib(vreid, quantity);
}
/**
* {@inheritDoc}
*/
@Override
public RangeFeeds getRecentFeedsByVREAndRange(String vreid, int from, int quantity) throws IllegalArgumentException, PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- if (from < 1) {
- throw new IllegalArgumentException("From must be greather than 0");
- }
- ArrayList feedsToReturn = new ArrayList();
- ArrayList feedIDs = getVREFeedIds(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 RangeFeeds();
- }
-
- 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);
- //need them in reverse order
- int howMany = from;
- for (int i = rangeStart; i > rangeEnd; i--) {
- Feed toAdd = readFeed(feedIDs.get(i));
- if (toAdd.getType() == FeedType.TWEET || toAdd.getType() == FeedType.SHARE || toAdd.getType() == FeedType.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 RangeFeeds(howMany+1, feedsToReturn);
+ return null;
}
/**
* {@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");
- }
- ArrayList feedsToReturn = new ArrayList();
- ArrayList 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);
- //need them in reverse order
- 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);
+ return postClient.getRecentPostsByVREAndRangeLib(vreid, from, quantity);
}
- /**
- * @deprecated
- * 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 getVREFeedIds(String vreid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(VRE_TIMELINE_POSTS).all()
- .whereColumn(VRE_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(vreid));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
- /**
- * 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 getVREPostIds(String vreid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(VRE_TIMELINE_POSTS).all()
- .whereColumn(VRE_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(vreid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- List toReturn = result.all().stream().map(row-> {
- try {
- String postid = row.getUuid(POST_ID).toString();
- return postid;
- } catch (RuntimeException e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
-
- return (ArrayList) toReturn;
- }
/*
*
********************** NOTIFICATIONS ***********************
@@ -1696,39 +424,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public boolean saveNotification(Notification n) {
- 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())));
-
- // save key in the unread notifications column family too
- PreparedStatement stmt3 = createUnreadNotificationEntry(session);
- writeBatch.add(stmt3.bind(n.getUserid(), n.getTime().toInstant(), UUID.fromString(n.getKey())));
- try{
- boolean res = session.execute(writeBatch).wasApplied();
-
- return res;
- }catch (Exception e){
- e.printStackTrace();
- return false;
- }
+ return notificationClient.saveNotificationLib(n);
}
/**
@@ -1736,197 +432,43 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public Notification readNotification(String notificationid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException {
- Notification toReturn = new Notification();
- CqlSession session = conn.getKeyspaceSession();
- try {
- toReturn = findNotById(notificationid, session).get();
-
- }
- catch (Exception e) {
- e.printStackTrace();
-
- }
- return toReturn;
+ return notificationClient.readNotificationLib(notificationid);
}
/**
* {@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");
-
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- //update the entry in notifications
- writeBatch.add(updateNotificationEntry(session,IS_READ).bind(UUID.fromString(notificationidToSet), true));
-
- // delete the notification's key from the unread notifications column family
- writeBatch.add(deleteUnreadNotEntry(session).bind(toSet.getUserid(), toSet.getTime().toInstant()));
-
- // execute the operations
- try {
- boolean res = session.execute(writeBatch).wasApplied();
-
- return res;
- } catch (Exception e) {
- _log.error("ERROR while setting Notification " + notificationidToSet + " to read.");
- return false;
- }
+ return notificationClient.setNotificationReadLib(notificationidToSet);
}
- /**
- *
- * @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 getUserNotificationsIds(String userid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_NOTIFICATIONS).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- ArrayList toReturn = new ArrayList();
-
- // Iterate rows and their columns
- for (Row row : result.all()) {
- toReturn.add(row.getUuid(NOT_ID).toString());
- }
- return toReturn;
- }
- /**
- * Return a list of not read notifications by user userid (messages as well as other notifications)
- * @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 getUnreadUserNotificationsIds(String userid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_NOTIFICATIONS_UNREAD).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- ArrayList toReturn = new ArrayList();
-
- // Iterate rows and their columns
- for (Row row : result.all()) {
- toReturn.add(row.getUuid(NOT_ID).toString());
- }
- return toReturn;
- }
/**
* {@inheritDoc}
*/
@Override
public List getAllNotificationByUser(String userid, int limit) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList notificationsIDs = getUserNotificationsIds(userid);
- //check if quantity is greater than user feeds
- limit = (limit > notificationsIDs.size()) ? notificationsIDs.size() : limit;
-
- //need them in reverse order
- for (int i = notificationsIDs.size()-1; i >= (notificationsIDs.size()-limit); i--) {
- Notification toAdd = null;
- try {
- toAdd = readNotification(notificationsIDs.get(i));
- toReturn.add(toAdd);
- } catch (NotificationIDNotFoundException e) {
- _log.error("Notification not found id=" + notificationsIDs.get(i));
- }
- }
- return toReturn;
+ return notificationClient.getAllNotificationByUserLib(userid, limit);
}
/**
* {@inheritDoc}
*/
@Override
public List getUnreadNotificationsByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException {
- ArrayList toReturn = new ArrayList();
- ArrayList notificationsIDs = getUnreadUserNotificationsIds(userid);
-
- //need them in reverse order
- for (int i = notificationsIDs.size()-1; i >= 0; i--) {
- try{
- toReturn.add(readNotification(notificationsIDs.get(i)));
- }catch(Exception e){
- _log.error("Unable to read notification with key " + notificationsIDs.get(i));
- }
- }
-
- return toReturn;
+ return notificationClient.getUnreadNotificationsByUserLib(userid);
}
/**
* {@inheritDoc}
*/
@Override
public List getRangeNotificationsByUser(String userid,int from, int quantity) throws NotificationTypeNotFoundException, ColumnNameNotFoundException, NotificationIDNotFoundException {
- if (from < 1) {
- throw new IllegalArgumentException("From must be greather than 0");
- }
- ArrayList toReturn = new ArrayList();
- ArrayList notificationsIDs = getUserNotificationsIds(userid);
-
- //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();
- }
-
- int rangeStart = notificationsIDs.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);
- //need them in reverse order
- for (int i = rangeStart; i > rangeEnd; i--) {
- Notification toAdd = readNotification(notificationsIDs.get(i));
- toReturn.add(toAdd);
- }
- return toReturn;
+ return notificationClient.getRangeNotificationsByUserLib(userid, from, quantity);
}
/**
* {@inheritDoc}
*/
@Override
public boolean setAllNotificationReadByUser(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
-
- // get the list of unread notifications
- ArrayList notificationsIDs = getUnreadUserNotificationsIds(userid);
-
- for (int i = notificationsIDs.size()-1; i >= 0; i--) {
- try{
-
- // set to read (and automatically remove from the unread column family)
- setNotificationRead(notificationsIDs.get(i));
-
- } catch (NotificationIDNotFoundException e) {
- _log.error("Could not set read notification with id =" + notificationsIDs.get(i));
- }
- }
- return true;
+ return notificationClient.setAllNotificationReadByUserLib(userid);
}
/**
@@ -1934,42 +476,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public boolean checkUnreadNotifications(String userid) throws NotificationTypeNotFoundException, ColumnNameNotFoundException {
-
- ArrayList 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;
+ return notificationClient.checkUnreadNotificationsLib(userid);
}
/**
* {@inheritDoc}
*/
@Override
public boolean checkUnreadMessagesNotifications(String userid) throws NotificationIDNotFoundException, NotificationTypeNotFoundException, ColumnNameNotFoundException {
-
- ArrayList 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;
+ return notificationClient.checkUnreadMessagesNotificationsLib(userid);
}
/*
*
@@ -1981,86 +495,15 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public List getUserNotificationChannels(String userid, NotificationType notificationType) throws NotificationChannelTypeNotFoundException, NotificationTypeNotFoundException {
- _log.trace("Asking for Single Notification preference of " + userid + " Type: " + notificationType);
- List toReturn = new ArrayList();
- NotificationChannelType[] toProcess = getUserNotificationPreferences(userid).get(notificationType);
- if (toProcess == null) {
- _log.warn("Single Notification preference of " + userid + " Type: " + notificationType + " not existing ... creating default");
- return createNewNotificationType(userid, notificationType);
- }
- else if (toProcess.length == 0)
- return toReturn;
- else
- for (int i = 0; i < toProcess.length; i++) {
- toReturn.add(toProcess[i]);
- }
- return toReturn;
+ return notificationClient.getUserNotificationChannelsLib(userid, notificationType);
}
- /**
- * called when you add new notification types where the setting does not exist yet
- * please note: by default we set all notifications
- */
- private List createNewNotificationType(String userid, NotificationType notificationType) {
- List toReturn = new ArrayList();
- CqlSession session = conn.getKeyspaceSession();
- String valueToInsert = "";
- NotificationChannelType[] wpTypes = NotificationChannelType.values();
-
- for (int i = 0; i < wpTypes.length; i++) {
- valueToInsert += wpTypes[i];
- if (i < wpTypes.length-1)
- valueToInsert += ",";
- toReturn.add(wpTypes[i]); //add the new added notification type
- }
-
- BatchStatement writeBatch = getBatch().add(
- createNotificationPreferenceEntry(session).bind(userid, notificationType.toString(), valueToInsert)
- );
- boolean res = false;
- try{
- res = session.execute(writeBatch).wasApplied();
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- if (res) {
- _log.trace("Set New Notification Setting for " + userid + " OK");
- return toReturn;
- }
- return new ArrayList(); //no notification if sth fails
- }
/**
* {@inheritDoc}
*/
@Override
public boolean setUserNotificationPreferences(String userid, Map enabledChannels) {
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
-
- 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 += ",";
- }
- if (channelsNo == 0) { //in case no channels were selected
- valueToInsert = "";
- _log.trace("No Channels selected for " + nType + " by " + userid);
- }
- writeBatch.add(createNotificationPreferenceEntry(session).bind(userid, nType.toString(), valueToInsert));
- }
-
- boolean overAllresult = session.execute(writeBatch).wasApplied();
- if (overAllresult)
- _log.trace("Set Notification Map for " + userid + " OK");
- else
- _log.trace("Set Notification Map for " + userid + " FAILED");
- return overAllresult;
+ return notificationClient.setUserNotificationPreferencesLib(userid, enabledChannels);
}
/**
* {@inheritDoc}
@@ -2069,61 +512,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public Map getUserNotificationPreferences(String userid) throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException {
- _log.trace("Asking for Notification preferences of " + userid);
- Map toReturn = new HashMap();
-
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_NOTIFICATIONS_PREFERENCES).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- //if there are no settings for this user create an entry and put all of them at true
- if (result.all().isEmpty()) {
- _log.info("Userid " + userid + " settings not found, initiating its preferences...");
- HashMap toCreate = new HashMap();
-
- for (int i = 0; i < NotificationType.values().length; i++) {
- //TODO: Potential bug in NotificationType for workspace are refactored
- //create a map with all notification enabled except for workspace notifications (They start with WP_) it was the only quick way
- if (NotificationType.values()[i].toString().startsWith("WP_")) {
- NotificationChannelType[] wpTypes = { NotificationChannelType.PORTAL };
- toCreate.put(NotificationType.values()[i], wpTypes);
- }
- else
- toCreate.put(NotificationType.values()[i], NotificationChannelType.values());
- }
- setUserNotificationPreferences(userid, toCreate); //commit the map
-
- return toCreate;
- }
- else {
- _log.trace("Notification preferences Found for " + userid);
- 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]));
- }
- }
- toReturn.put(getNotificationType(row.getString(TYPE)), toAdd);
- }
- }
- }
- return toReturn;
+ return notificationClient.getUserNotificationPreferencesLib(userid);
}
/*
*
@@ -2135,71 +524,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@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");
-
- String postid = comment.getFeedid();
- try {
- toComment = readFeed(postid);
- if (toComment == null)
- throw new FeedIDNotFoundException("Could not find Feed with id " + postid + " to associate this comment", postid);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- 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
- ));
-
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- //update the comment count
- boolean updateCommentNoResult = updateFeedCommentsCount(toComment, true);
- return updateCommentNoResult;
+ return commentClient.addCommentLib(comment)!=null;
}
/**
* {@inheritDoc}
*/
public Comment readCommentById(String commentId) throws CommentIDNotFoundException {
- 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());
- try {
- result = session.execute(stmtFind.bind(UUID.fromString(commentId)));
-
- if (result.all().isEmpty()) {
- throw new CommentIDNotFoundException("The requested commentId: " + commentId + " is not existing");
- }
- toReturn = readCommentFromRow(result.one());
- } catch (Exception e){
- e.printStackTrace();
- }
-
- return toReturn;
+ return commentClient.readCommentByIdLib(commentId);
}
/**
* {@inheritDoc}
@@ -2214,29 +545,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public List getAllCommentByPost(String postid) {
- //possible error index
- List toReturn = new ArrayList();
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare("SELECT * FROM comments WHERE postid=?");
- /*PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(COMMENTS).all()
- .where
- .whereColumn(POST_ID).isEqualTo(QueryBuilder.bindMarker())
- .build());*/
- try {
- result = session.execute(stmtFind.bind(UUID.fromString(postid)));
-
- for (Row row : result.all()) {
- Comment toAdd = readCommentFromRow(row);
- toReturn.add(toAdd);
- }
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- return toReturn;
+ return commentClient.getAllCommentsByPostIdLib(postid);
}
/**
@@ -2247,92 +556,16 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public List getRecentCommentsByUserAndDate(final String userid,
final long timeInMillis) throws Exception {
- final List 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);
-
- return commentsByUser; }
-
- /**
- * 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 getRecentCommentsByUserAndDateBody(final String userid,
- final long timeInMillis, boolean sort){
-
- //possible error
- final List commentsByUser = new ArrayList();
-
- CqlSession session = conn.getKeyspaceSession();
-
- ResultSet result = null;
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(COMMENTS)
- .all()
- .build());
- try {
- result = session.execute(stmtFind.bind());
-
-
- if (!result.all().isEmpty()){
- result.all().parallelStream().forEach( row->{
- if(row.getString(USER_ID).equals(userid)){
- try{
- 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);
- }catch(Exception e){
- _log.error("Unable to read comment with id" + row.getString(COMMENT_ID), e);
- }
- }
- }
- );
- }
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- if(sort)
- Collections.sort(commentsByUser, Collections.reverseOrder());
- return commentsByUser;
+ return commentClient.getRecentCommentsByUserAndDateLib(userid, timeInMillis);
}
+
/**
* {@inheritDoc}
*/
@Override
public boolean editComment(Comment comment2Edit) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, CommentIDNotFoundException, FeedIDNotFoundException {
- 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())));
-
- try {
- boolean res = session.execute(writeBatch).wasApplied();
-
- _log.info("Comments update OK to: " + comment2Edit.getText());
- return res;
- } catch (Exception e) {
-
- _log.error("Comments update NOT OK ");
- return false;
- }
+ return commentClient.editCommentLib(comment2Edit)!=null;
}
/**
@@ -2340,102 +573,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@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) {
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch().add(deleteCommentEntry(session).bind(UUID.fromString(commentid)));
-
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
-
- _log.error("Comment Delete FAILED for " + commentid + " from Feed " + feedid);
- e.printStackTrace();
- }
- _log.trace("Comment Deleted " + commentid + " from Feed " + feedid);
- }
-
-
- return updateCommentNoResult;
+ return commentClient.deleteCommentLib(commentid, feedid);
}
/**
* {@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)
- throw new FeedIDNotFoundException("Could not find Feed with id " + feedId + " to associate this like", feedId);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- if (isPostLiked(like.getUserid(), feedId)) {
- _log.info("User " + like.getUserid() + " already liked Feed " + feedId);
- return true;
- }
- else {
- CqlSession session = conn.getKeyspaceSession();
- // Inserting data
- //an entry in the feed CF
- //and an entry in the UserLikesCF
- 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())));
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return updateFeedLikesCount(toLike, true);
- }
+ return likeClient.likeLib(like);
}
/**
* {@inheritDoc}
*/
@Override
public boolean unlike(String userid, String likeid, String feedid) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, LikeIDNotFoundException, FeedIDNotFoundException {
- Feed toUpdate = readFeed(feedid);
- boolean updateLikeNoResult = false;
-
- updateLikeNoResult = updateFeedLikesCount(toUpdate, false); //this remove 1 from the Feed CF LikeNO
- if (updateLikeNoResult) {
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch().add(deleteLikeEntry(session).bind(UUID.fromString(likeid)))
- .add(deleteUserLikeEntry(session).bind(userid, UUID.fromString(likeid)));
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
-
- _log.error("Like Delete FAILED for " + likeid + " from Feed " + feedid);
- e.printStackTrace();
- }
- _log.trace("Unlike ok for " + likeid + " from Feed " + feedid);
- }
- return updateLikeNoResult;
-
+ return likeClient.unlikeLib(userid, likeid, feedid);
}
/**
* {@inheritDoc}
@@ -2450,26 +602,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public List getAllLikedPostIdsByUser(String userid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(USER_LIKED_POSTS).all()
- .whereColumn(USER_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(userid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- ArrayList toReturn = new ArrayList();
- for (Row row: result){
- toReturn.add(row.getUuid(POST_ID).toString());
- }
- return toReturn;
+ return likeClient.getAllLikedPostIdsByUserLib(userid);
}
/**
* {@inheritDoc}
@@ -2638,26 +771,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
public List getAllLikesByPost(String postid) {
//possible error index
-
- List toReturn = new ArrayList();
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(LIKES).all()
- .whereColumn(POST_ID).isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(UUID.fromString(postid)));
- for (Row row: result) {
- Like toAdd = readLikeFromRow(row);
- toReturn.add(toAdd);
- }
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
- return toReturn;
+ return likeClient.getAllLikesByPostLib(postid);
}
/*
*
@@ -2669,193 +783,42 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public boolean saveHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException {
- Set noduplicatesHashtags = null;
- if (hashtags != null && !hashtags.isEmpty()) {
- noduplicatesHashtags = new HashSet(hashtags);
- }
- // Inserting data
- CqlSession session = conn.getKeyspaceSession();
- for (String hashtag : noduplicatesHashtags) {
- String lowerCaseHashtag = hashtag.toLowerCase();
- boolean firstInsert = session.execute((createNewHashtagTimelineEntry(session).bind(lowerCaseHashtag, UUID.fromString(feedid), vreid))).wasApplied();
- boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
- if (! (firstInsert && secondInsert)) {
- _log.error("saveHashTags: Could not save the hashtag(s)");
-
- return false;
- }
- }
-
- return true;
+ return hashTagClient.saveHashTagsLib(feedid, vreid, hashtags);
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteHashTags(String feedid, String vreid, List hashtags) throws FeedIDNotFoundException {
- Set noduplicatesHashtags = null;
- if (hashtags != null && !hashtags.isEmpty()) {
- noduplicatesHashtags = new HashSet(hashtags);
- }
- // Inserting data
- CqlSession session = conn.getKeyspaceSession();
- for (String hashtag : noduplicatesHashtags) {
- String lowerCaseHashtag = hashtag.toLowerCase();
- boolean firstDelete = session.execute(deleteHashtagEntry(session).bind(lowerCaseHashtag, UUID.fromString(feedid))).wasApplied();
- boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
- if (! (firstDelete && secondInsert)) {
- _log.error("deleteHashTags: Could not delete the hashtag(s)");
-
- return false;
-
- }
- }
-
- return true;
+ return hashTagClient.deleteHashTagsLib(feedid, vreid, hashtags);
}
/**
* {@inheritDoc}
*/
@Override
public boolean saveHashTagsComment(String commentId, String vreid, List hashtags) throws CommentIDNotFoundException {
- Set noduplicatesHashtags = null;
- if (hashtags != null && !hashtags.isEmpty()) {
- noduplicatesHashtags = new HashSet(hashtags);
- }
- // Inserting datacommentIdcommentId
- CqlSession session = conn.getKeyspaceSession();
- for (String hashtag : noduplicatesHashtags) {
- String lowerCaseHashtag = hashtag.toLowerCase();
- boolean firstInsert = session.execute(createNewHashtagCommentEntry(session).bind(hashtag, UUID.fromString(commentId), vreid)).wasApplied();
- boolean secondInsert = false;
- if(firstInsert)
- secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
- if (! (firstInsert && secondInsert)) {
- _log.error("saveHashTags: Could not save the hashtag(s)");
-
- return false;
- }
- }
-
- return true;
+ return hashTagClient.saveHashTagsCommentLib(commentId, vreid, hashtags);
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteHashTagsComment(String commentId, String vreid, List hashtags) throws CommentIDNotFoundException {
- Set noduplicatesHashtags = null;
- if (hashtags != null && !hashtags.isEmpty()) {
- noduplicatesHashtags = new HashSet(hashtags);
- }
- // Inserting data
- CqlSession session = conn.getKeyspaceSession();
- for (String hashtag : noduplicatesHashtags) {
- String lowerCaseHashtag = hashtag.toLowerCase();
- boolean firstDelete = session.execute(deleteHashtagCommentEntry(session).bind(lowerCaseHashtag, UUID.fromString(commentId))).wasApplied();
- if(firstDelete){
- boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
- if (!(firstDelete && secondInsert)) {
- _log.error("deleteHashTags: Could not delete the hashtag(s)");
-
- return false;
- }
- }else{
- _log.error("deleteHashTags: Could not delete the hashtag(s)");
-
- return false;
- }
- }
-
- return true;
+ return hashTagClient.deleteHashTagsCommentLib(commentId, vreid, hashtags);
}
/**
* {@inheritDoc}
*/
@Override
public Map getVREHashtagsWithOccurrence(String vreid) {
- ResultSet result = null;
- CqlSession session = conn.getKeyspaceSession();
-
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(HASHTAGS_COUNTER).all()
- .whereColumn(VRE_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(vreid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
-
- HashMap toReturn = new HashMap ();
-
- // 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);
- }
-
- return toReturn;
+ return hashTagClient.getVREHashtagsWithOccurrenceLib(vreid);
}
/**
* {@inheritDoc}
*/
@Override
public Map getVREHashtagsWithOccurrenceFilteredByTime(String vreid, long timestamp){
- CqlSession session = conn.getKeyspaceSession();
- ResultSet result = null;
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(HASHTAGS_COUNTER).all()
- .whereColumn(VRE_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(vreid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- HashMap toReturn = new HashMap ();
-
- // Iterate rows and their columns
- for (Row row : result.all()) {
- // retrieve the feeds list for this hashtag
- List 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;
- }
-
- if(feeds.isEmpty()){
-
- _log.info("There are no feeds containing hashtag " + row.getString(HASHTAG) + " in vre " + vreid);
- continue;
-
- }
-
- // retrieve the most recent one among these feeds
- Collections.sort(feeds, Collections.reverseOrder());
-
- if(feeds.get(0).getTime().getTime() < timestamp){
- continue;
- }
-
- // else..
- int curValue = (int) row.getLong(COUNT);
-
- if (curValue > 0)
- toReturn.put(row.getString(HASHTAG), curValue);
- }
- return toReturn;
+ return hashTagClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(vreid, timestamp);
}
/**
@@ -2863,333 +826,65 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
@Override
public List getVREFeedsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- List 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());
- try {
- resultPost = session.execute(stmtFind1.bind(hashtag));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- PreparedStatement stmtFind2 = session.prepare(QueryBuilder
- .selectFrom(HASHTAGGED_COMMENTS).all()
- .whereColumn(HASHTAG)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- ResultSet resultComment = null;
- try {
- resultComment = session.execute(stmtFind2.bind(hashtag));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- Set postIds = new HashSet<>();
- // Iterate rows and their columns (feed)
- for (Row row : resultPost.all()) {
- if (row.getString(VRE_ID).compareTo(vreid)==0)
- postIds.add(row.getUuid(POST_ID).toString());
- }
- // Iterate rows and their columns (comments)
- 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));
- }
- }
- }
- toReturn = getFeedsByIds(new ArrayList<>(postIds));
- return toReturn;
+ return hashTagClient.getVREFeedsByHashtagLib(vreid, hashtag);
}
/**
* {@inheritDoc}
*/
@Override
public List getVREPostsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
- List 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());
- try {
- resultPost = session.execute(stmtFind1.bind(hashtag));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- PreparedStatement stmtFind2 = session.prepare(QueryBuilder
- .selectFrom(HASHTAGGED_COMMENTS).all()
- .whereColumn(HASHTAG)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- ResultSet resultComment = null;
- try {
- resultComment = session.execute(stmtFind2.bind(hashtag));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- Set postIds = new HashSet<>();
- // Iterate rows and their columns (feed)
- for (Row row : resultPost.all()) {
- if (row.getString(VRE_ID).compareTo(vreid)==0)
- postIds.add(row.getUuid(POST_ID).toString());
- }
- // Iterate rows and their columns (comments)
- 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));
- }
- }
- }
- toReturn = getPostsByIds(new ArrayList<>(postIds));
- return toReturn;
+ return hashTagClient.getVREPostsByHashtagLib(vreid, hashtag);
}
/*
*
********************** Invites ***********************
*
*/
- /**
- * common part to save a invite
- * @param invite
- * @return the partial mutation batch instance
- */
- private BatchStatement initSaveInvite(Invite invite, CqlSession session) {
- BatchStatement writeBatch = getBatch();
- if (invite == null)
- throw new NullArgumentException("Invite instance is null");
- // Inserting data
- 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;
- }
-
/**
* {@inheritDoc}
*/
@Override
public String isExistingInvite(String vreid, String email) {
- CqlSession session = conn.getKeyspaceSession();
-
- ResultSet result = null;
- PreparedStatement stmtFind1 = session.prepare(QueryBuilder
- .selectFrom(EMAIL_INVITES).all()
- .whereColumn(EMAIL)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind1.bind(email));
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- // Iterate rows and their columns
- for (Row row : result.all()) {
- if (row.getString(VRE_ID).compareTo(vreid)==0)
- return row.getUuid(INVITE_ID).toString();
-
- }
- return null;
+ return inviteClient.isExistingInviteLib(vreid, email);
}
/**
* {@inheritDoc}
*/
@Override
public InviteOperationResult saveInvite(Invite invite) throws AddressException {
- 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 ...");
- 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();
-
- return result ? InviteOperationResult.SUCCESS : InviteOperationResult.FAILED;
+ return inviteClient.saveInviteLib(invite);
}
/**
* {@inheritDoc}
*/
@Override
public Invite readInvite(String inviteid) throws InviteIDNotFoundException, InviteStatusNotFoundException {
- 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());
- try {
- result = session.execute(stmtFind.bind(UUID.fromString(inviteid)));
- if (result.one() == null) {
- throw new InviteStatusNotFoundException("The requested inviteid: " + inviteid + " is not existing");
- }
- toReturn = readAInviteFromRow(result.one());
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
- return toReturn;
+ return inviteClient.readInviteLib(inviteid);
}
- /**
- * 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
- * @throws InviteIDNotFoundException
- * @throws InviteStatusNotFoundException
- */
- private List getInvitesById(List inviteIds) throws InviteIDNotFoundException, InviteStatusNotFoundException {
- ArrayList toReturn = new ArrayList();
- for (String inviteid : inviteIds)
- toReturn.add(readInvite(inviteid));
- return toReturn;
- }
/**
* {@inheritDoc}
* @throws InviteStatusNotFoundException
*/
@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");
-
- CqlSession session = conn.getKeyspaceSession();
- BatchStatement writeBatch = getBatch();
- //update in the Invites Static CF
- //updated in the VREInvites Dynamic CF
- writeBatch.add(updateInviteEntry(session, STATUS).bind(status.toString(), UUID.fromString(inviteid)))
- .add(updateVreInviteEntry(session, STATUS).bind(status.toString(), vreid, UUID.fromString(inviteid)));
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- _log.error("ERROR while setting Invite " + inviteid + " to " + status.toString());
-
- return false;
- }
- _log.trace("Invite Status Set to " + status.toString() + " OK");
- return true;
+ return inviteClient.setInviteStatusLib(vreid, email, status);
}
/**
* {@inheritDoc}
*/
@Override
public List getInvitedEmailsByVRE(String vreid, InviteStatus... status) throws InviteIDNotFoundException, InviteStatusNotFoundException{
- CqlSession session = conn.getKeyspaceSession();
- ResultSet result = null;
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(VRE_INVITES).all()
- .whereColumn(VRE_ID)
- .isEqualTo(QueryBuilder.bindMarker())
- .build());
- try {
- result = session.execute(stmtFind.bind(vreid));
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- ArrayList invitesIds = new ArrayList();
- // Iterate rows and their columns
- for (Row row : result.all()) {
- if (status != null) {
- for (int i = 0; i < status.length; i++) {
- if (row.getString(STATUS).compareTo(status[i].toString())==0)
- invitesIds.add(row.getUuid(INVITE_ID).toString());
- }
- }
- else {
- invitesIds.add(row.getUuid(INVITE_ID).toString());
- }
- }
- return getInvitesById(invitesIds);
+ return inviteClient.getInvitedEmailsByVRELib(vreid, status);
}
/**
* {@inheritDoc}
*/
@Override
public List getAttachmentsByFeedId(String feedId) throws FeedIDNotFoundException {
- //index error
- Post toCheck = null;
- try {
- toCheck = readPost(feedId);
- if (toCheck == null)
- throw new FeedIDNotFoundException("Could not find Feed with id " + feedId, feedId);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- List toReturn = new ArrayList();
- CqlSession session = conn.getKeyspaceSession();
- PreparedStatement stmtFind = session.prepare(QueryBuilder
- .selectFrom(ATTACHMENTS).all()
- .whereColumn(POST_ID).isEqualTo(QueryBuilder.bindMarker())
- .build());
- ResultSet result = null;
- try {
- 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);
- toReturn.add(toAdd);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
-
- return null;
- }
- return toReturn;
+ return postClient.getAttachmentsByFeedIdLib(feedId);
}
/**
* {@inheritDoc}
@@ -3198,459 +893,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public void closeConnection() {
conn.closeConnection();
}
- /*
- *
- ********************** Helper methods ***********************
- *
- */
- /**
- * @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
- CqlSession session = conn.getKeyspaceSession();
- //an entry in the Attachment CF
- try {
- session.execute(createNewaAttachEntry(session).bind(
- UUID.fromString(toSave.getId()),
- UUID.fromString(feedId),
- toSave.getUri(),
- toSave.getName(),
- toSave.getDescription(),
- toSave.getThumbnailURL(),
- toSave.getMimeType()
- ));
-
- } catch (Exception e) {
-
- e.printStackTrace();
- return false;
- }
- return true;
- }
-
-
- /**
- * 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
- throw new NotificationChannelTypeNotFoundException("The Notification Channel Type was not recognized should be one of " + NotificationChannelType.values() + " asked for: " + channelName);
- }
-
- /**
- * simply return an enum representing the privacy level
- * @param privacyLevel .
- * @return correct enum representing the privacy level
- * @throws FeedTypeNotFoundException
- */
- private static PrivacyLevel getPrivacyLevel(String privacyLevel) throws PrivacyLevelTypeNotFoundException {
- 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
- * @throws FeedTypeNotFoundException .
- */
- private static FeedType getFeedType(String type) throws FeedTypeNotFoundException {
- 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);
- }
- /**
- * simply return an enum representing the feed type
- * @param type .
- * @return correct enum representing the feed type
- * @throws FeedTypeNotFoundException .
- */
- private static PostType getPostType(String type) throws FeedTypeNotFoundException {
- 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);
- }
-
- /**
- * simply return an enum representing the invite status type
- * @param type .
- * @return correct enum representing the feed type
- * @throws InviteStatusNotFoundException .
- */
- private static InviteStatus getInviteStatusType(String type) throws InviteStatusNotFoundException {
- switch (type) {
- case "PENDING":
- return InviteStatus.PENDING;
- case "ACCEPTED":
- return InviteStatus.ACCEPTED;
- case "REJECTED":
- return InviteStatus.REJECTED;
- case "RETRACTED":
- return InviteStatus.RETRACTED;
- default:
- throw new InviteStatusNotFoundException("The Invite Status was not recognized should be one of " + InviteStatus.values() + " asked for: " + type);
- }
-
- }
-
- /**
- * simply return an enum representing the feed type
- * @param type .
- * @return correct enum representing the feed type
- * @throws NotificationTypeNotFoundException .
- */
- private static NotificationType getNotificationType(String type) throws NotificationTypeNotFoundException {
- if (type.compareTo("WP_FOLDER_SHARE") == 0) {
- return NotificationType.WP_FOLDER_SHARE;
- }
- else if (type.compareTo("WP_FOLDER_UNSHARE") == 0) {
- return NotificationType.WP_FOLDER_UNSHARE;
- }
- else if (type.compareTo("WP_ADMIN_UPGRADE") == 0) {
- return NotificationType.WP_ADMIN_UPGRADE;
- }
- else if (type.compareTo("WP_ADMIN_DOWNGRADE") == 0) {
- return NotificationType.WP_ADMIN_DOWNGRADE;
- }
- else if (type.compareTo("WP_FOLDER_RENAMED") == 0) {
- return NotificationType.WP_FOLDER_RENAMED;
- }
- else if (type.compareTo("WP_FOLDER_ADDEDUSER") == 0) {
- return NotificationType.WP_FOLDER_ADDEDUSER;
- }
- else if (type.compareTo("WP_FOLDER_REMOVEDUSER") == 0) {
- return NotificationType.WP_FOLDER_REMOVEDUSER;
- }
- else if (type.compareTo("WP_ITEM_DELETE") == 0) {
- return NotificationType.WP_ITEM_DELETE;
- }
- else if (type.compareTo("WP_ITEM_UPDATED") == 0) {
- return NotificationType.WP_ITEM_UPDATED;
- }
- else if (type.compareTo("WP_ITEM_NEW") == 0) {
- return NotificationType.WP_ITEM_NEW;
- }
- else if (type.compareTo("WP_ITEM_RENAMED") == 0) {
- return NotificationType.WP_ITEM_RENAMED;
- }
- else if (type.compareTo("OWN_COMMENT") == 0) {
- return NotificationType.OWN_COMMENT;
- }
- else if (type.compareTo("COMMENT") == 0) {
- return NotificationType.COMMENT;
- }
- else if (type.compareTo("MENTION") == 0) {
- return NotificationType.MENTION;
- }
- else if (type.compareTo("LIKE") == 0) {
- return NotificationType.LIKE;
- }
- else if (type.compareTo("CALENDAR_ADDED_EVENT") == 0) {
- return NotificationType.CALENDAR_ADDED_EVENT;
- }
- else if (type.compareTo("CALENDAR_UPDATED_EVENT") == 0) {
- return NotificationType.CALENDAR_UPDATED_EVENT;
- }
- else if (type.compareTo("CALENDAR_DELETED_EVENT") == 0) {
- return NotificationType.CALENDAR_DELETED_EVENT;
- }
- else if (type.compareTo("CALENDAR_ADDED_EVENT") == 0) {
- return NotificationType.CALENDAR_ADDED_EVENT;
- }
- else if (type.compareTo("CALENDAR_UPDATED_EVENT") == 0) {
- return NotificationType.CALENDAR_UPDATED_EVENT;
- }
- else if (type.compareTo("CALENDAR_DELETED_EVENT") == 0) {
- return NotificationType.CALENDAR_DELETED_EVENT;
- }
- else if (type.compareTo("MESSAGE") == 0) {
- return NotificationType.MESSAGE;
- }
- else if (type.compareTo("POST_ALERT") == 0) {
- return NotificationType.POST_ALERT;
- }
- else if (type.compareTo("REQUEST_CONNECTION") == 0) {
- return NotificationType.REQUEST_CONNECTION;
- }
- else if (type.compareTo("JOB_COMPLETED_NOK") == 0) {
- return NotificationType.JOB_COMPLETED_NOK;
- }
- else if (type.compareTo("JOB_COMPLETED_OK") == 0) {
- return NotificationType.JOB_COMPLETED_OK;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_EDIT") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_EDIT;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_VIEW") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_VIEW;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_STEP_FORWARD_PEER") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_STEP_FORWARD_PEER;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_STEP_REQUEST_TASK") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER;
- }
- else if (type.compareTo("DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT") == 0) {
- return NotificationType.DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT;
- }
- else if (type.compareTo("TDM_TAB_RESOURCE_SHARE") == 0) {
- return NotificationType.TDM_TAB_RESOURCE_SHARE;
- }
- else if (type.compareTo("TDM_RULE_SHARE") == 0) {
- return NotificationType.TDM_RULE_SHARE;
- }
- else if (type.compareTo("TDM_TEMPLATE_SHARE") == 0) {
- return NotificationType.TDM_TEMPLATE_SHARE;
- }
- else if (type.compareTo("CAT_ITEM_SUBMITTED") == 0) {
- return NotificationType.CAT_ITEM_SUBMITTED;
- }
- else if (type.compareTo("CAT_ITEM_REJECTED") == 0) {
- return NotificationType.CAT_ITEM_REJECTED;
- }
- else if (type.compareTo("CAT_ITEM_PUBLISHED") == 0) {
- return NotificationType.CAT_ITEM_PUBLISHED;
- }
- else if (type.compareTo("CAT_ITEM_UPDATED") == 0) {
- return NotificationType.CAT_ITEM_UPDATED;
- }
- else if (type.compareTo("CAT_ITEM_DELETE") == 0) {
- return NotificationType.CAT_ITEM_DELETE;
- }
- else if (type.compareTo("GENERIC") == 0) {
- return NotificationType.GENERIC;
- }
-
- else
- throw new NotificationTypeNotFoundException("The Notification Type was not recognized should be one of " + NotificationType.values() + " asked for: " + type);
- }
- /**
- *
- * @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;
- try {
- 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());
- }
- CqlSession session = conn.getKeyspaceSession();
- //an entry in the feed CF
- try {
- session.execute(updatePostEntry(session, COMMENTS_NO).bind((long) newCount, UUID.fromString(toUpdate.getKey())));
-
- } catch (Exception e) {
- _log.error("CommentsNo update NOT OK ");
-
- 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;
- try {
- 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());
- }
- CqlSession session = conn.getKeyspaceSession();
- //an entry in the feed CF
- try {
- session.execute(updatePostEntry(session, LIKES_NO).bind((long)newCount, UUID.fromString(toUpdate.getKey())));
-
- } catch (Exception e) {
- _log.error("LikesNo update NOT OK ");
-
- return false;
- }
- _log.info("LikesNo update OK to: " + newCount);
- return true;
- }
-
- /**
- * update the hashtag count by incrementing or decrementing it by (1)
- * 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 vreHashtags = getVREHashtagsWithOccurrence(vreid);
- //if the hashtag not yet exist
- int newCount = 0;
-
- if (!vreHashtags.containsKey(hashtag)) {
- newCount = 1;
- }
- else {
- try {
- int current = vreHashtags.get(hashtag);
- newCount = increment ? current+1 : current-1;
- }
- catch (NumberFormatException e) {
- _log.error("Hashtag Number found is not a number: " + newCount);
- }
- }
- _log.debug("Updating counter for " + hashtag + " to " + newCount);
- 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));
- }
-
- try {
- session.execute(writeBatch);
-
- } catch (Exception e) {
- _log.error("Hashtag Count update NOT OK ");
-
- return false;
- }
- _log.debug("Hashtag Count update OK to: " + newCount);
- return true;
- }
- /**
- * 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;
- }
-
@Override
public List getAllVREIds(){
-
- List ids = new ArrayList<>();
-
- 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());
-
- } catch (Exception e){
- e.printStackTrace();
-
- }
-
- for (Row row : result.all()) {
- ids.add(row.getString(VRE_ID));
- }
-
- _log.debug("VRE ids are " + ids);
-
- return ids;
-
+ return postClient.getAllVREIdsLib();
}
}