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