use of ai.grakn.graql.Printer in project grakn by graknlabs.
the class GraqlPrinterTest method whenPrintingRole_ShowLabel.
@Test
public void whenPrintingRole_ShowLabel() {
Printer printer = Printers.graql(true);
Role role = rule.tx().admin().getMetaRole();
String roleString = printer.graqlString(role);
assertThat(roleString, containsString("role"));
}
use of ai.grakn.graql.Printer in project grakn by graknlabs.
the class GraqlPrinterTest method testEmptyResult.
@Test
public void testEmptyResult() {
Printer printer = Printers.graql(true);
Answer emptyResult = new QueryAnswer();
assertEquals("{}", printer.graqlString(emptyResult));
}
use of ai.grakn.graql.Printer in project grakn by graknlabs.
the class GraqlPrinterTest method testType.
@Test
public void testType() {
Printer printer = Printers.graql(true);
Type production = rule.tx().getEntityType("production");
String productionString = printer.graqlString(production);
assertThat(productionString, containsString("label"));
assertThat(productionString, containsString("production"));
assertThat(productionString, containsString("sub"));
assertThat(productionString, containsString("entity"));
assertThat(productionString, not(containsString("isa")));
assertThat(productionString, not(containsString("entity-type")));
}
use of ai.grakn.graql.Printer in project grakn by graknlabs.
the class GraqlPrinterTest method testEntityType.
@Test
public void testEntityType() {
Printer printer = Printers.graql(true);
Type entity = rule.tx().admin().getMetaEntityType();
String entityString = printer.graqlString(entity);
assertThat(entityString, containsString("label"));
assertThat(entityString, containsString("entity"));
assertThat(entityString, containsString("sub"));
assertThat(entityString, containsString(Schema.MetaSchema.THING.getLabel().getValue()));
assertThat(entityString, not(containsString("isa")));
}
use of ai.grakn.graql.Printer in project grakn by graknlabs.
the class GraqlController method executeQuery.
/**
* Execute a query and return a response in the format specified by the request.
*
* @param tx open transaction to current graph
* @param queryString read query to be executed
* @param acceptType response format that the client will accept
* @param multi execute multiple statements
* @param parser
*/
private String executeQuery(EmbeddedGraknTx<?> tx, String queryString, String acceptType, boolean multi, boolean skipSerialisation, QueryParser parser) throws JsonProcessingException {
Printer printer = this.printer;
if (APPLICATION_TEXT.equals(acceptType))
printer = Printers.graql(false);
String formatted;
boolean commitQuery = true;
if (multi) {
Stream<Query<?>> query = parser.parseList(queryString);
List<?> collectedResults = query.map(this::executeAndMonitor).collect(Collectors.toList());
if (skipSerialisation) {
formatted = mapper.writeValueAsString(new Object[collectedResults.size()]);
} else {
formatted = printer.graqlString(collectedResults);
}
} else {
Query<?> query = parser.parseQuery(queryString);
if (skipSerialisation) {
formatted = "";
} else {
formatted = printer.graqlString(executeAndMonitor(query));
}
commitQuery = !query.isReadOnly();
}
if (commitQuery)
tx.commitSubmitNoLogs().ifPresent(postProcessor::submit);
return formatted;
}
Aggregations