Defining skeleton implementation

This commit is contained in:
Luca Frosini 2023-03-03 17:11:10 +01:00
parent cf43846c73
commit 008303b939
4 changed files with 150 additions and 0 deletions

View File

@ -1,8 +1,17 @@
package org.gcube.grsf.publisher.record;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Fishery extends Record {
public Fishery(JsonNode jsonNode) {
super(jsonNode);
TextNode textNode = new TextNode("Fishery");
addProperty(SOURCE_KEY, textNode);
}
}

View File

@ -1,8 +1,74 @@
package org.gcube.grsf.publisher.record;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.grsf.publisher.record.property.Property;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Record {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public static final String DOMAIN_KEY = "Domain";
public static final String SOURCE_KEY = "Source";
protected ObjectMapper objectMapper;
protected JsonNode jsonNode;
protected Map<String, JsonNode> properties;
protected Set<String> groups;
protected Set<String> tags;
protected Set<String> resources;
public Record(JsonNode jsonNode) {
this.objectMapper = new ObjectMapper();
this.jsonNode = jsonNode;
this.properties = new HashMap<>();
this.groups = new HashSet<>();
this.tags = new HashSet<>();
this.resources = new HashSet<>();
}
protected void addProperty(String key, JsonNode value) {
this.properties.put(key, value);
}
protected void addGroup(String group) {
this.groups.add(group);
}
protected void addTag(String tag) {
this.tags.add(tag);
}
public void elaborate() {
Iterator<String> iterator = jsonNode.fieldNames();
while(iterator.hasNext()) {
String originalKey = iterator.next();
JsonNode originalValue = jsonNode.get(originalKey);
Property property = new Property(originalKey, originalValue);
property.elaborate();
String key = property.getKey();
JsonNode value = property.getValue();
this.properties.put(key, value);
this.groups.addAll(property.getGroups());
this.tags.addAll(property.getTags());
this.resources.addAll(property.getResources());
}
}
}

View File

@ -1,8 +1,17 @@
package org.gcube.grsf.publisher.record;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Stock extends Record {
public Stock (JsonNode jsonNode) {
super(jsonNode);
TextNode textNode = new TextNode("Stock");
addProperty(SOURCE_KEY, textNode);
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.grsf.publisher.record.property;
import java.util.HashSet;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Property {
protected String originalKey;
protected JsonNode originalValue;
protected String dstKey;
protected JsonNode dstValue;
protected Set<String> groups;
protected Set<String> tags;
protected Set<String> resources;
public Property(String originalKey, JsonNode originalValue) {
this.originalKey = originalKey;
this.originalValue = originalValue;
this.groups = new HashSet<>();
this.tags = new HashSet<>();
this.resources = new HashSet<>();
}
public Set<String> getGroups() {
return groups;
}
public Set<String> getTags() {
return tags;
}
public Set<String> getResources() {
return resources;
}
public String getKey() {
return dstKey;
}
public JsonNode getValue() {
return dstValue;
}
public void elaborate() {
// TODO
// TODO find the mapping in metadata profile
// TODO validate the field
// TODO set group not manageable by gcat
// TODO set tags not manageable by gcat
// TODO create resource if any
}
}