@@ -231,15 +231,25 @@ public Map<Long, String> retrieveAuthorNamesForSandBoxes(Set<Long> sandBoxIds) {
231
231
232
232
@ Override
233
233
public List <SandBox > retrieveSandBoxesForAuthor (Long authorId ) {
234
+ return retrieveSandBoxesForAuthor (authorId , null );
235
+ }
236
+
237
+ @ Override
238
+ public List <SandBox > retrieveSandBoxesForAuthor (Long authorId , SandBoxType sandBoxType ) {
234
239
CriteriaBuilder builder = sandBoxEntityManager .getCriteriaBuilder ();
235
240
CriteriaQuery <SandBox > criteria = builder .createQuery (SandBox .class );
236
241
Root <SandBoxManagementImpl > sandbox = criteria .from (SandBoxManagementImpl .class );
237
242
criteria .select (sandbox .get ("sandBox" ).as (SandBox .class ));
238
- criteria .where (
239
- builder .and (builder .equal (sandbox .get ("sandBox" ).get ("author" ), authorId ),
240
- builder .or (builder .isNull (sandbox .get ("sandBox" ).get ("archiveStatus" ).get ("archived" ).as (String .class )),
241
- builder .notEqual (sandbox .get ("sandBox" ).get ("archiveStatus" ).get ("archived" ).as (Character .class ), 'Y' )))
243
+ List <Predicate > restrictions = new ArrayList <Predicate >();
244
+ restrictions .add (builder .equal (sandbox .get ("sandBox" ).get ("author" ), authorId ));
245
+ if (sandBoxType != null ) {
246
+ restrictions .add (builder .equal (sandbox .get ("sandBox" ).get ("sandboxType" ), sandBoxType .getType ()));
247
+ }
248
+ restrictions .add (
249
+ builder .or (builder .isNull (sandbox .get ("sandBox" ).get ("archiveStatus" ).get ("archived" ).as (String .class )),
250
+ builder .notEqual (sandbox .get ("sandBox" ).get ("archiveStatus" ).get ("archived" ).as (Character .class ), 'Y' ))
242
251
);
252
+ criteria .where (restrictions .toArray (new Predicate [restrictions .size ()]));
243
253
TypedQuery <SandBox > query = sandBoxEntityManager .createQuery (criteria );
244
254
return query .getResultList ();
245
255
}
0 commit comments