View Javadoc
1   package de.dlr.shepard.neo4Core.dao;
2   
3   import java.util.Collections;
4   
5   import de.dlr.shepard.neo4Core.entities.Permissions;
6   import de.dlr.shepard.util.CypherQueryHelper;
7   
8   public class PermissionsDAO extends GenericDAO<Permissions> {
9   
10  	public Permissions findByEntity(long entityId) {
11  		String query = String.format("MATCH (e)-[:has_permissions]->(p:Permissions) WHERE ID(e) = %d ", entityId)
12  				+ CypherQueryHelper.getReturnPart("p");
13  		var permissions = findByQuery(query, Collections.emptyMap());
14  		if (permissions.iterator().hasNext())
15  			return permissions.iterator().next();
16  		return null;
17  	}
18  
19  	public Permissions createWithEntity(Permissions permissions, long entityId) {
20  		var created = createOrUpdate(permissions);
21  		String query = String.format(
22  				"MATCH (e) WHERE ID(e) = %d MATCH (p:Permissions) WHERE ID(p) = %d CREATE path = (e)-[r:has_permissions]->(p)",
23  				entityId, created.getId());
24  		runQuery(query, Collections.emptyMap());
25  		return find(created.getId());
26  	}
27  
28  	@Override
29  	public Class<Permissions> getEntityType() {
30  		return Permissions.class;
31  	}
32  
33  }