use of com.vaticle.typedb.core.test.behaviour.exception.ScenarioDefinitionException in project grakn by graknlabs.
the class TypeQLSteps method applyQueryTemplate.
private String applyQueryTemplate(String template, ConceptMap templateFiller) {
// find shortest matching strings between <>
Pattern pattern = Pattern.compile("<.+?>");
Matcher matcher = pattern.matcher(template);
StringBuilder builder = new StringBuilder();
int i = 0;
while (matcher.find()) {
String matched = matcher.group(0);
String requiredVariable = variableFromTemplatePlaceholder(matched.substring(1, matched.length() - 1));
builder.append(template, i, matcher.start());
if (templateFiller.contains(Reference.name(requiredVariable))) {
Concept concept = templateFiller.get(requiredVariable);
if (!concept.isThing())
throw new ScenarioDefinitionException("Cannot apply IID templating to Type concepts");
String conceptId = concept.asThing().getIID().toHexString();
builder.append(conceptId);
} else {
throw new ScenarioDefinitionException(String.format("No IID available for template placeholder: %s.", matched));
}
i = matcher.end();
}
builder.append(template.substring(i));
return builder.toString();
}
Aggregations