View Javadoc
1   package de.dlr.shepard.context.collection.io;
2   
3   import de.dlr.shepard.common.neo4j.io.AbstractDataObjectIO;
4   import de.dlr.shepard.common.util.HasId;
5   import de.dlr.shepard.context.collection.entities.Collection;
6   import java.util.Objects;
7   import lombok.Data;
8   import lombok.NoArgsConstructor;
9   import org.eclipse.microprofile.openapi.annotations.media.Schema;
10  
11  @Data
12  @NoArgsConstructor
13  @Schema(name = "Collection")
14  public class CollectionIO extends AbstractDataObjectIO {
15  
16    @Schema(readOnly = true, required = true)
17    private long[] dataObjectIds;
18  
19    @Schema(readOnly = true, required = true)
20    private long[] incomingIds;
21  
22    /**
23     * Id of a default file container.
24     * This value can be nullable.
25     * The default value is null.
26     */
27    @Schema(nullable = true)
28    private Long defaultFileContainerId = null;
29  
30    public CollectionIO(Collection collection) {
31      super(collection);
32      this.dataObjectIds = extractShepardIds(collection.getDataObjects());
33      this.incomingIds = extractShepardIds(collection.getIncoming());
34  
35      if (collection.getFileContainer() == null) {
36        this.defaultFileContainerId = null;
37      } else {
38        this.defaultFileContainerId = collection.getFileContainer().getId();
39      }
40    }
41  
42    @Override
43    public boolean equals(Object o) {
44      if (this == o) return true;
45      if (!super.equals(o)) return false;
46      if (!(o instanceof CollectionIO)) return false;
47      CollectionIO other = (CollectionIO) o;
48      return (
49        HasId.areEqualSets(dataObjectIds, other.dataObjectIds) &&
50        HasId.areEqualSets(incomingIds, other.incomingIds) &&
51        Objects.equals(defaultFileContainerId, other.defaultFileContainerId)
52      );
53    }
54  
55    @Override
56    public int hashCode() {
57      final int prime = 31;
58      int result = super.hashCode();
59      result = prime * result + HasId.hashcodeHelper(dataObjectIds);
60      result = prime * result + HasId.hashcodeHelper(incomingIds);
61      result = prime * result + Objects.hashCode(defaultFileContainerId);
62      return result;
63    }
64  }