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