1 package de.dlr.shepard.neo4Core.dao; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 8 import de.dlr.shepard.neo4Core.entities.FileContainer; 9 import de.dlr.shepard.util.CypherQueryHelper; 10 import de.dlr.shepard.util.QueryParamHelper; 11 12 public class FileContainerDAO extends GenericDAO<FileContainer> { 13 14 public List<FileContainer> findAllFileContainers(QueryParamHelper params, String username) { 15 String query; 16 Map<String, Object> paramsMap = new HashMap<>(); 17 paramsMap.put("name", params.getName()); 18 if (params.hasPagination()) { 19 paramsMap.put("offset", params.getPagination().getOffset()); 20 paramsMap.put("size", params.getPagination().getSize()); 21 } 22 query = String.format("MATCH %s WHERE %s WITH c", 23 CypherQueryHelper.getObjectPart("c", "FileContainer", params.hasName()), 24 CypherQueryHelper.getReadableByQuery("c", username)); 25 if (params.hasOrderByAttribute()) { 26 query += " " + CypherQueryHelper.getOrderByPart("c", params.getOrderByAttribute(), params.getOrderDesc()); 27 } 28 if (params.hasPagination()) { 29 query += " " + CypherQueryHelper.getPaginationPart(); 30 } 31 query += " " + CypherQueryHelper.getReturnPart("c", true); 32 var result = new ArrayList<FileContainer>(); 33 for (var container : findByQuery(query, paramsMap)) { 34 if (matchName(container, params.getName())) { 35 result.add(container); 36 } 37 } 38 return result; 39 } 40 41 private boolean matchName(FileContainer container, String name) { 42 return name == null || container.getName().equalsIgnoreCase(name); 43 } 44 45 @Override 46 public Class<FileContainer> getEntityType() { 47 return FileContainer.class; 48 } 49 50 }