while (tuples.hasNext()) {
Node parent = tuples.next().get("parent");
if (parent != null) {
if (parent.isURIReference()) {
try {
PID parentPID = new PID(parent.stringValue());
logger.debug("Found parent " + parentPID.toString());
parentPIDs.add(parentPID.toString());
} catch (MalformedPIDException e) {
logger.warn("parent/child relationship target is not a Fedora object" + parent.stringValue());
}
} else {
logger.warn("parent/child query result is not a Fedora object " + parent.stringValue());
}
} else {
logger.error("parent/child tuple result did not contain parent variable");
}
}
logger.debug("Query result count: " + tuples.count());
} else {
logger.debug("Query returned 0 results");
}
} catch (TrippiException e) {
logger.error("Error running TQL query " + e.getMessage(), e);
return parentPIDs;
}
} else if (verifyTripleLanguage(SPO)) {
// gets all relationships for pid, then filters results
// rather than executing separate queries for each relationship
// parent relationships
Map<String, Set<String>> pRels = null;
if (parentRelationships.size() == 1) {
pRels= getRelationships(pidUri, parentRelationships.get(0));
} else {
pRels = getRelationships(pidUri);
}
for (String rel : pRels.keySet()) {
if (parentRelationships.contains(rel)) {
for (String parent : pRels.get(rel)) {
PID parentPid;
try {
parentPid = new PID(parent);
parentPIDs.add(parentPid.toString());
} catch (MalformedPIDException e) {
logger.warn("Parent of " + pid + " through relationship " + rel + " is not a Fedora resource");
}
}
}
}
// child relationships
if (childRelationships != null && !childRelationships.isEmpty()) {
Map<String, Set<String>> cRels = null;
if (childRelationships.size() == 1) {
cRels= getReverseRelationships(pidUri, childRelationships.get(0));
} else {
cRels = getReverseRelationships(pidUri);
}
for (String rel : cRels.keySet()) {
if (childRelationships.contains(rel)) {
for (String parent : cRels.get(rel)) {
PID parentPid;
try {
parentPid = new PID(parent);
parentPIDs.add(parentPid.toString());
} catch (MalformedPIDException e) {
logger.warn("Parent of " + pid + " through relationship " + rel + " is not a Fedora resource");
}
}
}