Update some of the queries in the new Deposit mapper

This commit is contained in:
George Kalampokis 2023-11-06 17:43:20 +02:00
parent 49e34f9abc
commit 9e27558df7
1 changed files with 12 additions and 15 deletions

View File

@ -4,16 +4,17 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.*;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.depositinterface.models.*;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DescriptionTemplateQuery;
import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -30,11 +31,13 @@ public class DmpEntityDepositMapper {
private static final Logger logger = LoggerFactory.getLogger(DmpEntityDepositMapper.class);
private final ObjectMapper mapper;
private final ApplicationContext applicationContext;
private final EntityManager entityManager;
public DmpEntityDepositMapper(EntityManager entityManager) {
public DmpEntityDepositMapper(ApplicationContext applicationContext, EntityManager entityManager) {
this.applicationContext = applicationContext;
this.entityManager = entityManager;
this.mapper = new ObjectMapper();
}
@ -59,11 +62,8 @@ public class DmpEntityDepositMapper {
}
private List<DescriptionEntity> getDescriptions(UUID dmpId) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<DescriptionEntity> query = builder.createQuery(DescriptionEntity.class);
Root<DescriptionEntity> root = query.from(DescriptionEntity.class);
query = query.where(builder.and(builder.equal(root.get("dmp"), dmpId), builder.equal(root.get("isActive"), IsActive.Active)));
return entityManager.createQuery(query).getResultList();
DescriptionQuery descriptionQuery = this.applicationContext.getBean(DescriptionQuery.class);
return descriptionQuery.dmpIds(dmpId).isActive(IsActive.Active).collect();
}
@ -79,11 +79,8 @@ public class DmpEntityDepositMapper {
}
private DescriptionTemplateEntity getDescriptionTemplate(UUID descId) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<DescriptionTemplateEntity> query = builder.createQuery(DescriptionTemplateEntity.class);
Root<DescriptionTemplateEntity> root = query.from(DescriptionTemplateEntity.class);
query = query.where(builder.and(builder.equal(root.get("id"), descId), builder.equal(root.get("isActive"), IsActive.Active)));
return entityManager.createQuery(query).getSingleResult();
DescriptionTemplateQuery descriptionTemplateQuery = this.applicationContext.getBean(DescriptionTemplateQuery.class);
return descriptionTemplateQuery.ids(descId).isActive(IsActive.Active).first();
}
private List<DatasetFieldsDepositModel> fromDefinitionAndProperties(String definition, String properties){