use of org.kie.server.api.model.cases.CaseComment in project droolsjbpm-integration by kiegroup.
the class CaseManagementServiceBase method getComments.
public CaseCommentList getComments(String containerId, String caseId, String sort, Integer page, Integer pageSize) {
verifyContainerId(containerId, caseId);
CommentSortBy sortBy = parseCommentSortBy(sort);
Collection<CommentInstance> caseComments = caseService.getCaseComments(caseId, sortBy, ConvertUtils.buildQueryContext(page, pageSize));
logger.debug("Comments for case {} are {}", caseId, caseComments);
List<CaseComment> comments = ConvertUtils.transformCaseComments(caseComments);
CaseCommentList commentsList = new CaseCommentList(comments);
return commentsList;
}
use of org.kie.server.api.model.cases.CaseComment in project droolsjbpm-integration by kiegroup.
the class CaseRuntimeDataServiceIntegrationTest method testCreateCaseWithCaseFileWithCommentsWithRestrictions.
@Test
public void testCreateCaseWithCaseFileWithCommentsWithRestrictions() {
String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
// add a contact role to yoda so it can access a case once owner role is removed
caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_CONTACT_ROLE, USER_YODA);
assertNotNull(caseId);
assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
List<CaseComment> comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
List<String> restrictions = new ArrayList<>();
restrictions.add(CASE_OWNER_ROLE);
caseClient.addComment(CONTAINER_ID, caseId, USER_YODA, "first comment", restrictions);
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(1, comments.size());
CaseComment comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("first comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
// remove yoda from owner role to simulate lack of access
caseClient.removeUserFromRole(CONTAINER_ID, caseId, CASE_OWNER_ROLE, USER_YODA);
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
final String commentId = comment.getId();
assertClientException(() -> caseClient.updateComment(CONTAINER_ID, caseId, commentId, USER_YODA, "updated comment"), 403, "");
// add back yoda to owner role
caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_OWNER_ROLE, USER_YODA);
caseClient.updateComment(CONTAINER_ID, caseId, comment.getId(), USER_YODA, "updated comment");
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(1, comments.size());
comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("updated comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
final String updatedCommentId = comment.getId();
// remove yoda from owner role to simulate lack of access
caseClient.removeUserFromRole(CONTAINER_ID, caseId, CASE_OWNER_ROLE, USER_YODA);
assertClientException(() -> caseClient.removeComment(CONTAINER_ID, caseId, updatedCommentId), 403, "");
// add back yoda to owner role
caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_OWNER_ROLE, USER_YODA);
caseClient.removeComment(CONTAINER_ID, caseId, updatedCommentId);
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
}
use of org.kie.server.api.model.cases.CaseComment in project droolsjbpm-integration by kiegroup.
the class CaseRuntimeDataServiceIntegrationTest method testCreateCaseWithCaseFileWithComments.
@Test
public void testCreateCaseWithCaseFileWithComments() {
String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
assertNotNull(caseId);
assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
List<CaseComment> comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
String commentId = caseClient.addComment(CONTAINER_ID, caseId, USER_YODA, "first comment");
assertNotNull(commentId);
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(1, comments.size());
CaseComment comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("first comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
assertEquals(commentId, comment.getId());
caseClient.updateComment(CONTAINER_ID, caseId, comment.getId(), USER_YODA, "updated comment");
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(1, comments.size());
comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("updated comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
caseClient.removeComment(CONTAINER_ID, caseId, comment.getId());
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
}
use of org.kie.server.api.model.cases.CaseComment in project droolsjbpm-integration by kiegroup.
the class CaseRuntimeDataServiceIntegrationTest method testCreateCaseWithCaseFileWithCommentsSorted.
@Test
public void testCreateCaseWithCaseFileWithCommentsSorted() throws Exception {
String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
assertNotNull(caseId);
assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
caseClient.assignUserToRole(CONTAINER_ID, caseId, CASE_CONTACT_ROLE, USER_MARY);
List<CaseComment> comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(0, comments.size());
try {
caseClient.addComment(CONTAINER_ID, caseId, USER_YODA, "yoda's comment");
changeUser(USER_JOHN);
caseClient.addComment(CONTAINER_ID, caseId, USER_JOHN, "john's comment");
changeUser(USER_MARY);
caseClient.addComment(CONTAINER_ID, caseId, USER_MARY, "mary's comment");
comments = caseClient.getComments(CONTAINER_ID, caseId, 0, 10);
assertNotNull(comments);
assertEquals(3, comments.size());
CaseComment comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("yoda's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(1);
assertNotNull(comment);
assertEquals(USER_JOHN, comment.getAuthor());
assertEquals("john's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(2);
assertNotNull(comment);
assertEquals(USER_MARY, comment.getAuthor());
assertEquals("mary's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comments = caseClient.getComments(CONTAINER_ID, caseId, CaseServicesClient.COMMENT_SORT_BY_AUTHOR, 0, 10);
assertNotNull(comments);
assertEquals(3, comments.size());
comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_JOHN, comment.getAuthor());
assertEquals("john's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(1);
assertNotNull(comment);
assertEquals(USER_MARY, comment.getAuthor());
assertEquals("mary's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(2);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("yoda's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comments = caseClient.getComments(CONTAINER_ID, caseId, CaseServicesClient.COMMENT_SORT_BY_DATE, 0, 10);
assertNotNull(comments);
assertEquals(3, comments.size());
comment = comments.get(0);
assertNotNull(comment);
assertEquals(USER_YODA, comment.getAuthor());
assertEquals("yoda's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(1);
assertNotNull(comment);
assertEquals(USER_JOHN, comment.getAuthor());
assertEquals("john's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
comment = comments.get(2);
assertNotNull(comment);
assertEquals(USER_MARY, comment.getAuthor());
assertEquals("mary's comment", comment.getText());
assertNotNull(comment.getAddedAt());
assertNotNull(comment.getId());
} finally {
changeUser(USER_YODA);
}
}
Aggregations