60 lines
1.8 KiB
Java
60 lines
1.8 KiB
Java
package eu.eudat.criteria;
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectReader;
|
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
|
import eu.eudat.criteria.entities.Criteria;
|
|
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
public class DatasetCriteria {
|
|
private Criteria<UUID> id;
|
|
private Criteria<String> label;
|
|
|
|
public Criteria<UUID> getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(JsonNode jsonNode) throws IOException {
|
|
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
|
|
Criteria<UUID> criteria = new Criteria<>();
|
|
criteria.setAs(jsonNode.asText());
|
|
this.id = criteria;
|
|
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
|
|
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<UUID>>() {
|
|
});
|
|
this.id = reader.readValue(jsonNode);
|
|
}
|
|
}
|
|
|
|
public Criteria<String> getLabel() {
|
|
return label;
|
|
}
|
|
|
|
public void setLabel(JsonNode jsonNode) throws IOException {
|
|
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
|
|
Criteria<String> criteria = new Criteria<>();
|
|
criteria.setAs(jsonNode.asText());
|
|
this.label = criteria;
|
|
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
|
|
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<String>>() {
|
|
});
|
|
this.label = reader.readValue(jsonNode);
|
|
}
|
|
}
|
|
|
|
|
|
protected List<String> buildFields(String path) {
|
|
Set<String> fields = new HashSet<>();
|
|
path = path != null && !path.isEmpty() ? path + "." : "";
|
|
if (this.id != null) fields.add(path + this.id.getAs());
|
|
if (this.label != null) fields.add(path + this.label.getAs());
|
|
if (!fields.contains(path + "id")) fields.add(path + "id");
|
|
return new LinkedList<>(fields);
|
|
}
|
|
|
|
}
|