View Javadoc
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.StructuredDataContainer;
9   import de.dlr.shepard.util.CypherQueryHelper;
10  import de.dlr.shepard.util.QueryParamHelper;
11  
12  public class StructuredDataContainerDAO extends GenericDAO<StructuredDataContainer> {
13  
14  	public List<StructuredDataContainer> findAllStructuredDataContainers(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", "StructuredDataContainer", 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<StructuredDataContainer>();
33  		for (var container : findByQuery(query, paramsMap)) {
34  			if (matchName(container, params.getName())) {
35  				result.add(container);
36  			}
37  		}
38  
39  		return result;
40  	}
41  
42  	private boolean matchName(StructuredDataContainer container, String name) {
43  		return name == null || container.getName().equalsIgnoreCase(name);
44  	}
45  
46  	@Override
47  	public Class<StructuredDataContainer> getEntityType() {
48  		return StructuredDataContainer.class;
49  	}
50  
51  }