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