提交 a1585890 编写于 作者: B Bassam Al-Sarori

REST Delete ProcessInstance IdentityLink

上级 0319238d
......@@ -22,6 +22,8 @@ import org.activiti.engine.task.IdentityLink;
import org.activiti.rest.common.api.ActivitiUtil;
import org.activiti.rest.service.api.engine.RestIdentityLink;
import org.activiti.rest.service.application.ActivitiRestServicesApplication;
import org.restlet.data.Status;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
......@@ -47,6 +49,25 @@ public class ProcessInstanceIdentityLinkResource extends BaseProcessInstanceReso
.createRestIdentityLink(this, link);
}
@Delete
public void deleteIdentityLink() {
if(!authenticate())
return;
ProcessInstance processInstance = getProcessInstanceFromRequest();
// Extract and validate identity link from URL
String identityId = getAttribute("identityId");
String type = getAttribute("type");
validateIdentityLinkArguments(identityId, type);
getIdentityLink(identityId, type, processInstance.getId());
ActivitiUtil.getRuntimeService().deleteUserIdentityLink(processInstance.getId(), identityId, type);
setStatus(Status.SUCCESS_NO_CONTENT);
}
protected void validateIdentityLinkArguments(String identityId, String type) {
if(identityId == null) {
throw new ActivitiIllegalArgumentException("IdentityId is required.");
......
......@@ -190,4 +190,43 @@ public class ProcessInstanceIdentityLinkResourceTest extends BaseRestTestCase {
assertEquals("Could not find a process instance with id 'unexistingprocess'.", expected.getStatus().getDescription());
}
}
/**
* Test deleting a single identity link for a process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceIdentityLinkResourceTest.process.bpmn20.xml" })
public void testDeleteSingleIdentityLink() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "myType");
ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK,
processInstance.getId(), "kermit", "myType"));
client.delete();
assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK,
processInstance.getId(), "kermit", "myType"));
// Test with unexisting process identity link
try {
client.delete();
fail("Exception expected");
} catch(ResourceException expected) {
assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
assertEquals("Could not find the requested identity link.", expected.getStatus().getDescription());
}
// Test with unexisting process
client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, "unexistingprocess",
RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "myType"));
try {
client.delete();
fail("Exception expected");
} catch (ResourceException expected) {
assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
assertEquals("Could not find a process instance with id 'unexistingprocess'.", expected.getStatus().getDescription());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册