1 package de.dlr.shepard.neo4Core.io;
2
3 import java.util.Date;
4 import java.util.List;
5
6 import com.fasterxml.jackson.annotation.JsonFormat;
7
8 import de.dlr.shepard.neo4Core.entities.BasicEntity;
9 import de.dlr.shepard.util.HasId;
10 import io.swagger.v3.oas.annotations.media.Schema;
11 import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
12 import jakarta.validation.constraints.NotBlank;
13 import lombok.Data;
14 import lombok.NoArgsConstructor;
15
16 @Data
17 @NoArgsConstructor
18 @Schema(name = "BasicEntity")
19 public class BasicEntityIO implements HasId {
20
21 @Schema(accessMode = AccessMode.READ_ONLY)
22 private Long id;
23
24 @JsonFormat(shape = JsonFormat.Shape.STRING)
25 @Schema(accessMode = AccessMode.READ_ONLY)
26 private Date createdAt;
27
28 @Schema(accessMode = AccessMode.READ_ONLY)
29 private String createdBy;
30
31 @JsonFormat(shape = JsonFormat.Shape.STRING)
32 @Schema(accessMode = AccessMode.READ_ONLY, nullable = true)
33 private Date updatedAt;
34
35 @Schema(accessMode = AccessMode.READ_ONLY, nullable = true)
36 private String updatedBy;
37
38 @NotBlank
39 @Schema(nullable = true)
40 private String name;
41
42 public BasicEntityIO(BasicEntity entity) {
43 this.id = entity.getId();
44 this.createdAt = entity.getCreatedAt();
45 this.createdBy = entity.getCreatedBy() != null ? entity.getCreatedBy().getUsername() : null;
46 this.updatedAt = entity.getUpdatedAt();
47 this.updatedBy = entity.getUpdatedBy() != null ? entity.getUpdatedBy().getUsername() : null;
48 this.name = entity.getName();
49 }
50
51 protected static long[] extractIds(List<? extends BasicEntity> entities) {
52 var result = entities.stream().map(BasicEntity::getId).mapToLong(Long::longValue).toArray();
53 return result;
54 }
55
56 @Override
57 public String getUniqueId() {
58 return id.toString();
59 }
60
61 }