revised writeComment method
This commit is contained in:
parent
cb583b0a50
commit
f67c38ef2d
|
@ -38,6 +38,7 @@ import org.gcube.vomanagement.usermanagement.UserManager;
|
|||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.liferay.portlet.journal.FeedIdException;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
|
@ -185,48 +186,49 @@ public class Comments {
|
|||
public Response writeComment(
|
||||
@NotNull(message="Comment to write is missing")
|
||||
@Valid
|
||||
CommentInputBean comment) throws ValidationException{
|
||||
|
||||
CommentInputBean comment) throws ValidationException {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
logger.debug("Request of writing a comment coming from user " + username);
|
||||
String context = ScopeProvider.instance.get();
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.OK;
|
||||
// parse
|
||||
String postId = comment.getPostid();
|
||||
String commentText = comment.getText();
|
||||
String userid = username;
|
||||
Date time = new Date();
|
||||
|
||||
boolean result = false;
|
||||
Comment theComment = null;
|
||||
|
||||
try {
|
||||
String postId = comment.getPostid();
|
||||
String commentText = comment.getText();
|
||||
String userid = username;
|
||||
Date time = new Date();
|
||||
|
||||
String postOwnerId = CassandraConnection.getInstance().getDatabookStore().readPost(postId).getKey();
|
||||
theComment = SocialUtils.commentPost(userid, time, postId, commentText, postOwnerId, context);
|
||||
logger.info("Added comment " + theComment.toString());
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
Comment theComment = SocialUtils.commentPost(userid, time, postId, commentText, postOwnerId, context);
|
||||
if (theComment != null)
|
||||
logger.info("Added comment " + theComment.toString());
|
||||
else {
|
||||
logger.error("Unable to write comment");
|
||||
responseBean.setMessage("Unable to write comment, something went wrong please see server log");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
responseBean.setResult(true);
|
||||
responseBean.setSuccess(true);
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
} catch(FeedIDNotFoundException ex) {
|
||||
logger.error("Unable to find a post comment", ex);
|
||||
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
catch(Exception e) {
|
||||
logger.error("Unable to write comment", e);
|
||||
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
if(theComment != null){
|
||||
logger.info("Comment correctly written by user " + username);
|
||||
responseBean.setResult(result);
|
||||
responseBean.setSuccess(true);
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
|
||||
} else {
|
||||
logger.error("Unable to write comment.");
|
||||
responseBean.setMessage("Unable to write comment");
|
||||
responseBean.setSuccess(false);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue