View Javadoc
1   package de.dlr.shepard.neo4Core.dao;
2   
3   import de.dlr.shepard.neo4Core.entities.UserGroup;
4   import de.dlr.shepard.util.CypherQueryHelper;
5   import de.dlr.shepard.util.QueryParamHelper;
6   import jakarta.enterprise.context.RequestScoped;
7   import java.util.ArrayList;
8   import java.util.HashMap;
9   import java.util.List;
10  import java.util.Map;
11  
12  @RequestScoped
13  public class UserGroupDAO extends GenericDAO<UserGroup> {
14  
15    @Override
16    public Class<UserGroup> getEntityType() {
17      return UserGroup.class;
18    }
19  
20    public List<UserGroup> findAllUserGroups(QueryParamHelper params, String username) {
21      Map<String, Object> paramsMap = new HashMap<>();
22      if (params.hasPagination()) {
23        paramsMap.put("offset", params.getPagination().getOffset());
24        paramsMap.put("size", params.getPagination().getSize());
25      }
26      var query = String.format(
27        "MATCH %s WHERE %s WITH ug",
28        CypherQueryHelper.getObjectPart("ug", "UserGroup", false),
29        CypherQueryHelper.getReadableByQuery("ug", username)
30      );
31      if (params.hasOrderByAttribute()) {
32        query += " " + CypherQueryHelper.getOrderByPart("ug", params.getOrderByAttribute(), params.getOrderDesc());
33      }
34      if (params.hasPagination()) {
35        query += " " + CypherQueryHelper.getPaginationPart();
36      }
37      query += " " + CypherQueryHelper.getReturnPart("ug");
38      var result = new ArrayList<UserGroup>();
39      for (var userGroup : findByQuery(query, paramsMap)) {
40        result.add(userGroup);
41      }
42      return result;
43    }
44  }