argos/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java

141 lines
3.6 KiB
Java

package eu.eudat.elastic.entities;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Created by ikalyvas on 7/5/2018.
*/
public class Dataset implements ElasticEntity<Dataset> {
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
private String id;
//private List<Tag> tags = new LinkedList<>();
private String label;
private UUID template;
private Short status;
private UUID dmp;
private UUID grant;
private List<Collaborator> collaborators;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/*public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}*/
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public UUID getTemplate() {
return template;
}
public void setTemplate(UUID template) {
this.template = template;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
public UUID getGrant() {
return grant;
}
public void setGrant(UUID grant) {
this.grant = grant;
}
public List<Collaborator> getCollaborators() {
return collaborators;
}
public void setCollaborators(List<Collaborator> collaborators) {
this.collaborators = collaborators;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("id", this.id);
builder.field("label", this.label);
builder.field("template", this.template.toString());
builder.field("status", this.status.toString());
builder.field("dmp", this.dmp.toString());
builder.field("grant", this.grant.toString());
builder.startArray("collaborators");
this.collaborators.forEach(x -> {
try {
x.toElasticEntity(builder);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
builder.endArray();
/*builder.startArray("tags");
this.tags.forEach(x -> {
try {
x.toElasticEntity(builder);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
builder.endArray();*/
builder.endObject();
return builder;
}
@Override
public Dataset fromElasticEntity(Map<String, Object> fields) {
if (fields != null) {
this.id = (String) fields.get("id");
// this.tags = ((List<Tag>) fields.get("tags"));
this.label = (String) fields.get("label");
this.template = UUID.fromString((String) fields.get("template"));
this.status = Short.valueOf((String) fields.get("status"));
this.dmp = UUID.fromString((String) fields.get("dmp"));
this.grant = UUID.fromString((String) fields.get("grant"));
this.collaborators = ((List<Collaborator>) fields.get("collaborators"));
}
return this;
}
}