Skip to content

Commit

Permalink
Merge pull request #240 from BBMRI-ERIC/fix/resource_link
Browse files Browse the repository at this point in the history
fix: unintentional modification of representative resources
  • Loading branch information
RadovanTomik committed Mar 20, 2024
2 parents 255ce30 + d70f621 commit 1ab113d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -93,6 +94,13 @@ public void addResource(Resource resource) {
resource.getRepresentatives().add(this);
}

public Set<Resource> getResources() {
if (Objects.isNull(this.resources)) {
return Set.of();
}
return Collections.unmodifiableSet(this.resources);
}

public void removeResource(Resource resource) {
this.resources.remove(resource);
resource.getRepresentatives().remove(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {

private static Set<Resource> getResourcesInNegotiationRepresentedBy(
Negotiation negotiation, Person representative) {
Set<Resource> overlappingResources = representative.getResources();
Set<Resource> overlappingResources = new HashSet<>(representative.getResources());
overlappingResources.retainAll(negotiation.getResources());
return overlappingResources;
}
Expand Down

0 comments on commit 1ab113d

Please sign in to comment.