2018-07-11 15:47:36 +02:00
|
|
|
package eu.eudat.elastic.entities;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
2020-01-16 16:46:24 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-11 15:47:36 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-03-09 15:47:32 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.stream.Collectors;
|
2018-07-11 15:47:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by ikalyvas on 7/5/2018.
|
|
|
|
*/
|
|
|
|
public class Dataset implements ElasticEntity<Dataset> {
|
2020-01-16 16:46:24 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
|
2018-07-11 15:47:36 +02:00
|
|
|
|
2020-03-11 10:04:49 +01:00
|
|
|
public enum Status {
|
|
|
|
SAVED((short) 0), FINALISED((short) 1), CANCELED((short) 2), DELETED((short) 99),;
|
|
|
|
|
|
|
|
private short value;
|
|
|
|
|
|
|
|
private Status(short value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Status fromInteger(int value) {
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
return SAVED;
|
|
|
|
case 1:
|
|
|
|
return FINALISED;
|
|
|
|
case 2:
|
|
|
|
return CANCELED;
|
|
|
|
case 99:
|
|
|
|
return DELETED;
|
|
|
|
default:
|
|
|
|
throw new RuntimeException("Unsupported Dataset Status");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-11 15:47:36 +02:00
|
|
|
private String id;
|
2020-03-11 10:04:49 +01:00
|
|
|
private List<Tag> tags = new LinkedList<>();
|
2020-03-09 15:47:32 +01:00
|
|
|
private String label;
|
|
|
|
private UUID template;
|
|
|
|
private Short status;
|
|
|
|
private UUID dmp;
|
2020-03-11 10:04:49 +01:00
|
|
|
private UUID group;
|
2020-03-09 15:47:32 +01:00
|
|
|
private UUID grant;
|
|
|
|
private List<Collaborator> collaborators;
|
2020-03-11 10:04:49 +01:00
|
|
|
private Boolean lastVersion;
|
|
|
|
private List<Organization> organizations;
|
2018-07-11 15:47:36 +02:00
|
|
|
|
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId(String id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2020-03-11 10:04:49 +01:00
|
|
|
public List<Tag> getTags() {
|
2018-07-11 15:47:36 +02:00
|
|
|
return tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTags(List<Tag> tags) {
|
|
|
|
this.tags = tags;
|
2020-03-11 10:04:49 +01:00
|
|
|
}
|
2020-03-09 15:47:32 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-11 10:04:49 +01:00
|
|
|
public UUID getGroup() {
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGroup(UUID group) {
|
|
|
|
this.group = group;
|
|
|
|
}
|
|
|
|
|
2020-03-09 15:47:32 +01:00
|
|
|
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;
|
2018-07-11 15:47:36 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 10:04:49 +01:00
|
|
|
public Boolean getLastVersion() {
|
|
|
|
return lastVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastVersion(Boolean lastVersion) {
|
|
|
|
this.lastVersion = lastVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Organization> getOrganizations() {
|
|
|
|
return organizations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOrganizations(List<Organization> organizations) {
|
|
|
|
this.organizations = organizations;
|
|
|
|
}
|
|
|
|
|
2018-07-11 15:47:36 +02:00
|
|
|
@Override
|
|
|
|
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
|
|
builder.startObject();
|
|
|
|
builder.field("id", this.id);
|
2020-03-09 15:47:32 +01:00
|
|
|
builder.field("label", this.label);
|
|
|
|
builder.field("template", this.template.toString());
|
|
|
|
builder.field("status", this.status.toString());
|
|
|
|
builder.field("dmp", this.dmp.toString());
|
2020-03-11 10:04:49 +01:00
|
|
|
builder.field("group", this.group.toString());
|
2020-03-09 15:47:32 +01:00
|
|
|
builder.field("grant", this.grant.toString());
|
2020-03-11 10:04:49 +01:00
|
|
|
if (collaborators != null) {
|
|
|
|
builder.startArray("collaborators");
|
|
|
|
this.collaborators.forEach(x -> {
|
|
|
|
try {
|
|
|
|
x.toElasticEntity(builder);
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
builder.endArray();
|
|
|
|
}
|
|
|
|
builder.field("lastVersion", this.lastVersion.toString());
|
|
|
|
if (organizations != null) {
|
|
|
|
builder.startArray("organizations");
|
|
|
|
this.organizations.forEach(x -> {
|
|
|
|
try {
|
|
|
|
x.toElasticEntity(builder);
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
builder.endArray();
|
|
|
|
}
|
|
|
|
if (this.tags != null) {
|
|
|
|
builder.startArray("tags");
|
|
|
|
this.tags.forEach(x -> {
|
|
|
|
try {
|
|
|
|
x.toElasticEntity(builder);
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.endArray();
|
|
|
|
}
|
2018-07-11 15:47:36 +02:00
|
|
|
builder.endObject();
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Dataset fromElasticEntity(Map<String, Object> fields) {
|
|
|
|
if (fields != null) {
|
|
|
|
this.id = (String) fields.get("id");
|
2020-03-11 10:04:49 +01:00
|
|
|
this.tags = ((List<Tag>) fields.get("tags"));
|
2020-03-09 15:47:32 +01:00
|
|
|
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"));
|
2020-03-11 10:04:49 +01:00
|
|
|
this.group = UUID.fromString((String) fields.get("goup"));
|
2020-03-09 15:47:32 +01:00
|
|
|
this.grant = UUID.fromString((String) fields.get("grant"));
|
|
|
|
this.collaborators = ((List<Collaborator>) fields.get("collaborators"));
|
2020-03-11 10:04:49 +01:00
|
|
|
this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
|
|
|
|
this.organizations = (List<Organization>) fields.get("organiztions");
|
2018-07-11 15:47:36 +02:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|