From 7b1eb6599ee650e6535836796f63a34878be0277 Mon Sep 17 00:00:00 2001 From: Richard Palmer Date: Tue, 6 Jul 2021 21:39:20 +0100 Subject: [PATCH] Enable categories in field groups to be configurable --- .../metadataqa/api/counter/CompletenessCounter.java | 10 +++++++--- .../java/de/gwdg/metadataqa/api/json/FieldGroup.java | 12 ++++++++---- .../de/gwdg/metadataqa/api/schema/BaseSchema.java | 8 +++++++- .../de/gwdg/metadataqa/api/util/SchemaFactory.java | 11 +++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/gwdg/metadataqa/api/counter/CompletenessCounter.java b/src/main/java/de/gwdg/metadataqa/api/counter/CompletenessCounter.java index 572b4e84..43e6d979 100644 --- a/src/main/java/de/gwdg/metadataqa/api/counter/CompletenessCounter.java +++ b/src/main/java/de/gwdg/metadataqa/api/counter/CompletenessCounter.java @@ -2,6 +2,7 @@ import de.gwdg.metadataqa.api.model.Category; import de.gwdg.metadataqa.api.schema.Schema; +import de.gwdg.metadataqa.api.json.FieldGroup; import java.io.Serializable; import java.util.ArrayList; @@ -50,10 +51,10 @@ public void increaseInstance(List categories) { basicCounters.get(category).increaseInstance(); } - public void increaseInstance(Category category, boolean increase) { - basicCounters.get(category.name()).increaseTotal(); + public void increaseInstance(String category, boolean increase) { + basicCounters.get(category).increaseTotal(); if (increase) { - basicCounters.get(category.name()).increaseInstance(); + basicCounters.get(category).increaseInstance(); } } @@ -76,6 +77,9 @@ public static List getHeaders(Schema schema) { for (String category : schema.getCategories()) { headers.add(category); } + for (FieldGroup group: schema.getFieldGroups()) { + headers.add(group.getCategory()); + } return headers; } diff --git a/src/main/java/de/gwdg/metadataqa/api/json/FieldGroup.java b/src/main/java/de/gwdg/metadataqa/api/json/FieldGroup.java index deb00647..e9a072ae 100644 --- a/src/main/java/de/gwdg/metadataqa/api/json/FieldGroup.java +++ b/src/main/java/de/gwdg/metadataqa/api/json/FieldGroup.java @@ -27,7 +27,7 @@ public class FieldGroup { /** * The sub dimension or category. */ - private Category category; + private String category; /** * Construct a new FieldGroup object. @@ -39,11 +39,15 @@ public class FieldGroup { * * @see JsonBranch */ + public FieldGroup(String sCategory, List sFields) { + this.category = sCategory; + this.fields = sFields; + } + public FieldGroup(Category pCategory, String... pFields) { - this.category = pCategory; + this.category = pCategory.toString(); this.fields = Arrays.asList(pFields); } - /** * Get the list of field names. * @return @@ -58,7 +62,7 @@ public List getFields() { * @return * The category */ - public Category getCategory() { + public String getCategory() { return category; } diff --git a/src/main/java/de/gwdg/metadataqa/api/schema/BaseSchema.java b/src/main/java/de/gwdg/metadataqa/api/schema/BaseSchema.java index 845f98da..6263e427 100644 --- a/src/main/java/de/gwdg/metadataqa/api/schema/BaseSchema.java +++ b/src/main/java/de/gwdg/metadataqa/api/schema/BaseSchema.java @@ -19,6 +19,7 @@ public class BaseSchema implements Schema, CsvAwareSchema, Serializable { private final Map collectionPaths = new LinkedHashMap<>(); private final Map directChildren = new LinkedHashMap<>(); private Map extractableFields = new LinkedHashMap<>(); + private List fieldGroups = new ArrayList<>(); private List categories = null; private List ruleCheckers; private List indexFields; @@ -88,9 +89,14 @@ public JsonBranch getPathByLabel(String label) { return paths.get(label); } + public BaseSchema addFieldGroup(FieldGroup fieldgroup) { + fieldGroups.add(fieldgroup); + return this; + } + @Override public List getFieldGroups() { - return new ArrayList<>(); + return fieldGroups; } @Override diff --git a/src/main/java/de/gwdg/metadataqa/api/util/SchemaFactory.java b/src/main/java/de/gwdg/metadataqa/api/util/SchemaFactory.java index f2c78aeb..6f02d65f 100644 --- a/src/main/java/de/gwdg/metadataqa/api/util/SchemaFactory.java +++ b/src/main/java/de/gwdg/metadataqa/api/util/SchemaFactory.java @@ -2,7 +2,10 @@ import de.gwdg.metadataqa.api.configuration.SchemaConfiguration; import de.gwdg.metadataqa.api.configuration.schema.Field; +import de.gwdg.metadataqa.api.configuration.schema.Group; +import de.gwdg.metadataqa.api.model.Category; import de.gwdg.metadataqa.api.json.JsonBranch; +import de.gwdg.metadataqa.api.json.FieldGroup; import de.gwdg.metadataqa.api.schema.BaseSchema; import de.gwdg.metadataqa.api.schema.Format; import de.gwdg.metadataqa.api.schema.Schema; @@ -63,6 +66,14 @@ public static Schema fromConfig(SchemaConfiguration config) { schema.addField(branch); } + for (Group group : config.getGroups()) { + FieldGroup fieldgroup = new FieldGroup( + group.getCategories().get(0), + group.getFields()); + + schema.addFieldGroup(fieldgroup); + } + if (config.getNamespaces() != null) schema.setNamespaces(config.getNamespaces());