29
29
@ EqualsAndHashCode (callSuper = true )
30
30
public class Artifact extends PanacheMongoEntityBase {
31
31
32
- private static final String ENGAGEMENT_UUID = "engagementUuid" ;
33
32
private static final String MODIFIED = "modified" ;
34
- private static final String UUID = "uuid" ;
35
33
36
34
@ BsonId
37
35
@ DiffIgnore
@@ -43,10 +41,9 @@ public class Artifact extends PanacheMongoEntityBase {
43
41
@ DiffIgnore
44
42
private String created ;
45
43
@ DiffIgnore
46
- @ JsonbProperty (value = "last_modified " )
44
+ @ JsonbProperty (value = "updated " )
47
45
private String modified ;
48
46
49
- @ NotBlank
50
47
private String engagementUuid ;
51
48
@ NotBlank
52
49
private String title ;
@@ -56,6 +53,8 @@ public class Artifact extends PanacheMongoEntityBase {
56
53
private String type ;
57
54
@ NotBlank
58
55
private String linkAddress ;
56
+
57
+ private String region ;
59
58
60
59
/**
61
60
* Returns an {@link ArtifactCount} containing the count for the total number of
@@ -75,7 +74,7 @@ public static ArtifactCount countAllArtifacts() {
75
74
* @return
76
75
*/
77
76
public static ArtifactCount countArtifactsByEngagementUuid (String engagementUuid ) {
78
- return ArtifactCount .builder ().count (count (ENGAGEMENT_UUID , engagementUuid )).build ();
77
+ return ArtifactCount .builder ().count (count ("engagementUuid" , engagementUuid )).build ();
79
78
}
80
79
81
80
/**
@@ -88,6 +87,14 @@ public static ArtifactCount countArtifactsByEngagementUuid(String engagementUuid
88
87
public static ArtifactCount countArtifactsByType (String type ) {
89
88
return ArtifactCount .builder ().count (count ("type" , type )).build ();
90
89
}
90
+
91
+ public static ArtifactCount countArtifactsByRegion (List <String > regions ) {
92
+ return ArtifactCount .builder ().count (count ("region in ?1" , regions )).build ();
93
+ }
94
+
95
+ public static ArtifactCount countArtifactsByRegionAndType (String type , List <String > regions ) {
96
+ return ArtifactCount .builder ().count (count ("{ $and: [ {'type':?1}, {'region':{'$in':[?2]}} ] }" , type , regions )).build ();
97
+ }
91
98
92
99
/**
93
100
* Returns {@link List} of {@link Artifact}s sorted descending on modified
@@ -112,6 +119,16 @@ public static List<Artifact> pagedArtifacts(int page, int pageSize) {
112
119
public static List <Artifact > pagedArtifactsByType (String type , int page , int pageSize ) {
113
120
return find ("type" , Sort .descending (MODIFIED ), type ).page (page , pageSize ).list ();
114
121
}
122
+
123
+ public static List <Artifact > pagedArtifactsByRegion (List <String > regions , int page , int pageSize ) {
124
+ return find ("region in ?1" , Sort .descending (MODIFIED ), regions ).page (page , pageSize ).list ();
125
+ }
126
+
127
+ public static List <Artifact > pagedArtifactsByRegionAndType (String type , List <String > regions , int page , int pageSize ) {
128
+ //not sure why the commented query doesn't work but keep seeing this error - no viable alternative at input 'type='
129
+ //return find("type = ?1 and region in ?2", Sort.descending(MODIFIED), type, regions).page(page, pageSize).list();
130
+ return find ("{ $and: [ {'type':?1}, {'region':{'$in':[?2]}} ] }" , Sort .descending (MODIFIED ), type , regions ).page (page , pageSize ).list ();
131
+ }
115
132
116
133
/**
117
134
* Returns a {@link List} of {@link Artifact}s for the given engagement uuid,
@@ -123,7 +140,7 @@ public static List<Artifact> pagedArtifactsByType(String type, int page, int pag
123
140
* @return
124
141
*/
125
142
public static List <Artifact > pagedArtifactsByEngagementUuid (String engagementUuid , int page , int pageSize ) {
126
- return find (ENGAGEMENT_UUID , Sort .descending (MODIFIED ), engagementUuid ).page (page , pageSize ).list ();
143
+ return find ("engagementUuid" , Sort .descending (MODIFIED ), engagementUuid ).page (page , pageSize ).list ();
127
144
}
128
145
129
146
/**
@@ -134,7 +151,7 @@ public static List<Artifact> pagedArtifactsByEngagementUuid(String engagementUui
134
151
* @return
135
152
*/
136
153
public static List <Artifact > findAllByEngagementUuid (String engagementUuid ) {
137
- return list (ENGAGEMENT_UUID , engagementUuid );
154
+ return list ("engagementUuid" , engagementUuid );
138
155
}
139
156
140
157
/**
@@ -145,7 +162,7 @@ public static List<Artifact> findAllByEngagementUuid(String engagementUuid) {
145
162
* @return
146
163
*/
147
164
public static Optional <Artifact > findByUuid (String uuid ) {
148
- return find (UUID , uuid ).singleResultOptional ();
165
+ return find ("uuid" , uuid ).singleResultOptional ();
149
166
}
150
167
151
168
/**
@@ -155,7 +172,7 @@ public static Optional<Artifact> findByUuid(String uuid) {
155
172
* @return
156
173
*/
157
174
public static long deleteByUuid (String uuid ) {
158
- return Artifact .delete (UUID , uuid );
175
+ return Artifact .delete ("uuid" , uuid );
159
176
}
160
177
161
178
/**
0 commit comments