Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
[NLA-262] Improves getting subresource
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Buitendijk committed Jun 8, 2016
1 parent e7e29ea commit eadc6f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.jooq.lambda.Unchecked;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -234,17 +235,16 @@ public Optional<AlexandriaAnnotationBody> findAnnotationBodyWithTypeAndValue(Str

@Override
public Optional<AlexandriaResource> findSubresourceWithSubAndParentId(String sub, UUID parentId) {
// TODO: find the gremlin way to do this in one:
// in cypher: match (r:Resource{uuid:parentId})<-[:PART_OF]-(s:Resource{cargo:sub}) return s.uuid
return storage.runInTransaction(//
() -> storage.find(ResourceVF.class)//
.has("cargo", sub)//
() -> storage.getResourceVertexTraversal()//
.has(Storage.IDENTIFIER_PROPERTY, parentId.toString())//
.in(ResourceVF.PART_OF)//
.has(ResourceVF.Properties.CARGO, sub)//
.toList()//
.stream()//
.filter(r -> r.getParentResource() != null//
&& r.getParentResource().getUuid().equals(parentId.toString()))//
.parallelStream()//
.map(this::deframeResource)//
.findFirst());
.findAny()//
);
}

@Override
Expand Down Expand Up @@ -617,6 +617,11 @@ private AlexandriaAnnotation createAnnotation(AlexandriaTextLocator textLocator,
return alexandriaAnnotation;
}

private AlexandriaResource deframeResource(Vertex v) {
ResourceVF rvf = storage.frameVertex(v, ResourceVF.class);
return deframeResource(rvf);
}

private AlexandriaResource deframeResource(ResourceVF rvf) {
TentativeAlexandriaProvenance provenance = deframeProvenance(rvf);
UUID uuid = getUUID(rvf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
Expand All @@ -37,6 +37,7 @@
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo;
Expand Down Expand Up @@ -177,6 +178,10 @@ public GraphTraversal<Vertex, Vertex> getVertexTraversal(Object... vertexIds) {
return graph.traversal().V(vertexIds);
}

public GraphTraversal<Vertex, Vertex> getResourceVertexTraversal(Object... vertexIds) {
return getVertexTraversal(vertexIds).has(T.label, "Resource");
}

// graph methods

public void removeExpiredTentatives(final Long threshold) {
Expand Down Expand Up @@ -253,6 +258,11 @@ public void destroy() {
}
// Log.info("destroy done");
}

public <A extends AlexandriaVF> A frameVertex(Vertex v, Class<A> vfClass) {
return framedGraph.frame(v, vfClass);
}

// - private methods - //

private <A extends AlexandriaVF> FramedGraphTraversal<Object, A> find(final Class<A> vfClass, final UUID uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

@Vertex(Labels.RESOURCE)
public abstract class ResourceVF extends AlexandriaVF {
public static class Properties {
public static final String CARGO = "cargo";
}
public static final String PART_OF = "part_of";

public abstract String getCargo();
Expand Down

0 comments on commit eadc6f0

Please sign in to comment.