Added author.

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2023-11-24 11:49:40 +01:00
parent 9ea2895833
commit 36eefcba26
6 changed files with 338 additions and 20 deletions

View File

@ -24,10 +24,14 @@ See [Releases](https://code-repo.d4science.org/gCubeSystem/social-util-library/r
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
## Maintainers
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
## License
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
@ -39,4 +43,4 @@ open-source software toolkit used for building and operating Hybrid Data
Infrastructures enabling the dynamic deployment of Virtual Research Environments
by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)

View File

@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Ahmed Salah Tawfik Ibrahim ISTI-CNR
* @author Ahmed Ibrahim ISTI-CNR
*
*/
public class CassandraClusterConnection {

View File

@ -22,7 +22,8 @@ import static org.gcube.portal.databook.server.Schema.*;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Costantino Perciante ISTI-CNR
* This class is used for querying and adding data to Cassandra via Astyanax High Level API
* @author Ahmed Ibrahim ISTI-CNR
* This class is used for querying and adding data to Cassandra via Datastax High Level API
*/
public final class DBCassandraAstyanaxImpl implements DatabookStore {
@ -549,6 +550,88 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*
*/
private static Post feed2post(Feed feed){
Post post = new Post(feed.getKey(), PostType.valueOf(feed.getType().toString()), feed.getEntityId(), feed.getTime(),
feed.getVreid(), feed.getUri(), feed.getUriThumbnail(), feed.getDescription(), feed.getPrivacy(),
feed.getFullName(), feed.getEmail(), feed.getThumbnailURL(), feed.getCommentsNo(),
feed.getLikesNo(), feed.getLinkTitle(), feed.getLinkDescription(), feed.getLinkHost(), feed.isApplicationFeed(), feed.isMultiFileUpload());
return post;
}
private static Feed post2feed(Post post){
Feed feed = new Feed(post.getKey(), FeedType.valueOf(post.getType().toString()), post.getEntityId(), post.getTime(),
post.getVreid(), post.getUri(), post.getUriThumbnail(), post.getDescription(), post.getPrivacy(),
post.getFullName(), post.getEmail(), post.getThumbnailURL(), post.getCommentsNo(),
post.getLikesNo(), post.getLinkTitle(), post.getLinkDescription(), post.getLinkHost(), post.isApplicationFeed(), post.isMultiFileUpload());
return feed;
}
private List<BoundStatement> insertIntoPosts(CqlSession session, Post post){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO posts("+POST_ID+","+ LINK_HOST+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO posts("+POST_ID+","+ DESCRIPTION+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO posts("+POST_ID+","+ EMAIL+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO posts("+POST_ID+","+ LIKES_NO+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO posts("+POST_ID+","+ THUMBNAIL_URL+") values(?, ?)");
PreparedStatement prepStmt6 = session.prepare("INSERT INTO posts("+POST_ID+","+ LINK_DESCRIPTION+") values(?, ?)");
PreparedStatement prepStmt7 = session.prepare("INSERT INTO posts("+POST_ID+","+ TIMESTAMP+") values(?, ?)");
PreparedStatement prepStmt8 = session.prepare("INSERT INTO posts("+POST_ID+","+ URI+") values(?, ?)");
PreparedStatement prepStmt9 = session.prepare("INSERT INTO posts("+POST_ID+","+ IS_APPLICATION_POST+") values(?, ?)");
PreparedStatement prepStmt10 = session.prepare("INSERT INTO posts("+POST_ID+","+ ENTITY_ID+") values(?, ?)");
PreparedStatement prepStmt11 = session.prepare("INSERT INTO posts("+POST_ID+","+ PRIVACY+") values(?, ?)");
PreparedStatement prepStmt12 = session.prepare("INSERT INTO posts("+POST_ID+","+ TYPE+") values(?, ?)");
PreparedStatement prepStmt13 = session.prepare("INSERT INTO posts("+POST_ID+","+ URI_THUMBNAIL+") values(?, ?)");
PreparedStatement prepStmt14 = session.prepare("INSERT INTO posts("+POST_ID+","+ VRE_ID+") values(?, ?)");
PreparedStatement prepStmt15 = session.prepare("INSERT INTO posts("+POST_ID+","+ MULTI_FILE_UPLOAD+") values(?, ?)");
PreparedStatement prepStmt16 = session.prepare("INSERT INTO posts("+POST_ID+","+ FULL_NAME+") values(?, ?)");
PreparedStatement prepStmt17 = session.prepare("INSERT INTO posts("+POST_ID+","+ COMMENTS_NO+") values(?, ?)");
PreparedStatement prepStmt18 = session.prepare("INSERT INTO posts("+POST_ID+","+ LINK_TITLE+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
if(post.getLinkHost()!=null){
boundStatements.add(prepStmt1.bind(UUID.fromString(post.getKey()), post.getLinkHost()));
}
if(post.getDescription()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(post.getKey()), post.getDescription()));
}
if(post.getEmail()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(post.getKey()), post.getEmail()));
}
if(post.getLikesNo()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(post.getKey()), Long.parseLong(post.getLikesNo())));
}if(post.getThumbnailURL()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(post.getKey()), post.getThumbnailURL()));
}if(post.getLinkDescription()!=null){
boundStatements.add(prepStmt6.bind(UUID.fromString(post.getKey()), post.getLinkDescription()));
}if(post.getTime()!=null){
boundStatements.add(prepStmt7.bind(UUID.fromString(post.getKey()), post.getTime().toInstant()));
}if(post.getUri()!=null){
boundStatements.add(prepStmt8.bind(UUID.fromString(post.getKey()), post.getUri()));
}
boundStatements.add(prepStmt9.bind(UUID.fromString(post.getKey()), post.isApplicationFeed()));
if(post.getEntityId()!=null){
boundStatements.add(prepStmt10.bind(UUID.fromString(post.getKey()), post.getEntityId()));
}if(post.getPrivacy()!=null){
boundStatements.add(prepStmt11.bind(UUID.fromString(post.getKey()), post.getPrivacy().toString()));
}if(post.getType()!=null){
boundStatements.add(prepStmt12.bind(UUID.fromString(post.getKey()), post.getType().toString()));
}if(post.getUriThumbnail()!=null){
boundStatements.add(prepStmt13.bind(UUID.fromString(post.getKey()), post.getUriThumbnail()));
}if(post.getVreid()!=null){
boundStatements.add(prepStmt14.bind(UUID.fromString(post.getKey()), post.getVreid()));
}
boundStatements.add(prepStmt15.bind(UUID.fromString(post.getKey()), post.isMultiFileUpload()));
if(post.getFullName()!=null){
boundStatements.add(prepStmt16.bind(UUID.fromString(post.getKey()), post.getFullName()));
}if(post.getCommentsNo()!=null){
boundStatements.add(prepStmt17.bind(UUID.fromString(post.getKey()), Long.parseLong(post.getCommentsNo())));
}if(post.getLinkTitle()!=null){
boundStatements.add(prepStmt18.bind(UUID.fromString(post.getKey()), post.getLinkTitle()));
}
return boundStatements;
}
/**
* {@inheritDoc}
*/
@ -557,9 +640,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public boolean saveUserFeed(Feed post) {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoPosts(session, feed2post(post));
boundStatements.forEach(stmt -> writeBatch.add(stmt));
//an entry in posts
PreparedStatement stmt1 = createPostEntry(session);
/*PreparedStatement stmt1 = createPostEntry(session);
writeBatch.add(stmt1.bind(UUID.fromString(post.getKey()),
post.getLinkHost(),
post.getDescription(),
@ -579,6 +665,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
post.getFullName(),
post.getCommentsNo()!=null?Long.parseLong(post.getCommentsNo()):null,
post.getLinkTitle()));
*/
//an entry in the user Timeline
PreparedStatement stmt2 = createUserTimelineEntry(session);
@ -590,6 +677,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
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());
@ -605,9 +693,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public boolean saveUserPost(Post post) {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoPosts(session, post);
boundStatements.forEach(stmt -> writeBatch.add(stmt));
//an entry in posts
PreparedStatement stmt1 = createPostEntry(session);
/*PreparedStatement stmt1 = createPostEntry(session);
writeBatch.add(stmt1.bind(UUID.fromString(post.getKey()),
post.getLinkHost(),
post.getDescription(),
@ -626,7 +715,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
post.isMultiFileUpload(),
post.getFullName(),
post.getCommentsNo()!=null?Long.parseLong(post.getCommentsNo()):null,
post.getLinkTitle()));
post.getLinkTitle()));*/
//an entry in the user Timeline
PreparedStatement stmt2 = createUserTimelineEntry(session);
@ -695,8 +784,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoPosts(session, feed2post(post));
boundStatements.forEach(stmt -> writeBatch.add(stmt));
//an entry to posts
PreparedStatement stmt1 = createPostEntry(session);
/*PreparedStatement stmt1 = createPostEntry(session);
writeBatch.add(stmt1.bind(UUID.fromString(post.getKey()),
post.getLinkHost(),
post.getDescription(),
@ -715,7 +806,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
post.isMultiFileUpload(),
post.getFullName(),
post.getCommentsNo()!=null?Long.parseLong(post.getCommentsNo()):null,
post.getLinkTitle()));
post.getLinkTitle()));*/
//an entry in the Applications Timeline
@ -743,8 +834,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoPosts(session, post);
boundStatements.forEach(stmt -> writeBatch.add(stmt));
//an entry to posts
PreparedStatement stmt1 = createPostEntry(session);
/*PreparedStatement stmt1 = createPostEntry(session);
writeBatch.add(stmt1.bind(UUID.fromString(post.getKey()),
post.getLinkHost(),
post.getDescription(),
@ -763,7 +856,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
post.isMultiFileUpload(),
post.getFullName(),
post.getCommentsNo()!=null?Long.parseLong(post.getCommentsNo()):null,
post.getLinkTitle()));
post.getLinkTitle()));*/
//an entry in the Applications Timeline
@ -1691,6 +1784,52 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
********************** NOTIFICATIONS ***********************
*
*/
private List<BoundStatement> insertIntoNotifications(CqlSession session, Notification notification){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ TYPE+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ USER_ID+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ SUBJECT_ID+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ TIMESTAMP+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ DESCRIPTION+") values(?, ?)");
PreparedStatement prepStmt6 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ URI+") values(?, ?)");
PreparedStatement prepStmt7 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ SENDER_ID+") values(?, ?)");
PreparedStatement prepStmt8 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ SENDER_FULL_NAME+") values(?, ?)");
PreparedStatement prepStmt9 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ SENDER_THUMBNAIL_URL+") values(?, ?)");
PreparedStatement prepStmt10 = session.prepare("INSERT INTO notifications("+NOT_ID+","+ IS_READ+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
if(notification.getType()!=null){
boundStatements.add(prepStmt1.bind(UUID.fromString(notification.getKey()),notification.getType().toString()));
}
if(notification.getUserid()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(notification.getKey()), notification.getUserid()));
}
if(notification.getSubjectid()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(notification.getKey()), notification.getSubjectid()));
}
if(notification.getTime()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(notification.getKey()),notification.getTime().toInstant()));
}
if(notification.getDescription()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(notification.getKey()),notification.getDescription()));
}if(notification.getUri()!=null){
boundStatements.add(prepStmt6.bind(UUID.fromString(notification.getKey()),notification.getUri()));
}if(notification.getSenderid()!=null){
boundStatements.add(prepStmt7.bind(UUID.fromString(notification.getKey()),notification.getSenderid()));
}if(notification.getSenderFullName()!=null){
boundStatements.add(prepStmt8.bind(UUID.fromString(notification.getKey()),notification.getSenderFullName()));
}if(notification.getSenderThumbnail()!=null){
boundStatements.add(prepStmt9.bind(UUID.fromString(notification.getKey()),notification.getSenderThumbnail()));
}
boundStatements.add(prepStmt10.bind(UUID.fromString(notification.getKey()),notification.isRead()));
return boundStatements;
}
/**
* {@inheritDoc}
*/
@ -1699,6 +1838,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoNotifications(session, n);
boundStatements.forEach(stmt -> writeBatch.add(stmt));
/*
//notification entry
PreparedStatement stmt1 = createNotificationEntry(session);
writeBatch.add(stmt1.bind(UUID.fromString(n.getKey()),
@ -1712,7 +1855,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
n.getSenderFullName(),
n.getSenderThumbnail(),
n.isRead()));
*/
//an entry in the user Notifications Timeline
PreparedStatement stmt2 = createUserNotificationsEntry(session);
@ -1761,7 +1904,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
BatchStatement writeBatch = getBatch();
//update the entry in notifications
writeBatch.add(updateNotificationEntry(session,IS_READ).bind(UUID.fromString(notificationidToSet), true));
writeBatch.add(updateNotificationEntry(session,IS_READ).bind(true,UUID.fromString(notificationidToSet)));
// delete the notification's key from the unread notifications column family
writeBatch.add(deleteUnreadNotEntry(session).bind(toSet.getUserid(), toSet.getTime().toInstant()));
@ -2131,6 +2274,40 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
********************** COMMENTS ***********************
*
*/
private List<BoundStatement> insertIntoComments(CqlSession session, Comment comment){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ USER_ID+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ FULL_NAME+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ THUMBNAIL_URL+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ COMMENT+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ POST_ID+") values(?, ?)");
PreparedStatement prepStmt6 = session.prepare("INSERT INTO comments("+COMMENT_ID+","+ TIMESTAMP+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
if(comment.getUserid()!=null){
boundStatements.add(prepStmt1.bind(UUID.fromString(comment.getKey()),comment.getUserid()));
}
if(comment.getFullName()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(comment.getKey()), comment.getFullName()));
}
if(comment.getThumbnailURL()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(comment.getKey()), comment.getThumbnailURL()));
}
if(comment.getText()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(comment.getKey()),comment.getText()));
}
if(comment.getFeedid()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(comment.getKey()),UUID.fromString(comment.getFeedid())));
}if(comment.getTime()!=null){
boundStatements.add(prepStmt6.bind(UUID.fromString(comment.getKey()),comment.getTime().toInstant()));
}
return boundStatements;
}
/**
* {@inheritDoc}
*/
@ -2154,6 +2331,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
BatchStatement writeBatch = getBatch();
List<BoundStatement> boundStatements = insertIntoComments(session, comment);
boundStatements.forEach(stmt->writeBatch.add(stmt));
/*
writeBatch.add(createNewCommentEntry(session).bind(
UUID.fromString(comment.getKey()),
comment.getUserid(),
@ -2163,7 +2343,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
UUID.fromString(comment.getFeedid()),
comment.getTime().toInstant(),
null
));
));*/
try {
session.execute(writeBatch);
@ -2363,6 +2543,38 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
return updateCommentNoResult;
}
private List<BoundStatement> insertIntoLikes(CqlSession session, Like like){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO likes("+LIKE_ID+","+ USER_ID+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO likes("+LIKE_ID+","+ FULL_NAME+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO likes("+LIKE_ID+","+ THUMBNAIL_URL+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO likes("+LIKE_ID+","+ POST_ID+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO likes("+LIKE_ID+","+ TIMESTAMP+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
if(like.getUserid()!=null){
boundStatements.add(prepStmt1.bind(UUID.fromString(like.getKey()),like.getUserid()));
}
if(like.getFullName()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(like.getKey()), like.getFullName()));
}
if(like.getThumbnailURL()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(like.getKey()), like.getThumbnailURL()));
}
if(like.getFeedid()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(like.getKey()),UUID.fromString(like.getFeedid())));
}if(like.getTime()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(like.getKey()),like.getTime().toInstant()));
}
return boundStatements;
}
/**
* {@inheritDoc}
*/
@ -2392,8 +2604,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
// 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()),
BatchStatement writeBatch = getBatch().
//List<BoundStatement> boundStatements = insertIntoLikes(session,like);
//boundStatements.forEach(stmt->writeBatch.add(stmt));
add(createNewLikeEntry(session).bind(UUID.fromString(like.getKey()),
like.getUserid(),
like.getFullName(),
like.getThumbnailURL(),
@ -2972,6 +3187,47 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
********************** Invites ***********************
*
*/
private List<BoundStatement> insertIntoInvites(CqlSession session, Invite invite){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ SENDER_USER_ID+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ VRE_ID+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ EMAIL+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ CONTROL_CODE+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ STATUS+") values(?, ?)");
PreparedStatement prepStmt6 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ TIMESTAMP+") values(?, ?)");
PreparedStatement prepStmt7 = session.prepare("INSERT INTO invites("+INVITE_ID+","+ SENDER_FULL_NAME+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
if(invite.getSenderUserId()!=null){
boundStatements.add(prepStmt1.bind(UUID.fromString(invite.getKey()),invite.getSenderUserId()));
}
if(invite.getVreid()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(invite.getKey()), invite.getVreid()));
}
if(invite.getInvitedEmail()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(invite.getKey()), invite.getInvitedEmail()));
}
if(invite.getControlCode()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(invite.getKey()),invite.getControlCode()));
}
if(invite.getStatus()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(invite.getKey()),invite.getStatus().toString()));
}
if(invite.getTime()!=null){
boundStatements.add(prepStmt6.bind(UUID.fromString(invite.getKey()),invite.getTime().toInstant()));
}
if(invite.getSenderFullName()!=null){
boundStatements.add(prepStmt7.bind(UUID.fromString(invite.getKey()),invite.getSenderFullName()));
}
return boundStatements;
}
/**
* common part to save a invite
* @param invite
@ -2979,10 +3235,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
*/
private BatchStatement initSaveInvite(Invite invite, CqlSession session) {
BatchStatement writeBatch = getBatch();
if (invite == null)
throw new NullArgumentException("Invite instance is null");
insertIntoInvites(session,invite).forEach(stmt->writeBatch.add(stmt));
// Inserting data
writeBatch.add(createNewInviteEntry(session).bind(
/*writeBatch.add(createNewInviteEntry(session).bind(
UUID.fromString(invite.getKey()),
invite.getSenderUserId(),
invite.getVreid(),
@ -2991,7 +3249,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
invite.getStatus().toString(),
invite.getTime().toInstant(),
invite.getSenderFullName()
));
));*/
return writeBatch;
@ -3205,6 +3463,42 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
********************** Helper methods ***********************
*
*/
private List<BoundStatement> insertIntoAttachments(CqlSession session, Attachment attachment, String feedId){
PreparedStatement prepStmt1 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ POST_ID+") values(?, ?)");
PreparedStatement prepStmt2 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ URI+") values(?, ?)");
PreparedStatement prepStmt3 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ NAME+") values(?, ?)");
PreparedStatement prepStmt4 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ DESCRIPTION+") values(?, ?)");
PreparedStatement prepStmt5 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ URI_THUMBNAIL+") values(?, ?)");
PreparedStatement prepStmt6 = session.prepare("INSERT INTO attachments("+ATTACH_ID+","+ MIME_TYPE+") values(?, ?)");
List<BoundStatement> boundStatements = new ArrayList<>();
boundStatements.add(prepStmt1.bind(UUID.fromString(attachment.getId()),UUID.fromString(feedId)));
if(attachment.getUri()!=null){
boundStatements.add(prepStmt2.bind(UUID.fromString(attachment.getId()), attachment.getUri()));
}
if(attachment.getName()!=null){
boundStatements.add(prepStmt3.bind(UUID.fromString(attachment.getId()), attachment.getName()));
}
if(attachment.getDescription()!=null){
boundStatements.add(prepStmt4.bind(UUID.fromString(attachment.getId()),attachment.getDescription()));
}
if(attachment.getThumbnailURL()!=null){
boundStatements.add(prepStmt5.bind(UUID.fromString(attachment.getId()),attachment.getThumbnailURL()));
}
if(attachment.getMimeType()!=null){
boundStatements.add(prepStmt6.bind(UUID.fromString(attachment.getId()),attachment.getMimeType()));
}
return boundStatements;
}
/**
* @param feedId the feedId to which the attachment is attached
* @param toSave the instance to save
@ -3215,6 +3509,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
//an entry in the Attachment CF
try {
List<BoundStatement> boundStatements = insertIntoAttachments(session, toSave, feedId);
BatchStatement writeBatch = getBatch();
boundStatements.forEach(stmt->writeBatch.add(stmt));
session.execute(writeBatch);
/*
session.execute(createNewaAttachEntry(session).bind(
UUID.fromString(toSave.getId()),
UUID.fromString(feedId),
@ -3223,7 +3522,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
toSave.getDescription(),
toSave.getThumbnailURL(),
toSave.getMimeType()
));
));*/
} catch (Exception e) {

View File

@ -27,7 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Ahmed Salah Tawfik Ibrahim ISTI-CNR
* @author Ahmed Ibrahim ISTI-CNR
*
* @version 2.0.0 October 2023
*

View File

@ -1,5 +1,13 @@
package org.gcube.portal.databook.server;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Ahmed Ibrahim ISTI-CNR
*
* @version 2.0.0 October 2023
*
*/
public class Schema {
//Tables
public static final String NOTIFICATIONS = "Notifications";

View File

@ -7,6 +7,13 @@ import org.slf4j.LoggerFactory;
import java.util.List;
/**
* @author Massimiliano Assante ISTI-CNR
* @author Ahmed Ibrahim ISTI-CNR
*
* @version 2.0.0 October 2023
*
*/
public class Tester {
private static DBCassandraAstyanaxImpl store;
private static Logger LOGGER = LoggerFactory.getLogger(Tester.class);