1 package de.dlr.shepard.neo4Core.dao; 2 3 import de.dlr.shepard.neo4Core.entities.StructuredDataContainer; 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 StructuredDataContainerDAO extends GenericDAO<StructuredDataContainer> { 15 16 public List<StructuredDataContainer> findAllStructuredDataContainers(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", "StructuredDataContainer", 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<StructuredDataContainer>(); 37 for (var container : findByQuery(query, paramsMap)) { 38 if (matchName(container, params.getName())) { 39 result.add(container); 40 } 41 } 42 43 return result; 44 } 45 46 private boolean matchName(StructuredDataContainer container, String name) { 47 return name == null || container.getName().equalsIgnoreCase(name); 48 } 49 50 @Override 51 public Class<StructuredDataContainer> getEntityType() { 52 return StructuredDataContainer.class; 53 } 54 }