Updating Dmp Entity fields to reflect the database changes (migration script not yet updated)

This commit is contained in:
Thomas Georgios Giannos 2023-11-02 13:45:32 +02:00
parent ac15e33a87
commit c3808b5548
9 changed files with 192 additions and 229 deletions

View File

@ -0,0 +1,30 @@
package eu.eudat.commons.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum DmpAccessType implements DatabaseEnum<Short> {
Public((short) 0), Restricted((short) 1);
private final Short value;
DmpAccessType(Short value) {
this.value = value;
}
@Override
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, DmpAccessType> map = EnumUtils.getEnumValueMap(DmpAccessType.class);
public static DmpAccessType of(Short i) {
return map.get(i);
}
}

View File

@ -18,7 +18,7 @@ public enum DmpStatus implements DatabaseEnum<Short> {
@Override
@JsonValue
public Short getValue() {
return null;
return value;
}
private static final Map<Short, DmpStatus> map = EnumUtils.getEnumValueMap(DmpStatus.class);

View File

@ -1,11 +1,11 @@
package eu.eudat.data;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.*;
import org.hibernate.annotations.GenericGenerator;
import java.time.Instant;
import java.util.UUID;
@ -26,7 +26,7 @@ public class DmpEntity {
public static final String _label = "label";
@Column(name = "version")
private Integer version;
private Short version;
public static final String _version = "version";
@ -41,11 +41,6 @@ public class DmpEntity {
public static final String _properties = "properties";
@Column(name = "dmp_properties")
private String dmpProperties;
public static final String _dmpProperties = "dmpProperties";
@Column(name = "group_id", columnDefinition = "BINARY(16)")
private UUID groupId;
@ -56,16 +51,6 @@ public class DmpEntity {
public static final String _description = "description";
@Column(name = "is_public", nullable = false)
private boolean isPublic;
public static final String _isPublic = "isPublic";
@Column(name = "extra_properties")
private String extraProperties;
public static final String _extraProperties = "extraProperties";
@Column(name = "created_at")
@Convert(converter = DateToUTCConverter.class)
private Instant createdAt;
@ -90,17 +75,33 @@ public class DmpEntity {
public static final String _finalizedAt = "finalizedAt";
@Column(name = "published_at")
@Convert(converter = DateToUTCConverter.class)
private Instant publishedAt;
public static final String _publishedAt = "publishedAt";
@Column(name = "creator")
private UUID creator;
public static final String _creator = "creator";
@Enumerated(EnumType.STRING)
@Column(name = "access_type", nullable = false)
private DmpAccessType accessType;
public static final String _accessType = "accessType";
@Column(name = "blueprint")
private UUID blueprint;
public static final String _blueprint = "blueprint";
@Column(name = "language")
private String language;
public static final String _language = "language";
@Column(name = "public_after")
@Convert(converter = DateToUTCConverter.class)
private Instant publicAfter;
public static final String _publicAfter = "publicAfter";
public UUID getId() {
return id;
}
@ -117,11 +118,11 @@ public class DmpEntity {
this.label = label;
}
public Integer getVersion() {
public Short getVersion() {
return version;
}
public void setVersion(Integer version) {
public void setVersion(Short version) {
this.version = version;
}
@ -141,14 +142,6 @@ public class DmpEntity {
this.properties = properties;
}
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
public UUID getGroupId() {
return groupId;
}
@ -165,22 +158,6 @@ public class DmpEntity {
this.description = description;
}
public boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(String extraProperties) {
this.extraProperties = extraProperties;
}
public Instant getCreatedAt() {
return createdAt;
}
@ -213,14 +190,6 @@ public class DmpEntity {
this.finalizedAt = finalizedAt;
}
public Instant getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Instant publishedAt) {
this.publishedAt = publishedAt;
}
public UUID getCreator() {
return creator;
}
@ -229,4 +198,35 @@ public class DmpEntity {
this.creator = creator;
}
public DmpAccessType getAccessType() {
return accessType;
}
public void setAccessType(DmpAccessType accessType) {
this.accessType = accessType;
}
public UUID getBlueprint() {
return blueprint;
}
public void setBlueprint(UUID blueprint) {
this.blueprint = blueprint;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public Instant getPublicAfter() {
return publicAfter;
}
public void setPublicAfter(Instant publicAfter) {
this.publicAfter = publicAfter;
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.DmpAccessType;
import jakarta.persistence.Converter;
@Converter
public class DmpAccessTypeConverter extends DatabaseEnumConverter<DmpAccessType, Short> {
@Override
protected DmpAccessType of(Short i) {
return DmpAccessType.of(i);
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.model;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
@ -10,62 +11,85 @@ import java.util.UUID;
public class Dmp {
private UUID id;
public static final String _id = "id";
private String label;
public static final String _label = "label";
private Integer version;
private Short version;
public static final String _version = "version";
private DmpStatus status;
public static final String _status = "status";
private String properties;
public static final String _properties = "properties";
private String dmpProperties;
public static final String _dmpProperties = "dmpProperties";
private UUID groupId;
public static final String _groupId = "groupId";
private String description;
public static final String _description = "description";
private boolean isPublic;
public static final String _isPublic = "isPublic";
private String extraProperties;
public static final String _extraProperties = "extraProperties";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private IsActive isActive;
public static final String _isActive = "isActive";
private Instant finalizedAt;
public static final String _finalizedAt = "finalizedAt";
private Instant publishedAt;
public static final String _publishedAt = "publishedAt";
private UUID creator;
public static final String _creator = "creator";
private DmpAccessType accessType;
public static final String _accessType = "accessType";
private UUID blueprint;
public static final String _blueprint = "blueprint";
private String language;
public static final String _language = "language";
private Instant publicAfter;
public static final String _publicAfter = "publicAfter";
private String hash;
public static final String _hash = "hash";
private List<Description> dmpDescriptions;
public static final String _dmpDescriptions = "dmpDescriptions";
public static final String _dmpReferences = "dmpReferences";
private List<DmpReference> dmpReferences;
public static final String _dmpReferences = "dmpReferences";
public UUID getId() {
return id;
}
@ -82,11 +106,11 @@ public class Dmp {
this.label = label;
}
public Integer getVersion() {
public Short getVersion() {
return version;
}
public void setVersion(Integer version) {
public void setVersion(Short version) {
this.version = version;
}
@ -106,14 +130,6 @@ public class Dmp {
this.properties = properties;
}
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
public UUID getGroupId() {
return groupId;
}
@ -130,22 +146,6 @@ public class Dmp {
this.description = description;
}
public boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(String extraProperties) {
this.extraProperties = extraProperties;
}
public Instant getCreatedAt() {
return createdAt;
}
@ -194,6 +194,38 @@ public class Dmp {
this.creator = creator;
}
public DmpAccessType getAccessType() {
return accessType;
}
public void setAccessType(DmpAccessType accessType) {
this.accessType = accessType;
}
public UUID getBlueprint() {
return blueprint;
}
public void setBlueprint(UUID blueprint) {
this.blueprint = blueprint;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public Instant getPublicAfter() {
return publicAfter;
}
public void setPublicAfter(Instant publicAfter) {
this.publicAfter = publicAfter;
}
public String getHash() {
return hash;
}

View File

@ -57,6 +57,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions));
Map<UUID, List<Description>> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data);
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences));
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
@ -72,16 +73,10 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
m.setStatus(d.getStatus());
if (fields.hasField(this.asIndexer(Dmp._properties)))
m.setProperties(d.getProperties());
if (fields.hasField(this.asIndexer(Dmp._dmpProperties)))
m.setDmpProperties(d.getDmpProperties());
if (fields.hasField(this.asIndexer(Dmp._groupId)))
m.setGroupId(d.getGroupId());
if (fields.hasField(this.asIndexer(Dmp._description)))
m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(Dmp._isPublic)))
m.setIsPublic(d.getIsPublic());
if (fields.hasField(this.asIndexer(Dmp._extraProperties)))
m.setExtraProperties(d.getExtraProperties());
if (fields.hasField(this.asIndexer(Dmp._createdAt)))
m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Dmp._updatedAt)))
@ -90,8 +85,14 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Dmp._finalizedAt)))
m.setFinalizedAt(d.getFinalizedAt());
if (fields.hasField(this.asIndexer(Dmp._publishedAt)))
m.setPublishedAt(d.getPublishedAt());
if (fields.hasField(this.asIndexer(Dmp._accessType)))
m.setAccessType(d.getAccessType());
if (fields.hasField(this.asIndexer(Dmp._blueprint)))
m.setBlueprint(d.getBlueprint());
if (fields.hasField(this.asIndexer(Dmp._language)))
m.setLanguage(d.getLanguage());
if (fields.hasField(this.asIndexer(Dmp._publicAfter)))
m.setPublicAfter(d.getPublicAfter());
if (fields.hasField(this.asIndexer(Dmp._hash)))
m.setHash(this.hashValue(d.getUpdatedAt()));

View File

@ -13,34 +13,12 @@ public class DmpPersist {
private String label;
private Integer version;
private DmpStatus status;
private String properties;
private String dmpProperties;
private UUID groupId;
private String description;
private boolean isPublic;
private String extraProperties;
private Instant finalizedAt;
private Instant publishedAt;
private UUID grant;
private UUID profile;
private UUID creator;
private UUID project;
private String hash;
public UUID getId() {
@ -59,14 +37,6 @@ public class DmpPersist {
this.label = label;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public DmpStatus getStatus() {
return status;
}
@ -83,22 +53,6 @@ public class DmpPersist {
this.properties = properties;
}
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public String getDescription() {
return description;
}
@ -107,70 +61,6 @@ public class DmpPersist {
this.description = description;
}
public boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(String extraProperties) {
this.extraProperties = extraProperties;
}
public Instant getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
public Instant getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Instant publishedAt) {
this.publishedAt = publishedAt;
}
public UUID getGrant() {
return grant;
}
public void setGrant(UUID grant) {
this.grant = grant;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public UUID getCreator() {
return creator;
}
public void setCreator(UUID creator) {
this.creator = creator;
}
public UUID getProject() {
return project;
}
public void setProject(UUID project) {
this.project = project;
}
public String getHash() {
return hash;
}

View File

@ -1,6 +1,7 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
@ -192,16 +193,16 @@ public class DmpQuery extends QueryBase<DmpEntity> {
else if (item.match(Dmp._version)) return DmpEntity._version;
else if (item.match(Dmp._status)) return DmpEntity._status;
else if (item.match(Dmp._properties)) return DmpEntity._properties;
else if (item.match(Dmp._dmpProperties)) return DmpEntity._dmpProperties;
else if (item.match(Dmp._groupId)) return DmpEntity._groupId;
else if (item.match(Dmp._description)) return DmpEntity._description;
else if (item.match(Dmp._isPublic)) return DmpEntity._isPublic;
else if (item.match(Dmp._extraProperties)) return DmpEntity._extraProperties;
else if (item.match(Dmp._createdAt)) return DmpEntity._createdAt;
else if (item.match(Dmp._updatedAt)) return DmpEntity._updatedAt;
else if (item.match(Dmp._isActive)) return DmpEntity._isActive;
else if (item.match(Dmp._finalizedAt)) return DmpEntity._finalizedAt;
else if (item.match(Dmp._publishedAt)) return DmpEntity._publishedAt;
else if (item.match(Dmp._accessType)) return DmpEntity._accessType;
else if (item.match(Dmp._blueprint)) return DmpEntity._blueprint;
else if (item.match(Dmp._language)) return DmpEntity._language;
else if (item.match(Dmp._publicAfter)) return DmpEntity._publicAfter;
else return null;
}
@ -210,19 +211,19 @@ public class DmpQuery extends QueryBase<DmpEntity> {
DmpEntity item = new DmpEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DmpEntity._id, UUID.class));
item.setLabel(QueryBase.convertSafe(tuple, columns, DmpEntity._label, String.class));
item.setVersion(QueryBase.convertSafe(tuple, columns, DmpEntity._version, Integer.class));
item.setVersion(QueryBase.convertSafe(tuple, columns, DmpEntity._version, Short.class));
item.setStatus(QueryBase.convertSafe(tuple, columns, DmpEntity._status, DmpStatus.class));
item.setProperties(QueryBase.convertSafe(tuple, columns, DmpEntity._properties, String.class));
item.setDmpProperties(QueryBase.convertSafe(tuple, columns, DmpEntity._dmpProperties, String.class));
item.setGroupId(QueryBase.convertSafe(tuple, columns, DmpEntity._groupId, UUID.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, DmpEntity._description, String.class));
item.setIsPublic(QueryBase.convertSafe(tuple, columns, DmpEntity._isPublic, Boolean.class));
item.setExtraProperties(QueryBase.convertSafe(tuple, columns, DmpEntity._extraProperties, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, DmpEntity._isActive, IsActive.class));
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._finalizedAt, Instant.class));
item.setPublishedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._publishedAt, Instant.class));
item.setAccessType(QueryBase.convertSafe(tuple, columns, DmpEntity._accessType, DmpAccessType.class));
item.setBlueprint(QueryBase.convertSafe(tuple, columns, DmpEntity._blueprint, UUID.class));
item.setLanguage(QueryBase.convertSafe(tuple, columns, DmpEntity._language, String.class));
item.setPublicAfter(QueryBase.convertSafe(tuple, columns, DmpEntity._publicAfter, Instant.class));
return item;
}

View File

@ -93,21 +93,16 @@ public class DmpServiceImpl implements DmpService {
} else {
data = new DmpEntity();
data.setId(UUID.randomUUID());
data.setGroupId(UUID.randomUUID());
data.setVersion((short) 1);
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setLabel(model.getLabel());
data.setVersion(model.getVersion());
data.setStatus(model.getStatus());
data.setProperties(model.getProperties());
data.setDmpProperties(model.getDmpProperties());
data.setGroupId(model.getGroupId());
data.setDescription(model.getDescription());
data.setIsPublic(model.getIsPublic());
data.setExtraProperties(model.getExtraProperties());
data.setFinalizedAt(model.getFinalizedAt());
data.setPublishedAt(model.getPublishedAt());
data.setUpdatedAt(Instant.now());
if (isUpdate)
this.entityManager.merge(data);