Skip to content

Instantly share code, notes, and snippets.

@okram
Created November 4, 2011 14:30
Show Gist options
  • Save okram/1339442 to your computer and use it in GitHub Desktop.
Save okram/1339442 to your computer and use it in GitHub Desktop.
package com.cisco.hmp.graph.sharesav
import com.tinkerpop.blueprints.pgm.IndexableGraph
import com.tinkerpop.blueprints.pgm.Vertex
import com.tinkerpop.gremlin.Gremlin
import com.tinkerpop.gremlin.GremlinTokens.T
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
class ShareSavTraversals {
/*
HMP services will receive a request with User name and SAV name as input.
User is associated at Level 3 in the Share Hierarchy.
If the user is attached at level 3 then get the all the share node Ids that user has access.
Since the SAV's attached at level 6 in the Share Hierarchy, check for the given SAV Name input name at level 6 in the share node attributes.
If SAV Name matches with SAV Name Attribute at the Level 6 Node then return the corresponding SAV ID to the called environment(Response).
*/
static {
Gremlin.load();
}
public static Iterator<Long> evaluateQuery(final IndexableGraph g, final String userName, final String savName, Long startDate, Long endDate) {
if (endDate == -1l) {
endDate = Long.MIN_VALUE;
}
if (startDate == -1l) {
startDate = Long.MAX_VALUE;
}
final Vertex root = g.idx(T.v)[[share_id: 2l]] >> 1;
final Vertex user = g.idx(T.v)[[user_name: userName]] >> 1;
return root.out('contains').loop(1) {it.loops < 3}.out('hasUser').retain([user]).back(2).
out('contains').loop(1) {it.loops < 5}.out('hasSav').
out('hasProperty').filter {it.getProperty('_type') == 'sav_name'}.filter {it.getProperty('value') == savName}.
filter {it.getProperty('_startDate') <= startDate && it.getProperty('_endDate') >= endDate}.back(4).sav_id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment