Skip to content

Commit

Permalink
issue #76: inactive fields don't create categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Jul 8, 2021
1 parent 020afb0 commit 3417c8d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/main/java/de/gwdg/metadataqa/api/model/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static List<String> extractCategories(Collection<JsonBranch> paths) {
}

public static List<String> extractCategories(Collection<JsonBranch> paths,
boolean reorder) {
boolean reorder) {
List<String> existingCategories = extractExistingCategories(paths);

if (reorder)
Expand All @@ -44,9 +44,10 @@ public static List<String> extractCategories(Collection<JsonBranch> paths,
private static List<String> extractExistingCategories(Collection<JsonBranch> paths) {
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public JsonBranch getPathByLabel(String label) {

@Override
public List<String> getCategories() {
if (categories == null) {
if (categories == null)
categories = Category.extractCategories(paths.values(), true);
}

return categories;
}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/de/gwdg/metadataqa/api/model/CategoryTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 3417c8d

Please sign in to comment.