use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.
the class DocumentSelectionBuilder method build.
public String build(ModelElement elem) {
StringBuilder sb = new StringBuilder();
if (elem != null) {
for (ModelElement e : elem.subElements("document")) {
if (sb.length() > 0) {
sb.append(" OR ");
}
sb.append('(');
String type = e.getStringAttribute("type");
sb.append(type);
String selection = e.getStringAttribute("selection");
if (selection != null) {
validateSelectionExpression(selection, type);
sb.append(" AND (");
sb.append(selection);
sb.append(')');
}
sb.append(')');
}
String globalSelection = elem.getStringAttribute("selection");
if (globalSelection != null) {
validateSelectionExpression(globalSelection, null);
StringBuilder global = new StringBuilder();
global.append('(').append(globalSelection).append(") AND (").append(sb.toString()).append(')');
return global.toString();
}
}
return sb.toString();
}
use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.
the class DomDispatchBuilder method buildGroup.
private static DispatchSpec.Group buildGroup(ModelElement groupElement) {
List<ModelElement> nodes = groupElement.subElements("node");
DispatchSpec.Group group = new DispatchSpec.Group();
for (ModelElement nodeElement : nodes) {
group.addNode(buildNode(nodeElement));
}
return group;
}
use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.
the class DomDispatchBuilder method build.
public static DispatchSpec build(ModelElement contentXml) {
DispatchSpec.Builder builder = new DispatchSpec.Builder();
ModelElement dispatchElement = contentXml.getChild("dispatch");
if (dispatchElement == null) {
return builder.build();
}
builder.setNumDispatchGroups(dispatchElement.childAsInteger("num-dispatch-groups"));
List<ModelElement> groupsElement = dispatchElement.subElements("group");
if (groupsElement != null) {
builder.setGroups(buildGroups(groupsElement));
}
return builder.build();
}
use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.
the class DomSearchCoverageBuilder method build.
public static SearchCoverage build(ModelElement contentXml) {
SearchCoverage.Builder builder = new SearchCoverage.Builder();
ModelElement searchElement = contentXml.getChild("search");
if (searchElement == null) {
return builder.build();
}
ModelElement coverageElement = searchElement.getChild("coverage");
if (coverageElement == null) {
return builder.build();
}
builder.setMinimum(coverageElement.childAsDouble("minimum"));
builder.setMinWaitAfterCoverageFactor(coverageElement.childAsDouble("min-wait-after-coverage-factor"));
builder.setMaxWaitAfterCoverageFactor(coverageElement.childAsDouble("max-wait-after-coverage-factor"));
return builder.build();
}
use of com.yahoo.vespa.model.builder.xml.dom.ModelElement in project vespa by vespa-engine.
the class GlobalDistributionBuilderTest method global_documents_are_identified.
@Test
public void global_documents_are_identified() {
GlobalDistributionBuilder builder = new GlobalDistributionBuilder(createDocumentDefinitions());
String documentsElement = "<documents>" + " <document type=\"" + NON_GLOBAL_EXPLICIT.getName() + "\" global=\"false\"/>" + " <document type=\"" + GLOBAL_1.getName() + "\" global=\"true\"/>" + " <document type=\"" + NON_GLOBAL_IMPLICIT.getName() + "\"/>" + " <document type=\"" + GLOBAL_2.getName() + "\" global=\"true\"/>" + "</documents>";
Set<NewDocumentType> expectedResult = new HashSet<>(Arrays.asList(GLOBAL_1, GLOBAL_2));
Set<NewDocumentType> actualResult = builder.build(new ModelElement(XML.getDocument(documentsElement).getDocumentElement()));
assertEquals(expectedResult, actualResult);
}
Aggregations