1 package de.dlr.shepard.neo4Core.dao;
2
3 import de.dlr.shepard.neo4Core.entities.URIReference;
4 import de.dlr.shepard.util.Constants;
5 import de.dlr.shepard.util.CypherQueryHelper;
6 import jakarta.enterprise.context.RequestScoped;
7 import java.util.Collections;
8 import java.util.List;
9 import java.util.stream.StreamSupport;
10
11 @RequestScoped
12 public class URIReferenceDAO extends VersionableEntityDAO<URIReference> {
13
14
15
16
17
18
19
20 public List<URIReference> findByDataObjectNeo4jId(long dataObjectId) {
21 String query =
22 String.format(
23 "MATCH (d:DataObject)-[hr:has_reference]->%s WHERE ID(d)=%d ",
24 CypherQueryHelper.getObjectPart("r", "URIReference", false),
25 dataObjectId
26 ) +
27 CypherQueryHelper.getReturnPart("r");
28
29 var queryResult = findByQuery(query, Collections.emptyMap());
30
31 List<URIReference> result = StreamSupport.stream(queryResult.spliterator(), false)
32 .filter(r -> r.getDataObject() != null)
33 .filter(r -> r.getDataObject().getId().equals(dataObjectId))
34 .toList();
35
36 return result;
37 }
38
39 public List<URIReference> findByDataObjectShepardId(long dataObjectShepardId) {
40 String query =
41 String.format(
42 "MATCH (d:DataObject)-[hr:has_reference]->%s WHERE d." + Constants.SHEPARD_ID + "=%d ",
43 CypherQueryHelper.getObjectPart("r", "URIReference", false),
44 dataObjectShepardId
45 ) +
46 CypherQueryHelper.getReturnPart("r");
47
48 var queryResult = findByQuery(query, Collections.emptyMap());
49
50 List<URIReference> result = StreamSupport.stream(queryResult.spliterator(), false)
51 .filter(r -> r.getDataObject() != null)
52 .filter(r -> r.getDataObject().getShepardId().equals(dataObjectShepardId))
53 .toList();
54
55 return result;
56 }
57
58 @Override
59 public Class<URIReference> getEntityType() {
60 return URIReference.class;
61 }
62 }