Bugs fixed

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2023-12-04 17:38:33 +01:00
parent b968a6f7dd
commit 785511f6a3
2 changed files with 155 additions and 108 deletions

View File

@ -554,18 +554,52 @@ 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());
Post post = new Post();
if (feed.getKey()!=null)post.setKey(feed.getKey());
if (feed.getType()!=null)post.setType(PostType.valueOf(feed.getType().toString()));
if (feed.getEntityId()!=null)post.setEntityId(feed.getEntityId());
if (feed.getTime()!=null)post.setTime(feed.getTime());
if (feed.getVreid()!=null)post.setVreid(feed.getVreid());
if (feed.getUri()!=null)post.setUri(feed.getUri());
if (feed.getUriThumbnail()!=null)post.setUriThumbnail(feed.getUriThumbnail());
if (feed.getDescription()!=null)post.setDescription(feed.getDescription());
if (feed.getPrivacy()!=null)post.setPrivacy(feed.getPrivacy());
if (feed.getFullName()!=null)post.setFullName(feed.getFullName());
if (feed.getEmail()!=null)post.setEmail(feed.getEmail());
if (feed.getThumbnailURL()!=null)post.setThumbnailURL(feed.getThumbnailURL());
if (feed.getCommentsNo()!=null)post.setCommentsNo(feed.getCommentsNo());
if (feed.getLikesNo()!=null)post.setLikesNo(feed.getLikesNo());
if (feed.getLinkTitle()!=null)post.setLinkTitle(feed.getLinkTitle());
if (feed.getLinkDescription()!=null)post.setLinkDescription(feed.getLinkDescription());
if (feed.getLinkHost()!=null)post.setLinkHost(feed.getLinkHost());
post.setApplicationFeed(feed.isApplicationFeed());
post.setMultiFileUpload(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());
Feed feed = new Feed();
if (post.getKey()!=null)feed.setKey(post.getKey());
if (post.getType()!=null)feed.setType(FeedType.valueOf(post.getType().toString()));
if (post.getEntityId()!=null)feed.setEntityId(post.getEntityId());
if (post.getTime()!=null)feed.setTime(post.getTime());
if (post.getVreid()!=null)feed.setVreid(post.getVreid());
if (post.getUri()!=null)feed.setUri(post.getUri());
if (post.getUriThumbnail()!=null)feed.setUriThumbnail(post.getUriThumbnail());
if (post.getDescription()!=null)feed.setDescription(post.getDescription());
if (post.getPrivacy()!=null)feed.setPrivacy(post.getPrivacy());
if (post.getFullName()!=null)feed.setFullName(post.getFullName());
if (post.getEmail()!=null)feed.setEmail(post.getEmail());
if (post.getThumbnailURL()!=null)feed.setThumbnailURL(post.getThumbnailURL());
if (post.getCommentsNo()!=null)feed.setCommentsNo(post.getCommentsNo());
if (post.getLikesNo()!=null)feed.setLikesNo(post.getLikesNo());
if (post.getLinkTitle()!=null)feed.setLinkTitle(post.getLinkTitle());
if (post.getLinkDescription()!=null)feed.setLinkDescription(post.getLinkDescription());
if (post.getLinkHost()!=null)feed.setLinkHost(post.getLinkHost());
feed.setApplicationFeed(post.isApplicationFeed());
feed.setMultiFileUpload(post.isMultiFileUpload());
return feed;
}
private List<BoundStatement> insertIntoPosts(CqlSession session, Post post){
@ -1049,29 +1083,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} catch (Exception e) {
e.printStackTrace();
}
List<Feed> toReturn = result.all().stream().map(row-> {
try {
List<Feed>toReturn = new ArrayList<>();
List<Row>rows=result.all();
for (Row row: rows){
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) {
toReturn.add(toCheck);
} catch (ColumnNameNotFoundException | PrivacyLevelTypeNotFoundException | FeedTypeNotFoundException |
FeedIDNotFoundException e) {
throw new RuntimeException(e);
}
}
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
return null;
}).collect(Collectors.toList());
return toReturn;
}
/**
@ -1096,29 +1122,21 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} catch (Exception e) {
e.printStackTrace();
}
List<Post> toReturn = result.all().stream().map(row-> {
try {
List<Row>rows = result.all();
List<Post> toReturn = new ArrayList<>();
for (Row row: rows){
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) {
toReturn.add(toCheck);
} catch (ColumnNameNotFoundException | PrivacyLevelTypeNotFoundException | FeedIDNotFoundException |
FeedTypeNotFoundException e) {
throw new RuntimeException(e);
}
}
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
return null;
}).collect(Collectors.toList());
return toReturn;
}
/**
@ -1326,16 +1344,16 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
List<String> toReturn = result.all().stream().map(row-> {
List<Row>rows = result.all();
List<String>toReturn = new ArrayList<>();
for (Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
return (ArrayList<String>) toReturn;
}
/**
@ -1358,17 +1376,17 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
List<String> toReturn = result.all().stream().map(row-> {
ArrayList<String> toReturn = new ArrayList<>();
List<Row>rows = result.all();
for(Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
return (ArrayList<String>) toReturn;
}
return toReturn;
}
/**
@ -1394,7 +1412,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
for (Row row: result.all()){
List<Row>rows = result.all();
for (Row row: rows){
if (row.getUuid(POST_ID).toString().equals(postid)){
return true;
}
@ -1425,17 +1444,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
List<String> toReturn = result.all().stream().map(row-> {
List<Row>rows=result.all();
ArrayList<String> toReturn=new ArrayList<>();
for(Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
return (ArrayList<String>) toReturn;
return toReturn;
}
/**
* helper method that retrieve all the post Ids belonging to an application
@ -1458,16 +1479,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
List<String> toReturn = result.all().stream().map(row-> {
List<Row>rows=result.all();
ArrayList<String> toReturn=new ArrayList<>();
for(Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
return (ArrayList<String>) toReturn;
return toReturn;
}
/**
@ -1492,7 +1516,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
for (Row row: result.all()) {
List<Row>rows=result.all();
for (Row row: rows) {
Feed toAdd = readFeedFromRow(row);
if (toAdd.getType() == FeedType.TWEET || toAdd.getType() == FeedType.SHARE || toAdd.getType() == FeedType.PUBLISH)
toReturn.add(toAdd);
@ -1517,7 +1542,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
e.printStackTrace();
}
for (Row row: result.all()) {
List<Row>rows=result.all();
for (Row row: rows) {
Post toAdd = readPostFromRow(row);
if (toAdd.getType() == PostType.TWEET || toAdd.getType() == PostType.SHARE || toAdd.getType() == PostType.PUBLISH)
toReturn.add(toAdd);
@ -1743,16 +1769,18 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
List<String> toReturn = result.all().stream().map(row-> {
List<Row>rows=result.all();
ArrayList<String> toReturn=new ArrayList<>();
for(Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
return (ArrayList<String>) toReturn;
return toReturn;
}
/**
* get a list of user vre post UUIDs in chronological order from the oldest to the more recent
@ -1775,16 +1803,19 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
List<String> toReturn = result.all().stream().map(row-> {
List<Row>rows=result.all();
ArrayList<String> toReturn=new ArrayList<>();
for(Row row: rows){
try {
String postid = row.getUuid(POST_ID).toString();
return postid;
toReturn.add(postid);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
return (ArrayList<String>) toReturn;
return toReturn;
}
/*
*
@ -1962,7 +1993,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
ArrayList<String> toReturn = new ArrayList<String>();
// Iterate rows and their columns
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
toReturn.add(row.getUuid(NOT_ID).toString());
}
return toReturn;
@ -1991,7 +2023,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
ArrayList<String> toReturn = new ArrayList<String>();
// Iterate rows and their columns
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
toReturn.add(row.getUuid(NOT_ID).toString());
}
return toReturn;
@ -2204,9 +2237,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
for (NotificationType nType : enabledChannels.keySet()) {
String valueToInsert = "";
_log.info("Type: " + nType.toString());
int channelsNo = (enabledChannels.get(nType) != null) ? enabledChannels.get(nType).length : 0;
for (int i = 0; i < channelsNo; i++) {
valueToInsert += enabledChannels.get(nType)[i];
_log.info(enabledChannels.get(nType)[i].toString());
valueToInsert += NotificationChannelType.valueOf(enabledChannels.get(nType)[i].toString());
if (i < channelsNo-1)
valueToInsert += ",";
}
@ -2221,9 +2256,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
BatchStatement writeBatch = getBatch().addAll(boundStatements);
boolean overAllresult = session.execute(writeBatch).wasApplied();
if (overAllresult)
_log.trace("Set Notification Map for " + userid + " OK");
_log.info("Set Notification Map for " + userid + " OK");
else
_log.trace("Set Notification Map for " + userid + " FAILED");
_log.info("Set Notification Map for " + userid + " FAILED");
return overAllresult;
}
/**
@ -2437,8 +2472,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());*/
try {
result = session.execute(stmtFind.bind(UUID.fromString(postid)));
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
Comment toAdd = readCommentFromRow(row);
toReturn.add(toAdd);
}
@ -2645,6 +2680,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
//an entry in the feed CF
//and an entry in the UserLikesCF
List<BoundStatement> boundStatements = insertIntoLikes(session,like);
BoundStatement stmt2 = createNewUserLikesEntry(session).bind(like.getUserid(), UUID.fromString(like.getKey()), UUID.fromString(like.getFeedid()));
boundStatements.add(stmt2);
//boundStatements.forEach(stmt->writeBatch.add(stmt));
BatchStatement writeBatch = getBatch().addAll(boundStatements);
@ -3040,8 +3078,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
HashMap<String, Integer> toReturn = new HashMap<String, Integer> ();
List<Row> rows = result.all();
// Iterate rows and their columns
for (Row row : result.all()) {
for (Row row : rows) {
Integer curValue = (int) row.getLong(COUNT);
if (curValue > 0)
toReturn.put(row.getString(HASHTAG), curValue);
@ -3070,9 +3109,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
HashMap<String, Integer> toReturn = new HashMap<String, Integer> ();
List<Row> rows = result.all();
// Iterate rows and their columns
for (Row row : result.all()) {
for (Row row : rows) {
// retrieve the feeds list for this hashtag
List<Post> feeds = null;
try{
@ -3141,12 +3180,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Set<String> postIds = new HashSet<>();
// Iterate rows and their columns (feed)
for (Row row : resultPost.all()) {
List<Row>rowsPost=resultPost.all();
for (Row row : rowsPost) {
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()) {
List<Row>rowsComment=resultComment.all();
for (Row row : rowsComment) {
if (row.getString(VRE_ID).compareTo(vreid)==0){
try {
Comment c = readCommentById(row.getUuid(COMMENT_ID).toString());
@ -3195,12 +3236,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Set<String> postIds = new HashSet<>();
// Iterate rows and their columns (feed)
for (Row row : resultPost.all()) {
List<Row>rowsPost=resultPost.all();
for (Row row : rowsPost) {
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()) {
List<Row>rowsComment=resultComment.all();
for (Row row : rowsComment) {
if (row.getString(VRE_ID).compareTo(vreid)==0){
try {
Comment c = readCommentById(row.getUuid(COMMENT_ID).toString());
@ -3317,7 +3360,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
// Iterate rows and their columns
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
if (row.getString(VRE_ID).compareTo(vreid)==0)
return row.getUuid(INVITE_ID).toString();
@ -3439,7 +3483,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
ArrayList<String> invitesIds = new ArrayList<String>();
// Iterate rows and their columns
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
if (status != null) {
for (int i = 0; i < status.length; i++) {
if (row.getString(STATUS).compareTo(status[i].toString())==0)
@ -3477,7 +3522,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
result = session.execute(stmtFind.bind(UUID.fromString(feedId)));
// Iterate rows and their columns
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
_log.trace("Reading attachment if feed=" + row.getUuid(POST_ID).toString());
Attachment toAdd = readAttachmentFromRow(row);
toReturn.add(toAdd);
@ -3975,7 +4021,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override
public List<String> getAllVREIds(){
List<String> ids = new ArrayList<>();
Set<String> ids = new HashSet<>();
CqlSession session = conn.getKeyspaceSession();
ResultSet result = null;
@ -3990,13 +4036,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
for (Row row : result.all()) {
List<Row>rows=result.all();
for (Row row : rows) {
ids.add(row.getString(VRE_ID));
}
List<String> toReturn = new ArrayList<>();
toReturn.addAll(ids);
_log.debug("VRE ids are " + ids);
return ids;
return toReturn;
}
}

View File

@ -107,7 +107,7 @@ public class RunningCluster implements Serializable {
host = "10.1.28.55:9042, 10.1.30.142:9042, 10.1.28.100:9042";
datacenterName = "1";
keyspaceName = "dev_mig_new_schema_test";
keyspaceName = "dev_mig_consistent";
}
/**