Skip to content

Commit

Permalink
Merge pull request #73 from atiro/field-group-free-categories
Browse files Browse the repository at this point in the history
Enable categories in field groups to be configurable
  • Loading branch information
pkiraly authored Jul 7, 2021
2 parents 284573d + 7b1eb65 commit 2a7dc24
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,10 +51,10 @@ public void increaseInstance(List<String> 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();
}
}

Expand All @@ -76,6 +77,9 @@ public static List<String> getHeaders(Schema schema) {
for (String category : schema.getCategories()) {
headers.add(category);
}
for (FieldGroup group: schema.getFieldGroups()) {
headers.add(group.getCategory());
}
return headers;
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/de/gwdg/metadataqa/api/json/FieldGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FieldGroup {
/**
* The sub dimension or category.
*/
private Category category;
private String category;

/**
* Construct a new FieldGroup object.
Expand All @@ -39,11 +39,15 @@ public class FieldGroup {
*
* @see JsonBranch
*/
public FieldGroup(String sCategory, List<String> 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
Expand All @@ -58,7 +62,7 @@ public List<String> getFields() {
* @return
* The category
*/
public Category getCategory() {
public String getCategory() {
return category;
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/de/gwdg/metadataqa/api/schema/BaseSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BaseSchema implements Schema, CsvAwareSchema, Serializable {
private final Map<String, JsonBranch> collectionPaths = new LinkedHashMap<>();
private final Map<String, JsonBranch> directChildren = new LinkedHashMap<>();
private Map<String, String> extractableFields = new LinkedHashMap<>();
private List<FieldGroup> fieldGroups = new ArrayList<>();
private List<String> categories = null;
private List<RuleChecker> ruleCheckers;
private List<JsonBranch> indexFields;
Expand Down Expand Up @@ -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<FieldGroup> getFieldGroups() {
return new ArrayList<>();
return fieldGroups;
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/gwdg/metadataqa/api/util/SchemaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 2a7dc24

Please sign in to comment.