Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions reverse_engineering/gremlinHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getGraphFeatures,
getGraphVariables,
wrapInGraphSONMapperScript,
wrapInGraphSONMapperV2Script,
getDataQuery,
getTemplateData,
getEdgeLabelsScript,
Expand Down Expand Up @@ -252,6 +253,7 @@ const getIndexes = async () => {
client.submit(getEdgeIndexes(state.traversalSource)),
client.submit(getRelationIndexes(state.traversalSource)),
]);

const vertexIndexes = data[0].toArray();
const edgeIndexes = data[1].toArray();
const vertexCentricIndexesData = data[2].toArray();
Expand Down Expand Up @@ -560,15 +562,22 @@ const addMetaProperties = (schema, metaProperties) => {
});
};

const submitGraphSONDataScript = query => client.submit(wrapInGraphSONMapperScript(query));
const submitGraphSONDataScript = async query => {
try {
return await client.submit(wrapInGraphSONMapperScript(query));
} catch (_) {
//failed to execute GraphSONXModuleV3 mapper for query, trying to use legacy V2

const getMetaPropertiesData = (element, label, limit) => {
return await client.submit(wrapInGraphSONMapperV2Script(query));
}
};

const getMetaPropertiesData = async (element, label, limit) => {
if (element !== 'V') {
return Promise.resolve({
first: () => ({}),
});
}

return submitGraphSONDataScript(getMetaPropertiesDataQuery(state.traversalSource, label, limit));
};

Expand Down
55 changes: 34 additions & 21 deletions reverse_engineering/helpers/gremlinScriptsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const getEdgeDataFromSchema = (traversalSource, edgeLabel) =>
openManagement().
getEdgeLabel('${edgeLabel}').
mappedConnections().
inject([]) {accumulator, connection ->
def currentConnection = [
"relationship": '${edgeLabel}',
"start": connection.getOutgoingVertexLabel().name(),
"end": connection.getIncomingVertexLabel().name()
inject([]) {accumulator, connection ->
def currentConnection = [
"relationship": '${edgeLabel}',
"start": connection.getOutgoingVertexLabel().name(),
"end": connection.getIncomingVertexLabel().name()
]
def temp = accumulator.findAll {it -> it.start == currentConnection.start && it.end == currentConnection.end }.size
temp == 0 ? accumulator.add(currentConnection) : accumulator
Expand Down Expand Up @@ -54,11 +54,11 @@ const getVertexIndexes = traversalSource =>
getGraph().
openManagement().
getGraphIndexes(Vertex.class).
collect{element ->
[element.name(),
element,
element.getFieldKeys().collect{field ->
[field.name(),element.getParametersFor(field).collect{i -> [i.key(), i.value().toString()]}]
collect{element ->
[element.name(),
element,
element.getFieldKeys().collect{field ->
[field.name(),element.getParametersFor(field).collect{i -> [i.key(), i.value().toString()]}]
}
]
};`;
Expand All @@ -68,11 +68,11 @@ const getEdgeIndexes = traversalSource =>
getGraph().
openManagement().
getGraphIndexes(Edge.class).
collect{element ->
[element.name(),
element,
element.getFieldKeys().collect{field ->
[field.name(),element.getParametersFor(field).collect{i -> [i.key(), i.value().toString()]}]
collect{element ->
[element.name(),
element,
element.getFieldKeys().collect{field ->
[field.name(),element.getParametersFor(field).collect{i -> [i.key(), i.value().toString()]}]
}
]
};`;
Expand All @@ -89,12 +89,12 @@ const getRelationIndexes = traversalSource =>
relationIndexes.
findAll{item -> item.size() > 0}.
inject([]){ temp, val -> temp.plus(val)}.
collect{ri ->
[ri.name(),
ri.getType().name(),
ri.getDirection(),
collect{ri ->
[ri.name(),
ri.getType().name(),
ri.getDirection(),
ri.getSortKey()[0].name(),
ri.getSortOrder(),
ri.getSortOrder(),
ri.getIndexStatus().name(),
ri.getSortKey().collect{key -> key.name()}
]
Expand All @@ -103,17 +103,29 @@ const getRelationIndexes = traversalSource =>
const getGraphFeatures = traversalSource => `${traversalSource}.getGraph().features()`;
const getGraphVariables = traversalSource => `${traversalSource}.getGraph().variables().asMap()`;

//https://tinkerpop.apache.org/javadocs/current/full/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONXModuleV3.html#build()
const wrapInGraphSONMapperScript = query =>
`GraphSONMapper.
build().
typeInfo(org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo.PARTIAL_TYPES).
addCustomModule(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0.build().create(false)).
addCustomModule(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV3.build()).
version(GraphSONVersion.V3_0).
addRegistry(JanusGraphIoRegistry.instance()).
create().
createMapper().
writeValueAsString(${query})`;

const wrapInGraphSONMapperV2Script = query =>
`GraphSONMapper.
build().
typeInfo(org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo.PARTIAL_TYPES).
addCustomModule(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0.build().create(false)).
version(GraphSONVersion.V3_0).
addRegistry(JanusGraphIoRegistry.instance()).
create().
createMapper().
writeValueAsString(${query})`;

const getDataQuery = (traversalSource, element, label, limit) =>
`${traversalSource}.${element}().hasLabel('${label}').limit(${limit}).valueMap().toList()`;

Expand Down Expand Up @@ -200,6 +212,7 @@ module.exports = {
getGraphFeatures,
getGraphVariables,
wrapInGraphSONMapperScript,
wrapInGraphSONMapperV2Script,
getDataQuery,
getTemplateData,
getEdgeLabelsScript,
Expand Down