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