use of org.vertexium.VertexiumException in project vertexium by visallo.
the class SortContainersComparator method compare.
private int compare(QueryBase.SortContainer sortContainer, T vertexiumObject1, T vertexiumObject2) {
if (vertexiumObject1 instanceof VertexiumObject && vertexiumObject2 instanceof VertexiumObject) {
VertexiumObject elem1 = (VertexiumObject) vertexiumObject1;
VertexiumObject elem2 = (VertexiumObject) vertexiumObject2;
List<Object> elem1PropertyValues = toList(elem1.getPropertyValues(sortContainer.propertyName));
List<Object> elem2PropertyValues = toList(elem2.getPropertyValues(sortContainer.propertyName));
if (elem1PropertyValues.size() > 0 && elem2PropertyValues.size() == 0) {
return -1;
} else if (elem2PropertyValues.size() > 0 && elem1PropertyValues.size() == 0) {
return 1;
} else {
for (Object elem1PropertyValue : elem1PropertyValues) {
for (Object elem2PropertyValue : elem2PropertyValues) {
int result = comparePropertyValues(elem1PropertyValue, elem2PropertyValue);
if (result != 0) {
return sortContainer.direction == SortDirection.ASCENDING ? result : -result;
}
}
}
}
return 0;
} else {
throw new VertexiumException("unexpected searchable item combination: " + vertexiumObject1.getClass().getName() + ", " + vertexiumObject2.getClass().getName());
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class CypherCstToAstVisitor method toBinaryExpressions.
private <T extends ParseTree> CypherBinaryExpression toBinaryExpressions(List<ParseTree> children, Function<T, CypherAstBase> itemTransform) {
CypherAstBase left = null;
CypherBinaryExpression.Op op = null;
for (int i = 0; i < children.size(); i++) {
ParseTree child = children.get(i);
if (child instanceof TerminalNode) {
CypherBinaryExpression.Op newOp = CypherBinaryExpression.Op.parseOrNull(child.getText());
if (newOp != null) {
if (op == null) {
op = newOp;
} else {
throw new VertexiumException("unexpected op, found too many ops in a row");
}
}
} else {
// noinspection unchecked
CypherAstBase childObj = itemTransform.apply((T) child);
if (left == null) {
left = childObj;
} else {
if (op == null) {
throw new VertexiumException("unexpected binary expression. expected an op between expressions");
}
left = new CypherBinaryExpression(left, op, childObj);
}
op = null;
}
}
return (CypherBinaryExpression) left;
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class AccumuloGraphConfiguration method createConnector.
public Connector createConnector() {
try {
LOGGER.info("Connecting to accumulo instance [%s] zookeeper servers [%s]", this.getAccumuloInstanceName(), this.getZookeeperServers());
ZooKeeperInstance instance = new ZooKeeperInstance(getClientConfiguration());
return instance.getConnector(this.getAccumuloUsername(), this.getAuthenticationToken());
} catch (Exception ex) {
throw new VertexiumException(String.format("Could not connect to Accumulo instance [%s] zookeeper servers [%s]", this.getAccumuloInstanceName(), this.getZookeeperServers()), ex);
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class AccumuloGraphTestUtils method createTable.
private static void createTable(Connector connector, String tableName) {
try {
NewTableConfiguration config = new NewTableConfiguration().withoutDefaultIterators().setTimeType(TimeType.MILLIS);
connector.tableOperations().create(tableName, config);
} catch (Exception e) {
throw new VertexiumException("Unable to create table " + tableName);
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class AccumuloResource method addAuthorizations.
public void addAuthorizations(AccumuloGraph graph, String... authorizations) {
try {
String principal = graph.getConnector().whoami();
Authorizations currentAuthorizations = graph.getConnector().securityOperations().getUserAuthorizations(principal);
List<byte[]> newAuthorizationsArray = new ArrayList<>();
for (byte[] currentAuth : currentAuthorizations) {
newAuthorizationsArray.add(currentAuth);
}
for (String authorization : authorizations) {
if (!currentAuthorizations.contains(authorization)) {
newAuthorizationsArray.add(authorization.getBytes(UTF_8));
}
}
Authorizations newAuthorizations = new Authorizations(newAuthorizationsArray);
graph.getConnector().securityOperations().changeUserAuthorizations(principal, newAuthorizations);
} catch (Exception ex) {
throw new VertexiumException("could not add authorizations", ex);
}
}
Aggregations