View Javadoc
1   package de.dlr.shepard.context.references.file.io;
2   
3   import de.dlr.shepard.common.util.HasId;
4   import de.dlr.shepard.context.references.basicreference.io.BasicReferenceIO;
5   import de.dlr.shepard.context.references.file.entities.FileReference;
6   import de.dlr.shepard.data.file.entities.ShepardFile;
7   import jakarta.validation.constraints.NotEmpty;
8   import jakarta.validation.constraints.NotNull;
9   import lombok.Data;
10  import lombok.NoArgsConstructor;
11  import org.eclipse.microprofile.openapi.annotations.media.Schema;
12  
13  @Data
14  @NoArgsConstructor
15  @Schema(name = "FileReference")
16  public class FileReferenceIO extends BasicReferenceIO {
17  
18    @NotEmpty
19    @Schema(required = true)
20    private String[] fileOids;
21  
22    @NotNull
23    @Schema(required = true)
24    private long fileContainerId;
25  
26    public FileReferenceIO(FileReference ref) {
27      super(ref);
28      this.fileOids = ref.getFiles().stream().map(ShepardFile::getOid).toArray(String[]::new);
29      this.fileContainerId = ref.getFileContainer() != null ? ref.getFileContainer().getId() : -1;
30    }
31  
32    @Override
33    public boolean equals(Object o) {
34      if (this == o) return true;
35      if (o == null) return false;
36      if (!super.equals(o)) return false;
37      if (this.getClass() != o.getClass()) return false;
38      FileReferenceIO other = (FileReferenceIO) o;
39      return (fileContainerId == other.fileContainerId && HasId.areEqualSets(fileOids, other.fileOids));
40    }
41  
42    @Override
43    public int hashCode() {
44      final int prime = 31;
45      int result = super.hashCode();
46      result = prime * result + ((Long) fileContainerId).hashCode();
47      result = prime * result + HasId.hashcodeHelper(fileOids);
48      return result;
49    }
50  }