144 lines
3.8 KiB
Java
144 lines
3.8 KiB
Java
package eu.old.eudat.data.entities;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonValue;
|
|
import org.opencdmp.commons.enums.EnumUtils;
|
|
import org.opencdmp.data.converters.enums.DatabaseEnum;
|
|
import org.opencdmp.data.converters.enums.DatabaseEnumConverter;
|
|
import eu.old.eudat.data.converters.DateToUTCConverter;
|
|
import eu.old.eudat.data.entities.helpers.EntityBinder;
|
|
import eu.old.eudat.queryable.queryableentity.DataEntity;
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Entity
|
|
@Table(name = "\"EntityDoi\"")
|
|
public class EntityDoi implements DataEntity<EntityDoi, UUID> {
|
|
public enum EntityType implements DatabaseEnum<Short> {
|
|
|
|
DMP((short) 0);
|
|
|
|
private final Short value;
|
|
|
|
EntityType(Short value) {
|
|
this.value = value;
|
|
}
|
|
|
|
@Override
|
|
@JsonValue
|
|
public Short getValue() {
|
|
return value;
|
|
}
|
|
|
|
private static final Map<Short, EntityType> map = EnumUtils.getEnumValueMap(EntityType.class);
|
|
|
|
public static EntityType of(Short i) {
|
|
return map.get(i);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Id
|
|
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
|
private UUID id;
|
|
|
|
@Column(name = "entity_type", nullable = false)
|
|
@Convert(converter = EntityTypeConverter.class)
|
|
private EntityType entityType;
|
|
|
|
@Column(name = "repository_id", nullable = false)
|
|
private String repositoryId;
|
|
|
|
@Column(name = "doi", nullable = false)
|
|
private String doi;
|
|
|
|
@Column(name = "created_at", nullable = false)
|
|
@Convert(converter = DateToUTCConverter.class)
|
|
private Date createdAt;
|
|
|
|
@Column(name = "updated_at", nullable = false)
|
|
@Convert(converter = DateToUTCConverter.class)
|
|
private Date updatedAt;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "entity_id", nullable = false)
|
|
private DMP entityId;
|
|
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public EntityType getEntityType() {
|
|
return entityType;
|
|
}
|
|
public void setEntityType(EntityType entityType) {
|
|
this.entityType = entityType;
|
|
}
|
|
|
|
public String getRepositoryId() {
|
|
return repositoryId;
|
|
}
|
|
public void setRepositoryId(String repositoryId) {
|
|
this.repositoryId = repositoryId;
|
|
}
|
|
|
|
public String getDoi() {
|
|
return doi;
|
|
}
|
|
public void setDoi(String doi) {
|
|
this.doi = doi;
|
|
}
|
|
|
|
public Date getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
public void setCreatedAt(Date createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
public Date getUpdatedAt() {
|
|
return updatedAt;
|
|
}
|
|
public void setUpdatedAt(Date updatedAt) {
|
|
this.updatedAt = updatedAt;
|
|
}
|
|
|
|
public DMP getEntityId() {
|
|
return entityId;
|
|
}
|
|
public void setEntityId(DMP entityId) {
|
|
this.entityId = entityId;
|
|
}
|
|
|
|
@Override
|
|
public void update(EntityDoi doi) {
|
|
this.entityType = doi.getEntityType();
|
|
this.repositoryId = doi.getRepositoryId();
|
|
this.doi = doi.getDoi();
|
|
this.createdAt = doi.getCreatedAt();
|
|
this.updatedAt = doi.getUpdatedAt();
|
|
this.entityId = doi.getEntityId();
|
|
}
|
|
|
|
@Override
|
|
public UUID getKeys() {
|
|
return this.id;
|
|
}
|
|
|
|
@Override
|
|
public EntityDoi buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
|
String currentBase = base.isEmpty() ? "" : base + ".";
|
|
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
|
if (fields.contains(currentBase + "entityId"))
|
|
this.entityId = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields , base.isEmpty() ? "entityId" : base + "." + "entityId")).collect(Collectors.toList()).get(0);
|
|
return this;
|
|
}
|
|
}
|