From 3417c8d5dd0533395523e6cc6e7d2b352aac7a5c Mon Sep 17 00:00:00 2001 From: pkiraly Date: Thu, 8 Jul 2021 16:53:39 +0200 Subject: [PATCH] issue #76: inactive fields don't create categories. --- .../gwdg/metadataqa/api/model/Category.java | 9 ++-- .../metadataqa/api/schema/edm/EdmSchema.java | 4 +- .../metadataqa/api/model/CategoryTest.java | 43 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/test/java/de/gwdg/metadataqa/api/model/CategoryTest.java diff --git a/src/main/java/de/gwdg/metadataqa/api/model/Category.java b/src/main/java/de/gwdg/metadataqa/api/model/Category.java index b5cab26a..41d6c966 100644 --- a/src/main/java/de/gwdg/metadataqa/api/model/Category.java +++ b/src/main/java/de/gwdg/metadataqa/api/model/Category.java @@ -32,7 +32,7 @@ public static List extractCategories(Collection paths) { } public static List extractCategories(Collection paths, - boolean reorder) { + boolean reorder) { List existingCategories = extractExistingCategories(paths); if (reorder) @@ -44,9 +44,10 @@ public static List extractCategories(Collection paths, private static List extractExistingCategories(Collection paths) { List existingCategories = new ArrayList<>(); for (JsonBranch branch : paths) - for (String category : branch.getCategories()) - if (!existingCategories.contains(category)) - existingCategories.add(category); + if (branch.isActive()) + for (String category : branch.getCategories()) + if (!existingCategories.contains(category)) + existingCategories.add(category); return existingCategories; } diff --git a/src/main/java/de/gwdg/metadataqa/api/schema/edm/EdmSchema.java b/src/main/java/de/gwdg/metadataqa/api/schema/edm/EdmSchema.java index f0ebf7e8..99b99a40 100644 --- a/src/main/java/de/gwdg/metadataqa/api/schema/edm/EdmSchema.java +++ b/src/main/java/de/gwdg/metadataqa/api/schema/edm/EdmSchema.java @@ -58,9 +58,9 @@ public JsonBranch getPathByLabel(String label) { @Override public List getCategories() { - if (categories == null) { + if (categories == null) categories = Category.extractCategories(paths.values(), true); - } + return categories; } diff --git a/src/test/java/de/gwdg/metadataqa/api/model/CategoryTest.java b/src/test/java/de/gwdg/metadataqa/api/model/CategoryTest.java new file mode 100644 index 00000000..604d3da6 --- /dev/null +++ b/src/test/java/de/gwdg/metadataqa/api/model/CategoryTest.java @@ -0,0 +1,43 @@ +package de.gwdg.metadataqa.api.model; + +import de.gwdg.metadataqa.api.json.JsonBranch; +import de.gwdg.metadataqa.api.schema.BaseSchema; +import de.gwdg.metadataqa.api.schema.Schema; +import de.gwdg.metadataqa.api.schema.edm.EdmFullBeanSchema; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +public class CategoryTest { + + Schema schemaWithActiveField = new BaseSchema().addField(new JsonBranch("contentWarning").setCategories("CONTEXT")); + Schema schemaWithInactiveField = new BaseSchema().addField(new JsonBranch("contentWarning").setCategories("CONTEXT").setActive(false)); + + @Test + public void extractCategories_withActive() { + assertEquals(List.of("CONTEXT"), schemaWithActiveField.getCategories()); + } + + @Test + public void extractCategories_withInactive() { + assertEquals(List.of(), schemaWithInactiveField.getCategories()); + } + + @Test + public void ExtractCategories_withTrue() { + Schema schema = new EdmFullBeanSchema(); + assertEquals(List.of( + "MANDATORY", "DESCRIPTIVENESS", "SEARCHABILITY", "CONTEXTUALIZATION", "IDENTIFICATION", "BROWSING", "VIEWING", "REUSABILITY", "MULTILINGUALITY"), + Category.extractCategories(schema.getPaths(), true)); + } + + @Test + public void ExtractCategories_withFalse() { + Schema schema = new EdmFullBeanSchema(); + assertEquals(List.of( + "MANDATORY", "DESCRIPTIVENESS", "SEARCHABILITY", "IDENTIFICATION", "MULTILINGUALITY", "CONTEXTUALIZATION", "BROWSING", "REUSABILITY", "VIEWING"), + Category.extractCategories(schema.getPaths(), false)); + } +} \ No newline at end of file