Skip to content

Commit f3f6052

Browse files
Added support to create, get and delete group identity links on case and process instances
1 parent 31bc0f1 commit f3f6052

File tree

10 files changed

+322
-72
lines changed

10 files changed

+322
-72
lines changed

modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/CmmnRestResponseFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public RestIdentityLink createRestIdentityLink(String type, String userId, Strin
443443
}
444444

445445
if (caseInstanceId != null) {
446-
result.setUrl(urlBuilder.buildUrl(CmmnRestUrls.URL_CASE_INSTANCE_IDENTITYLINK, caseInstanceId, (userId != null ? userId : groupId), type));
446+
result.setUrl(urlBuilder.buildUrl(CmmnRestUrls.URL_CASE_INSTANCE_IDENTITYLINK, caseInstanceId, family, (userId != null ? userId : groupId), type));
447447
} else if (taskId != null) {
448448
result.setUrl(urlBuilder.buildUrl(CmmnRestUrls.URL_TASK_IDENTITYLINK, taskId, family, (userId != null ? userId : groupId), type));
449449
} else if (caseDefinitionId != null) {

modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/CmmnRestUrls.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,9 @@ public final class CmmnRestUrls {
292292
public static final String[] URL_CASE_INSTANCE_IDENTITYLINKS_COLLECTION = { SEGMENT_RUNTIME_RESOURCES, SEGMENT_CASE_INSTANCE_RESOURCE, "{0}", SEGMENT_IDENTITYLINKS };
293293

294294
/**
295-
* URL template for an identitylink on a case instance: <i>cmmn-runtime/case-instances/{0:caseInstanceId}/identitylinks/users/{1: identityId}/{2:type}</i>
295+
* URL template for an identitylink on a case instance: <i>cmmn-runtime/case-instances/{0:caseInstanceId}/identitylinks/{1: family}/{2: identityId}/{3:type}</i>
296296
*/
297-
public static final String[] URL_CASE_INSTANCE_IDENTITYLINK = { SEGMENT_RUNTIME_RESOURCES, SEGMENT_CASE_INSTANCE_RESOURCE, "{0}", SEGMENT_IDENTITYLINKS,
298-
SEGMENT_IDENTITYLINKS_FAMILY_USERS, "{1}", "{2}" };
297+
public static final String[] URL_CASE_INSTANCE_IDENTITYLINK = { SEGMENT_RUNTIME_RESOURCES, SEGMENT_CASE_INSTANCE_RESOURCE, "{0}", SEGMENT_IDENTITYLINKS, "{1}", "{2}", "{3}" };
299298

300299
/**
301300
* URL template for plan item instance collection: <i>cmmn-runtime/plan-item-instances</i>

modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/caze/CaseInstanceIdentityLinkCollectionResource.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.util.List;
1717

18+
import org.apache.commons.lang3.StringUtils;
1819
import org.flowable.cmmn.api.runtime.CaseInstance;
1920
import org.flowable.cmmn.rest.service.api.engine.RestIdentityLink;
2021
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
@@ -71,12 +72,12 @@ public RestIdentityLink createIdentityLink(@ApiParam(name = "caseInstanceId") @P
7172

7273
CaseInstance caseInstance = getCaseInstanceFromRequestWithoutAccessCheck(caseInstanceId);
7374

74-
if (identityLink.getGroup() != null) {
75-
throw new FlowableIllegalArgumentException("Only user identity links are supported on a case instance.");
75+
if (identityLink.getGroup() == null && identityLink.getUser() == null) {
76+
throw new FlowableIllegalArgumentException("User or group are required.");
7677
}
77-
78-
if (identityLink.getUser() == null) {
79-
throw new FlowableIllegalArgumentException("The user is required.");
78+
79+
if (StringUtils.isEmpty(identityLink.getGroup()) && StringUtils.isEmpty(identityLink.getUser())) {
80+
throw new FlowableIllegalArgumentException("Only one value of user or group is supported.");
8081
}
8182

8283
if (identityLink.getType() == null) {
@@ -87,7 +88,12 @@ public RestIdentityLink createIdentityLink(@ApiParam(name = "caseInstanceId") @P
8788
restApiInterceptor.createCaseInstanceIdentityLink(caseInstance, identityLink);
8889
}
8990

90-
runtimeService.addUserIdentityLink(caseInstance.getId(), identityLink.getUser(), identityLink.getType());
91+
if (StringUtils.isNotEmpty(identityLink.getGroup())) {
92+
runtimeService.addGroupIdentityLink(caseInstance.getId(), identityLink.getGroup(), identityLink.getType());
93+
94+
} else {
95+
runtimeService.addUserIdentityLink(caseInstance.getId(), identityLink.getUser(), identityLink.getType());
96+
}
9197

9298
return restResponseFactory.createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, caseInstance.getId());
9399
}

modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/caze/CaseInstanceIdentityLinkResource.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.flowable.cmmn.api.runtime.CaseInstance;
19+
import org.flowable.cmmn.rest.service.api.CmmnRestUrls;
1920
import org.flowable.cmmn.rest.service.api.engine.RestIdentityLink;
2021
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
2122
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
@@ -42,20 +43,22 @@
4243
public class CaseInstanceIdentityLinkResource extends BaseCaseInstanceResource {
4344

4445

45-
@ApiOperation(value = "Get a specific involved people from case instance", tags = { "Case Instance Identity Links" }, nickname = "getCaseInstanceIdentityLinks")
46+
@ApiOperation(value = "Get a single identity link on a case instance", tags = { "Case Instance Identity Links" }, nickname = "getCaseInstanceIdentityLinks")
4647
@ApiResponses(value = {
4748
@ApiResponse(code = 200, message = "Indicates the case instance was found and the specified link is retrieved."),
4849
@ApiResponse(code = 404, message = "Indicates the requested case instance was not found or the link to delete does not exist. The response status contains additional information about the error.")
4950
})
50-
@GetMapping(value = "/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/users/{identityId}/{type}", produces = "application/json")
51-
public RestIdentityLink getIdentityLinkRequest(@ApiParam(name = "caseInstanceId") @PathVariable("caseInstanceId") String caseInstanceId, @ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
51+
@GetMapping(value = "/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/{family}/{identityId}/{type}", produces = "application/json")
52+
public RestIdentityLink getIdentityLinkRequest(@ApiParam(name = "caseInstanceId") @PathVariable("caseInstanceId") String caseInstanceId,
53+
@ApiParam(name = "family") @PathVariable("family") String family,
54+
@ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
5255
@ApiParam(name = "type") @PathVariable("type") String type) {
5356

5457
CaseInstance caseInstance = getCaseInstanceFromRequestWithoutAccessCheck(caseInstanceId);
5558

56-
validateIdentityLinkArguments(identityId, type);
59+
validateIdentityLinkArguments(family, identityId, type);
5760

58-
IdentityLink link = getIdentityLink(identityId, type, caseInstance.getId());
61+
IdentityLink link = getIdentityLink(identityId, family, type, caseInstance.getId());
5962

6063
if (restApiInterceptor != null) {
6164
restApiInterceptor.accessCaseInstanceIdentityLink(caseInstance, link);
@@ -64,30 +67,40 @@ public RestIdentityLink getIdentityLinkRequest(@ApiParam(name = "caseInstanceId"
6467
return restResponseFactory.createRestIdentityLink(link);
6568
}
6669

67-
@ApiOperation(value = "Remove an involved user to from case instance", tags = { "Case Instance Identity Links" }, nickname = "deleteCaseInstanceIdentityLinks", code = 204)
70+
@ApiOperation(value = "Delete an identity link on a case instance", tags = { "Case Instance Identity Links" }, nickname = "deleteCaseInstanceIdentityLinks", code = 204)
6871
@ApiResponses(value = {
6972
@ApiResponse(code = 204, message = "Indicates the case instance was found and the link has been deleted. Response body is left empty intentionally."),
7073
@ApiResponse(code = 404, message = "Indicates the requested case instance was not found or the link to delete does not exist. The response status contains additional information about the error.")
7174
})
72-
@DeleteMapping(value = "/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/users/{identityId}/{type}")
75+
@DeleteMapping(value = "/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/{family}/{identityId}/{type}")
7376
@ResponseStatus(HttpStatus.NO_CONTENT)
74-
public void deleteIdentityLink(@ApiParam(name = "caseInstanceId") @PathVariable("caseInstanceId") String caseInstanceId, @ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
77+
public void deleteIdentityLink(@ApiParam(name = "caseInstanceId") @PathVariable("caseInstanceId") String caseInstanceId,
78+
@ApiParam(name = "family") @PathVariable("family") String family,
79+
@ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
7580
@ApiParam(name = "type") @PathVariable("type") String type) {
7681

7782
CaseInstance caseInstance = getCaseInstanceFromRequestWithoutAccessCheck(caseInstanceId);
7883

79-
validateIdentityLinkArguments(identityId, type);
84+
validateIdentityLinkArguments(family, identityId, type);
8085

81-
IdentityLink link = getIdentityLink(identityId, type, caseInstance.getId());
86+
IdentityLink link = getIdentityLink(identityId, family, type, caseInstance.getId());
8287

8388
if (restApiInterceptor != null) {
8489
restApiInterceptor.deleteCaseInstanceIdentityLink(caseInstance, link);
8590
}
8691

87-
runtimeService.deleteUserIdentityLink(caseInstance.getId(), identityId, type);
92+
if (CmmnRestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family)) {
93+
runtimeService.deleteGroupIdentityLink(caseInstance.getId(), identityId, type);
94+
95+
} else {
96+
runtimeService.deleteUserIdentityLink(caseInstance.getId(), identityId, type);
97+
}
8898
}
8999

90-
protected void validateIdentityLinkArguments(String identityId, String type) {
100+
protected void validateIdentityLinkArguments(String family, String identityId, String type) {
101+
if (family == null || (!CmmnRestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !CmmnRestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
102+
throw new FlowableIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
103+
}
91104
if (identityId == null) {
92105
throw new FlowableIllegalArgumentException("IdentityId is required.");
93106
}
@@ -96,12 +109,15 @@ protected void validateIdentityLinkArguments(String identityId, String type) {
96109
}
97110
}
98111

99-
protected IdentityLink getIdentityLink(String identityId, String type, String caseInstanceId) {
112+
protected IdentityLink getIdentityLink(String identityId, String family, String type, String caseInstanceId) {
100113
// Perhaps it would be better to offer getting a single identity link
101114
// from the API
102115
List<IdentityLink> allLinks = runtimeService.getIdentityLinksForCaseInstance(caseInstanceId);
103116
for (IdentityLink link : allLinks) {
104-
if (identityId.equals(link.getUserId()) && link.getType().equals(type)) {
117+
if (CmmnRestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family) && identityId.equals(link.getUserId()) && link.getType().equals(type)) {
118+
return link;
119+
120+
} else if (CmmnRestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && identityId.equals(link.getGroupId()) && link.getType().equals(type)) {
105121
return link;
106122
}
107123
}

0 commit comments

Comments
 (0)