Adding converter for Instants to Dates
This commit is contained in:
parent
3a033a655b
commit
caf7ec09c4
|
@ -5,6 +5,7 @@ import eu.eudat.commons.enums.DmpStatus;
|
|||
import eu.eudat.commons.enums.DmpVersionStatus;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.data.converters.DateToUTCConverter;
|
||||
import eu.eudat.data.converters.InstantToUTCConverter;
|
||||
import eu.eudat.data.converters.enums.DmpAccessTypeConverter;
|
||||
import eu.eudat.data.converters.enums.DmpStatusConverter;
|
||||
import eu.eudat.data.converters.enums.IsActiveConverter;
|
||||
|
@ -63,13 +64,13 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
|
|||
public static final String _description = "description";
|
||||
|
||||
@Column(name = "created_at")
|
||||
@Convert(converter = DateToUTCConverter.class)
|
||||
@Convert(converter = InstantToUTCConverter.class)
|
||||
private Instant createdAt;
|
||||
|
||||
public static final String _createdAt = "createdAt";
|
||||
|
||||
@Column(name = "updated_at")
|
||||
@Convert(converter = DateToUTCConverter.class)
|
||||
@Convert(converter = InstantToUTCConverter.class)
|
||||
private Instant updatedAt;
|
||||
|
||||
public static final String _updatedAt = "updatedAt";
|
||||
|
@ -81,6 +82,7 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
|
|||
public static final String _isActive = "isActive";
|
||||
|
||||
@Column(name = "finalized_at")
|
||||
@Convert(converter = InstantToUTCConverter.class)
|
||||
private Instant finalizedAt;
|
||||
|
||||
public static final String _finalizedAt = "finalizedAt";
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package eu.eudat.data.converters;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
|
||||
@Converter
|
||||
public class InstantToUTCConverter implements AttributeConverter<Instant, Date> {
|
||||
|
||||
@Override
|
||||
public Date convertToDatabaseColumn(Instant attribute) {
|
||||
if(attribute == null) return null;
|
||||
return Date.from(attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant convertToEntityAttribute(Date dbData) {
|
||||
if (dbData == null) return null;
|
||||
return dbData.toInstant();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue