[Task 72222] fixed a bug with the links after the implementation of the array dynamic workflowgroup links

This commit is contained in:
Raf Ponsaerts
2020-07-29 13:00:16 +02:00
parent 239bc5271d
commit 338764b046

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;
@@ -44,4 +46,26 @@ public abstract class HALResource<T> extends EntityModel<T> {
public void setPageHeader(EmbeddedPageHeader page) {
this.pageHeader = page;
}
@Override
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());
boolean doesNameExist = false;
for (Link existingLink : list) {
if (StringUtils.equalsIgnoreCase(existingLink.getName(), link.getName())) {
doesNameExist = true;
}
}
if (!doesNameExist) {
super.add(link);
}
}
}
return this;
}
}