1 package de.dlr.shepard.neo4Core.dao; 2 3 import de.dlr.shepard.neo4Core.entities.TimeseriesContainer; 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 TimeseriesContainerDAO extends GenericDAO<TimeseriesContainer> { 15 16 public List<TimeseriesContainer> findAllTimeseriesContainers(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 25 query = String.format( 26 "MATCH %s WHERE %s WITH c", 27 CypherQueryHelper.getObjectPart("c", "TimeseriesContainer", params.hasName()), 28 CypherQueryHelper.getReadableByQuery("c", username) 29 ); 30 if (params.hasOrderByAttribute()) { 31 query += " " + CypherQueryHelper.getOrderByPart("c", params.getOrderByAttribute(), params.getOrderDesc()); 32 } 33 if (params.hasPagination()) { 34 query += " " + CypherQueryHelper.getPaginationPart(); 35 } 36 query += " " + CypherQueryHelper.getReturnPart("c", Neighborhood.ESSENTIAL); 37 var result = new ArrayList<TimeseriesContainer>(); 38 for (var container : findByQuery(query, paramsMap)) { 39 if (matchName(container, params.getName())) { 40 result.add(container); 41 } 42 } 43 return result; 44 } 45 46 private boolean matchName(TimeseriesContainer container, String name) { 47 return name == null || container.getName().equalsIgnoreCase(name); 48 } 49 50 @Override 51 public Class<TimeseriesContainer> getEntityType() { 52 return TimeseriesContainer.class; 53 } 54 }