Added dmp description template deletions on description template deleter

This commit is contained in:
Thomas Georgios Giannos 2023-11-07 14:32:37 +02:00
parent cfb7da7968
commit 001cd0828b
1 changed files with 13 additions and 5 deletions

View File

@ -2,9 +2,11 @@ package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.UserDescriptionTemplateEntity;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.eudat.query.UserDescriptionTemplateQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
@ -63,24 +65,30 @@ public class DescriptionTemplateDeleter implements Deleter {
logger.trace("changes saved");
}
public void delete(List<DescriptionTemplateEntity> datas) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0));
if (datas == null || datas.isEmpty())
public void delete(List<DescriptionTemplateEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
List<UUID> ids = datas.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList());
List<UUID> ids = data.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList());
{
logger.debug("checking related - {}", UserDescriptionTemplateEntity.class.getSimpleName());
List<UserDescriptionTemplateEntity> items = this.queryFactory.query(UserDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect();
UserDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(UserDescriptionTemplateDeleter.class);
deleter.delete(items);
}
{
logger.debug("checking related - {}", DmpDescriptionTemplateEntity.class.getSimpleName());
List<DmpDescriptionTemplateEntity> items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect();
DmpDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class);
deleter.delete(items);
}
//TODO can not delete profile if has Datasets
Instant now = Instant.now();
for (DescriptionTemplateEntity item : datas) {
for (DescriptionTemplateEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);