1 package de.dlr.shepard.neo4Core.dao;
2
3 import de.dlr.shepard.neo4Core.entities.StructuredDataReference;
4 import de.dlr.shepard.util.Constants;
5 import de.dlr.shepard.util.CypherQueryHelper;
6 import de.dlr.shepard.util.TraversalRules;
7 import jakarta.enterprise.context.RequestScoped;
8 import java.util.Collections;
9 import java.util.List;
10 import java.util.stream.StreamSupport;
11
12 @RequestScoped
13 public class StructuredDataReferenceDAO extends VersionableEntityDAO<StructuredDataReference> {
14
15
16
17
18
19
20
21 public List<StructuredDataReference> findByDataObjectNeo4jId(long dataObjectId) {
22 String query =
23 String.format(
24 "MATCH (d:DataObject)-[hr:has_reference]->%s WHERE ID(d)=%d ",
25 CypherQueryHelper.getObjectPart("r", "StructuredDataReference", false),
26 dataObjectId
27 ) +
28 CypherQueryHelper.getReturnPart("r");
29 var queryResult = findByQuery(query, Collections.emptyMap());
30 List<StructuredDataReference> result = StreamSupport.stream(queryResult.spliterator(), false)
31 .filter(r -> r.getDataObject() != null)
32 .filter(r -> r.getDataObject().getId().equals(dataObjectId))
33 .toList();
34 return result;
35 }
36
37 public List<StructuredDataReference> findReachableReferencesByShepardId(
38 TraversalRules traversalRule,
39 long collectionShepardId,
40 long startShepardId,
41 String userName
42 ) {
43 String query = getSearchForReachableReferencesByShepardIdQuery(
44 traversalRule,
45 collectionShepardId,
46 startShepardId,
47 userName
48 );
49 var queryResult = findByQuery(query, Collections.emptyMap());
50 List<StructuredDataReference> ret = StreamSupport.stream(queryResult.spliterator(), false).toList();
51 return ret;
52 }
53
54 public List<StructuredDataReference> findReachableReferencesByNeo4jId(
55 long collectionId,
56 long startId,
57 String userName
58 ) {
59 String query = getSearchForReachableReferencesQuery(collectionId, startId, userName);
60 var queryResult = findByQuery(query, Collections.emptyMap());
61 List<StructuredDataReference> ret = StreamSupport.stream(queryResult.spliterator(), false).toList();
62 return ret;
63 }
64
65 public List<StructuredDataReference> findReachableReferencesByShepardId(
66 long collectionShepardId,
67 long startShepardId,
68 String userName
69 ) {
70 String query = getSearchForReachableReferencesByShepardIdQuery(collectionShepardId, startShepardId, userName);
71 var queryResult = findByQuery(query, Collections.emptyMap());
72 List<StructuredDataReference> ret = StreamSupport.stream(queryResult.spliterator(), false).toList();
73 return ret;
74 }
75
76 public List<StructuredDataReference> findReachableReferencesByNeo4jId(long collectionId, String userName) {
77 String query = getSearchForReachableReferencesQuery(collectionId, userName);
78 var queryResult = findByQuery(query, Collections.emptyMap());
79 List<StructuredDataReference> ret = StreamSupport.stream(queryResult.spliterator(), false).toList();
80 return ret;
81 }
82
83 public List<StructuredDataReference> findReachableReferencesByShepardId(long collectionShepardId, String userName) {
84 String query = getSearchForReachableReferencesByShepardIdQuery(collectionShepardId, userName);
85 var queryResult = findByQuery(query, Collections.emptyMap());
86 List<StructuredDataReference> ret = StreamSupport.stream(queryResult.spliterator(), false).toList();
87 return ret;
88 }
89
90 public List<StructuredDataReference> findByDataObjectShepardId(long dataObjectShepardId) {
91 String query =
92 String.format(
93 "MATCH (d:DataObject)-[hr:has_reference]->%s WHERE d." + Constants.SHEPARD_ID + "=%d ",
94 CypherQueryHelper.getObjectPart("r", "StructuredDataReference", false),
95 dataObjectShepardId
96 ) +
97 CypherQueryHelper.getReturnPart("r");
98 var queryResult = findByQuery(query, Collections.emptyMap());
99 List<StructuredDataReference> result = StreamSupport.stream(queryResult.spliterator(), false)
100 .filter(r -> r.getDataObject() != null)
101 .filter(r -> r.getDataObject().getShepardId().equals(dataObjectShepardId))
102 .toList();
103 return result;
104 }
105
106 @Override
107 public Class<StructuredDataReference> getEntityType() {
108 return StructuredDataReference.class;
109 }
110 }