-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
CollectionResourceWorkflowGroupHalLinkFactory.java
65 lines (56 loc) · 2.46 KB
/
CollectionResourceWorkflowGroupHalLinkFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.link;
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
import org.dspace.app.rest.CollectionGroupRestController;
import org.dspace.app.rest.model.hateoas.CollectionResource;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.content.Collection;
import org.dspace.content.service.CollectionService;
import org.dspace.core.Context;
import org.dspace.services.RequestService;
import org.dspace.xmlworkflow.Role;
import org.dspace.xmlworkflow.WorkflowUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Component;
/**
* This class makes sure that the workflowGroup links with the relevant WorkflowRoles are added
* to the CollectionResource in a dynamic way depending on what workflow is enabled for the collection
*/
@Component
public class CollectionResourceWorkflowGroupHalLinkFactory
extends HalLinkFactory<CollectionResource, CollectionGroupRestController> {
@Autowired
private CollectionService collectionService;
@Autowired
private RequestService requestService;
@Override
protected void addLinks(CollectionResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
Context context = ContextUtil.obtainContext(requestService.getCurrentRequest().getHttpServletRequest());
Collection collection = collectionService.find(context, UUID.fromString(halResource.getContent().getId()));
Map<String, Role> roles = WorkflowUtils.getCollectionRoles(collection);
UUID resourceUuid = UUID.fromString(halResource.getContent().getUuid());
for (Map.Entry<String, Role> entry : roles.entrySet()) {
list.add(buildLink("workflowGroups", getMethodOn()
.getWorkflowGroupForRole(resourceUuid, null, null,
entry.getKey())).withName(entry.getKey()));
}
}
@Override
protected Class<CollectionGroupRestController> getControllerClass() {
return CollectionGroupRestController.class;
}
@Override
protected Class<CollectionResource> getResourceClass() {
return CollectionResource.class;
}
}