Merge pull request #2911 from atmire/issue-2800-workflowgroup-collection-links

[Issue 2800] workflowgroup collection links
This commit is contained in:
Tim Donohue
2020-08-06 15:52:12 -05:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -47,9 +47,9 @@ public class CollectionResourceWorkflowGroupHalLinkFactory
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/" + entry.getKey(), getMethodOn()
list.add(buildLink("workflowGroups", getMethodOn()
.getWorkflowGroupForRole(resourceUuid, null, null,
entry.getKey())));
entry.getKey())).withName(entry.getKey()));
}
}

View File

@@ -8,11 +8,13 @@
package org.dspace.app.rest.model.hateoas;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
@@ -49,6 +51,15 @@ public abstract class HALResource<T> extends EntityModel<T> {
public EntityModel<T> add(Link link) {
if (!hasLink(link.getRel())) {
return super.add(link);
} else {
String name = link.getName();
if (StringUtils.isNotBlank(name)) {
List<Link> list = this.getLinks(link.getRel());
// If a link of this name doesn't already exist in the list, add it
if (!list.stream().anyMatch((l -> StringUtils.equalsIgnoreCase(l.getName(), name)))) {
super.add(link);
}
}
}
return this;
}