1
2
3
4
5
6 package org.tailormap.api.persistence;
7
8 import com.fasterxml.jackson.annotation.JsonProperty;
9 import jakarta.persistence.Column;
10 import jakarta.persistence.Entity;
11 import jakarta.persistence.EnumType;
12 import jakarta.persistence.Enumerated;
13 import jakarta.persistence.GeneratedValue;
14 import jakarta.persistence.GenerationType;
15 import jakarta.persistence.Id;
16 import jakarta.persistence.Table;
17 import jakarta.validation.Valid;
18 import jakarta.validation.constraints.NotNull;
19 import java.io.Serializable;
20 import java.time.OffsetDateTime;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.hibernate.annotations.Type;
24 import org.springframework.format.annotation.DateTimeFormat;
25
26
27 @Entity
28 @Table(name = "search_index")
29 public class SearchIndex implements Serializable {
30 @Id
31 @GeneratedValue(strategy = GenerationType.IDENTITY)
32 private Long id;
33
34 @NotNull private String name;
35
36 private Long featureTypeId;
37
38
39 @JsonProperty("searchFieldsUsed")
40 @Type(value = io.hypersistence.utils.hibernate.type.json.JsonBinaryType.class)
41 @Column(columnDefinition = "jsonb")
42 @Valid
43 private List<String> searchFieldsUsed = new ArrayList<>();
44
45
46 @JsonProperty("searchDisplayFieldsUsed")
47 @Type(value = io.hypersistence.utils.hibernate.type.json.JsonBinaryType.class)
48 @Column(columnDefinition = "jsonb")
49 @Valid
50 private List<String> searchDisplayFieldsUsed = new ArrayList<>();
51
52 @Column(columnDefinition = "text")
53 private String comment;
54
55
56 @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
57 @Valid
58 @JsonProperty("lastIndexed")
59 private OffsetDateTime lastIndexed;
60
61 public enum Status {
62 INITIAL("initial"),
63 INDEXING("indexing"),
64 INDEXED("indexed"),
65 ERROR("error");
66 private final String value;
67
68 Status(String value) {
69 this.value = value;
70 }
71
72 public String getValue() {
73 return value;
74 }
75
76 @Override
77 public String toString() {
78 return String.valueOf(value);
79 }
80
81 public static SearchIndex.Status fromValue(String value) {
82 for (SearchIndex.Status status : SearchIndex.Status.values()) {
83 if (status.value.equals(value)) {
84 return status;
85 }
86 }
87 throw new IllegalArgumentException("Unexpected value '%s'".formatted(value));
88 }
89 }
90
91 @Enumerated(EnumType.STRING)
92 @NotNull
93 @Column(columnDefinition = "varchar(8) default 'INITIAL'")
94 private SearchIndex.Status status = SearchIndex.Status.INITIAL;
95
96 public Long getId() {
97 return id;
98 }
99
100 public SearchIndex setId(Long id) {
101 this.id = id;
102 return this;
103 }
104
105 public String getName() {
106 return name;
107 }
108
109 public SearchIndex setName(String name) {
110 this.name = name;
111 return this;
112 }
113
114 public Long getFeatureTypeId() {
115 return featureTypeId;
116 }
117
118 public SearchIndex setFeatureTypeId(Long featureTypeId) {
119 this.featureTypeId = featureTypeId;
120 return this;
121 }
122
123 public List<String> getSearchFieldsUsed() {
124 return searchFieldsUsed;
125 }
126
127 public SearchIndex setSearchFieldsUsed(List<String> searchFieldsUsed) {
128 this.searchFieldsUsed = searchFieldsUsed;
129 return this;
130 }
131
132 public List<String> getSearchDisplayFieldsUsed() {
133 return searchDisplayFieldsUsed;
134 }
135
136 public SearchIndex setSearchDisplayFieldsUsed(List<String> searchDisplayFieldsUsed) {
137 this.searchDisplayFieldsUsed = searchDisplayFieldsUsed;
138 return this;
139 }
140
141 public String getComment() {
142 return comment;
143 }
144
145 public SearchIndex setComment(String comment) {
146 this.comment = comment;
147 return this;
148 }
149
150 public OffsetDateTime getLastIndexed() {
151 return lastIndexed;
152 }
153
154 public SearchIndex setLastIndexed(OffsetDateTime lastIndexed) {
155 this.lastIndexed = lastIndexed;
156 return this;
157 }
158
159 public Status getStatus() {
160 return status;
161 }
162
163 public SearchIndex setStatus(Status status) {
164 this.status = status;
165 return this;
166 }
167 }