View Javadoc
1   package de.dlr.shepard.data.file.daos;
2   
3   import de.dlr.shepard.common.neo4j.daos.GenericDAO;
4   import de.dlr.shepard.common.util.CypherQueryHelper;
5   import de.dlr.shepard.data.file.entities.ShepardFile;
6   import jakarta.enterprise.context.RequestScoped;
7   import java.util.Map;
8   
9   @RequestScoped
10  public class ShepardFileDAO extends GenericDAO<ShepardFile> {
11  
12    /**
13     * Find a shepardFile by oid
14     *
15     * @param containerId FileContainer ID
16     * @param oid         Identifies the shepardFile
17     *
18     * @return the found shepardFile or null
19     */
20    public ShepardFile find(long containerId, String oid) {
21      var query = String.format(
22        "MATCH (c:FileContainer)-[:file_in_container]->(f:ShepardFile {oid: $oid}) WHERE ID(c)=%d %s",
23        containerId,
24        CypherQueryHelper.getReturnPart("f")
25      );
26      var results = findByQuery(query, Map.of("oid", oid));
27      return results.iterator().hasNext() ? results.iterator().next() : null;
28    }
29  
30    @Override
31    public Class<ShepardFile> getEntityType() {
32      return ShepardFile.class;
33    }
34  }