Fix on dmp references persisting flow

This commit is contained in:
Thomas Georgios Giannos 2023-11-03 16:47:54 +02:00
parent 2f20675348
commit b389ebf160
3 changed files with 32 additions and 5 deletions

View File

@ -1,9 +1,8 @@
package eu.eudat.data; package eu.eudat.data;
import jakarta.persistence.Column; import eu.eudat.commons.enums.IsActive;
import jakarta.persistence.Entity; import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.Id; import jakarta.persistence.*;
import jakarta.persistence.Table;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@ -27,6 +26,7 @@ public class DmpReferenceEntity {
@Column(name = "data") @Column(name = "data")
private String data; private String data;
public static final String _data = "data";
@Column(name = "created_at", nullable = false) @Column(name = "created_at", nullable = false)
private Instant createdAt; private Instant createdAt;
@ -36,7 +36,10 @@ public class DmpReferenceEntity {
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
public static final String _data = "data"; @Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
public UUID getId() { public UUID getId() {
return id; return id;
@ -85,4 +88,12 @@ public class DmpReferenceEntity {
public void setUpdatedAt(Instant updatedAt) { public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.model.deleter; package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.query.DmpReferenceQuery; import eu.eudat.query.DmpReferenceQuery;
import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.Deleter;
@ -15,6 +16,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -64,6 +66,8 @@ public class DmpReferenceDeleter implements Deleter {
for (DmpReferenceEntity item : data) { for (DmpReferenceEntity item : data) {
logger.trace("deleting item {}", item.getId()); logger.trace("deleting item {}", item.getId());
logger.trace("updating item"); logger.trace("updating item");
item.setUpdatedAt(Instant.now());
item.setIsActive(IsActive.Inactive);
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
} }

View File

@ -19,6 +19,7 @@ import eu.eudat.model.Dmp;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.deleter.DmpDeleter; import eu.eudat.model.deleter.DmpDeleter;
import eu.eudat.model.deleter.DmpReferenceDeleter;
import eu.eudat.model.deleter.ReferenceDeleter; import eu.eudat.model.deleter.ReferenceDeleter;
import eu.eudat.model.persist.DmpPersist; import eu.eudat.model.persist.DmpPersist;
import eu.eudat.model.persist.ReferencePersist; import eu.eudat.model.persist.ReferencePersist;
@ -215,6 +216,8 @@ public class DmpServiceImpl implements DmpService {
List<UUID> updatedReferencesIds = models.stream().map(ReferencePersist::getId).filter(this.conventionService::isValidGuid).distinct().toList(); List<UUID> updatedReferencesIds = models.stream().map(ReferencePersist::getId).filter(this.conventionService::isValidGuid).distinct().toList();
List<ReferenceEntity> toDelete = existingReferences.stream().filter(x -> !updatedReferencesIds.contains(x.getId())).toList(); List<ReferenceEntity> toDelete = existingReferences.stream().filter(x -> !updatedReferencesIds.contains(x.getId())).toList();
List<DmpReferenceEntity> dmpReferenceRecordsToDelete = this.queryFactory.query(DmpReferenceQuery.class).referenceIds(toDelete.stream().map(ReferenceEntity::getId).toList()).collect();
this.deleterFactory.deleter(DmpReferenceDeleter.class).delete(dmpReferenceRecordsToDelete);
this.deleterFactory.deleter(ReferenceDeleter.class).delete(toDelete); this.deleterFactory.deleter(ReferenceDeleter.class).delete(toDelete);
Map<UUID, ReferenceEntity> existingReferencesLookup = existingReferences.stream().collect(Collectors.toMap(ReferenceEntity::getId, x -> x)); Map<UUID, ReferenceEntity> existingReferencesLookup = existingReferences.stream().collect(Collectors.toMap(ReferenceEntity::getId, x -> x));
@ -236,6 +239,15 @@ public class DmpServiceImpl implements DmpService {
data.setId(UUID.randomUUID()); data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now()); data.setCreatedAt(Instant.now());
DmpReferenceEntity dmpReference = new DmpReferenceEntity();
dmpReference.setReferenceId(data.getId());
dmpReference.setDmpId(dmpId);
dmpReference.setCreatedAt(Instant.now());
dmpReference.setUpdatedAt(Instant.now());
dmpReference.setIsActive(IsActive.Active);
//TODO: Add data persistence here
this.entityManager.persist(dmpReference);
} }
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition()))); data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition())));