aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-10-15 13:36:39 +0200
committerJon Bratseth <bratseth@gmail.com>2021-10-15 13:36:39 +0200
commitb6d8f17313fc20d1ca256fb61c3013c89d7ee47c (patch)
tree5f2ba4a14d8993ddb9e7f80c9a3210ca64db5565 /config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
parent88cd5ae7d2a2660ca8420a91824fa14d78e95582 (diff)
Validate summary inheritance
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
index 78cc0d496b0..6056ca49abf 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java
@@ -128,10 +128,10 @@ public class SearchBuilder {
/**
* Import search definition.
*
- * @param fileName The name of the file to import.
- * @return The name of the imported object.
- * @throws IOException Thrown if the file can not be read for some reason.
- * @throws ParseException Thrown if the file does not contain a valid search definition. ```
+ * @param fileName the name of the file to import
+ * @return the name of the imported object
+ * @throws IOException thrown if the file can not be read for some reason
+ * @throws ParseException thrown if the file does not contain a valid search definition
*/
public String importFile(String fileName) throws IOException, ParseException {
File file = new File(fileName);
@@ -146,10 +146,10 @@ public class SearchBuilder {
* Reads and parses the search definition string provided by the given reader. Once all search definitions have been
* imported, call {@link #build()}.
*
- * @param reader The reader whose content to import.
- * @param searchDefDir The path to use when resolving file references.
- * @return The name of the imported object.
- * @throws ParseException Thrown if the file does not contain a valid search definition.
+ * @param reader the reader whose content to import
+ * @param searchDefDir the path to use when resolving file references
+ * @return the name of the imported object
+ * @throws ParseException thrown if the file does not contain a valid search definition
*/
public String importReader(NamedReader reader, String searchDefDir) throws IOException, ParseException {
return importString(IOUtils.readAll(reader), searchDefDir);
@@ -222,6 +222,9 @@ public class SearchBuilder {
public void build(boolean validate) {
if (isBuilt) throw new IllegalStateException("Model already built");
+ if (validate)
+ searchList.forEach(search -> search.validate());
+
List<Search> built = new ArrayList<>();
List<SDDocumentType> sdocs = new ArrayList<>();
sdocs.add(SDDocumentType.VESPA_DOCUMENT);
@@ -230,6 +233,7 @@ public class SearchBuilder {
sdocs.add(search.getDocument());
}
}
+
var orderer = new SDDocumentTypeOrderer(sdocs, deployLogger);
orderer.process();
for (SDDocumentType sdoc : orderer.getOrdered()) {
@@ -255,7 +259,8 @@ public class SearchBuilder {
builder.addToModel(searchList);
if ( validate && ! builder.valid() )
- throw new IllegalArgumentException("Impossible to build a correct model.");
+ throw new IllegalArgumentException("Impossible to build a correct model");
+
searchList = built;
isBuilt = true;
}
@@ -332,6 +337,14 @@ public class SearchBuilder {
return builder;
}
+ public static SearchBuilder createFromStrings(DeployLogger logger, String ... schemas) throws ParseException {
+ SearchBuilder builder = new SearchBuilder(logger);
+ for (var schema : schemas)
+ builder.importString(schema);
+ builder.build(true);
+ return builder;
+ }
+
/**
* Convenience factory method to import and build a {@link Search} object from a file. Only for testing.
*