From 074e374d9a0e5c326b05ce5b68b7952f2e2228be Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 4 Oct 2023 12:46:06 +0300 Subject: [PATCH] Removing old implementation of DescriptionTemplateType entity, fixing issues with entity scanning and field resolving on new implementation --- .../data/DescriptionTemplateTypeEntity.java | 16 ++-- .../eudat/model/DescriptionTemplateType.java | 9 +- .../eu/eudat/model/builder/BaseBuilder.java | 6 +- .../query/DescriptionTemplateTypeQuery.java | 19 ++-- .../lookup/DescriptionTemplateTypeLookup.java | 8 +- .../DescriptionTemplateTypeService.java | 14 ++- .../data/dao/entities/DatasetProfileDao.java | 4 +- .../dao/entities/DatasetProfileDaoImpl.java | 4 +- .../entities/DescriptionTemplateTypeDao.java | 10 -- .../DescriptionTemplateTypeDaoImpl.java | 65 ------------- .../data/entities/DescriptionTemplate.java | 7 +- .../entities/DescriptionTemplateType.java | 89 ------------------ .../main/java/eu/eudat/EuDatApplication.java | 2 + .../DevelDatabaseConfiguration.java | 7 +- .../main/java/eu/eudat/controllers/Admin.java | 9 +- .../DescriptionTemplateTypeController.java | 94 ------------------- .../DescriptionTemplateTypeManager.java | 84 ----------------- .../operations/DatabaseRepository.java | 2 - .../operations/DatabaseRepositoryImpl.java | 11 --- .../DescriptionTemplateTypeModel.java | 56 ----------- 20 files changed, 66 insertions(+), 450 deletions(-) delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDao.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDaoImpl.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplateType.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/logic/managers/DescriptionTemplateTypeManager.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/descriptiontemplatetype/DescriptionTemplateTypeModel.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateTypeEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateTypeEntity.java index be7a2477f..2abf17f9e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateTypeEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateTypeEntity.java @@ -1,31 +1,31 @@ package eu.eudat.data; +import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; -import jakarta.persistence.*; import java.util.UUID; @Entity -@Table(name = "DescriptionTemplateType") +@Table(name = "\"DescriptionTemplateType\"") public class DescriptionTemplateTypeEntity implements BaseEntity { @Id @GeneratedValue @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "ID", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; - public static final String _id = "ID"; + public static final String _id = "id"; - @Column(name = "Name", nullable = false) + @Column(name = "\"Name\"", nullable = false) private String name; - public static final String _name = "Name"; + public static final String _name = "name"; - @Column(name = "Status", nullable = false) + @Column(name = "\"Status\"", nullable = false) private Short status; - public static final String _status = "Status"; + public static final String _status = "status"; public UUID getId() { return id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DescriptionTemplateType.java b/dmp-backend/core/src/main/java/eu/eudat/model/DescriptionTemplateType.java index 1350eb689..c5fd4a351 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/DescriptionTemplateType.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DescriptionTemplateType.java @@ -1,14 +1,17 @@ package eu.eudat.model; +import com.fasterxml.jackson.annotation.JsonInclude; + import java.util.UUID; +@JsonInclude(JsonInclude.Include.NON_NULL) public class DescriptionTemplateType { private UUID id; private String name; - private short status; + private Short status; public UUID getId() { return id; @@ -26,11 +29,11 @@ public class DescriptionTemplateType { this.name = name; } - public short getStatus() { + public Short getStatus() { return status; } - public void setStatus(short status) { + public void setStatus(Short status) { this.status = status; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/BaseBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/BaseBuilder.java index 4d6b584ab..c91948d76 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/BaseBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/BaseBuilder.java @@ -3,7 +3,6 @@ package eu.eudat.model.builder; import eu.eudat.convention.ConventionService; import gr.cite.tools.data.builder.Builder; import gr.cite.tools.data.query.QueryBase; -import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; @@ -36,6 +35,11 @@ public abstract class BaseBuilder implements Builder { public abstract List build(FieldSet directives, List data); + /** + * Provides all the fields that can be projected on the entity listings associated with this builder + * + * @return The field set + */ public abstract FieldSet getFullFieldSet(); public Map asForeignKey(QueryBase query, FieldSet directives, Function keySelector) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateTypeQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateTypeQuery.java index 8476fb6b6..e1ad1cf80 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateTypeQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateTypeQuery.java @@ -1,6 +1,5 @@ package eu.eudat.query; -import eu.eudat.commons.enums.DescriptionTemplateTypeStatus; import eu.eudat.data.DescriptionTemplateTypeEntity; import eu.eudat.query.lookup.DescriptionTemplateTypeLookup; import eu.eudat.query.lookup.LookupAware; @@ -73,9 +72,12 @@ public class DescriptionTemplateTypeQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id)); - for (UUID item : this.ids) inClause.value(item); + for (UUID item : this.ids) + inClause.value(item); predicates.add(inClause); } if (this.names != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._name)); - for (String item : this.names) inClause.value(item); + for (String item : this.names) + inClause.value(item); predicates.add(inClause); } if (this.statuses != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._status)); - for (Short item : this.statuses) inClause.value(item); + for (Short item : this.statuses) + inClause.value(item); predicates.add(inClause); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateTypeLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateTypeLookup.java index 0c928c99e..2ba561a52 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateTypeLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateTypeLookup.java @@ -4,7 +4,9 @@ import gr.cite.tools.data.query.Lookup; public class DescriptionTemplateTypeLookup extends Lookup { - private String name, status; + private String name; + + private Short status; public String getName() { return name; @@ -14,11 +16,11 @@ public class DescriptionTemplateTypeLookup extends Lookup { this.name = name; } - public String getStatus() { + public Short getStatus() { return status; } - public void setStatus(String status) { + public void setStatus(Short status) { this.status = status; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeService.java b/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeService.java index 3f8ebef88..13e7edd61 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeService.java @@ -7,6 +7,8 @@ import eu.eudat.model.builder.DescriptionTemplateTypeBuilder; import eu.eudat.query.DescriptionTemplateTypeQuery; import eu.eudat.query.lookup.DescriptionTemplateTypeLookup; import gr.cite.tools.data.builder.BuilderFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import org.springframework.transaction.PlatformTransactionManager; @@ -14,8 +16,6 @@ import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import java.util.List; import java.util.UUID; @@ -51,6 +51,11 @@ public class DescriptionTemplateTypeService { .build(null, query.ids(id).first()); } + public DescriptionTemplateTypeEntity getEntityByName(String name) { + DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class); + return query.names(name).first(); + } + public DescriptionTemplateType create(DescriptionTemplateType payload) { DescriptionTemplateTypeEntity created = new DescriptionTemplateTypeEntity(); created.setId(UUID.randomUUID()); @@ -89,9 +94,10 @@ public class DescriptionTemplateTypeService { return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(null, entity); } - public boolean delete (UUID id) { + public boolean delete(UUID id) { DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, id); - if (entity == null) return false; + if (entity == null) + return false; entity.setStatus(DescriptionTemplateTypeStatus.DELETED.getValue()); entityManager.merge(entity); entityManager.flush(); diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDao.java index 35f508436..10b4e85a7 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDao.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDao.java @@ -1,9 +1,9 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DescriptionTemplateTypeEntity; import eu.eudat.data.dao.DatabaseAccessLayer; import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.entities.DescriptionTemplate; -import eu.eudat.data.entities.DescriptionTemplateType; import eu.eudat.queryable.QueryableList; import java.util.List; @@ -19,6 +19,6 @@ public interface DatasetProfileDao extends DatabaseAccessLayer getAllIds(); - Long countWithType(DescriptionTemplateType type); + Long countWithType(DescriptionTemplateTypeEntity type); } \ No newline at end of file diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDaoImpl.java index d0d77b877..03a942969 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetProfileDaoImpl.java @@ -1,10 +1,10 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DescriptionTemplateTypeEntity; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; import eu.eudat.data.entities.DescriptionTemplate; -import eu.eudat.data.entities.DescriptionTemplateType; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; import eu.eudat.queryable.types.SelectionField; @@ -128,7 +128,7 @@ public class DatasetProfileDaoImpl extends DatabaseAccess i } @Override - public Long countWithType(DescriptionTemplateType type) { + public Long countWithType(DescriptionTemplateTypeEntity type) { return this.getDatabaseService().getQueryable(DescriptionTemplate.class).where((builder, root) -> builder.equal(root.get("type"), type)).count(); } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDao.java deleted file mode 100644 index 764bf32e0..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package eu.eudat.data.dao.entities; - -import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.entities.DescriptionTemplateType; - -import java.util.UUID; - -public interface DescriptionTemplateTypeDao extends DatabaseAccessLayer { - DescriptionTemplateType findFromName(String name); -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDaoImpl.java deleted file mode 100644 index 518332c01..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DescriptionTemplateTypeDaoImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package eu.eudat.data.dao.entities; - -import eu.eudat.data.dao.DatabaseAccess; -import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.entities.DescriptionTemplateType; -import eu.eudat.queryable.QueryableList; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -import jakarta.transaction.Transactional; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -@Component("descriptionTemplateTypeDao") -public class DescriptionTemplateTypeDaoImpl extends DatabaseAccess implements DescriptionTemplateTypeDao { - - @Autowired - public DescriptionTemplateTypeDaoImpl(DatabaseService databaseService) { - super(databaseService); - } - - @Override - public DescriptionTemplateType findFromName(String name){ - try { - return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.equal(root.get("name"), name)).getSingle(); - } - catch(Exception e){ - return null; - } - } - - @Override - @Transactional - public DescriptionTemplateType createOrUpdate(DescriptionTemplateType item) { - return this.getDatabaseService().createOrUpdate(item, DescriptionTemplateType.class); - } - - @Override - public DescriptionTemplateType find(UUID id) { - return getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle(); - } - - @Override - public void delete(DescriptionTemplateType item) { - this.getDatabaseService().delete(item); - } - - @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.notEqual((root.get("status")), DescriptionTemplateType.Status.DELETED.getValue())); - } - - @Async - @Override - public CompletableFuture createOrUpdateAsync(DescriptionTemplateType item) { - return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); - } - - @Override - public DescriptionTemplateType find(UUID id, String hint) { - throw new UnsupportedOperationException(); - } - -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplate.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplate.java index 993fc155c..d08729b6c 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplate.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplate.java @@ -1,6 +1,7 @@ package eu.eudat.data.entities; +import eu.eudat.data.DescriptionTemplateTypeEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.queryable.queryableentity.DataEntity; import org.hibernate.annotations.GenericGenerator; @@ -87,7 +88,7 @@ public class DescriptionTemplate implements DataEntity @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "\"Type\"", nullable = false) - private DescriptionTemplateType type; + private DescriptionTemplateTypeEntity type; @OneToMany(mappedBy = "descriptionTemplate", fetch = FetchType.LAZY) private Set users; @@ -162,10 +163,10 @@ public class DescriptionTemplate implements DataEntity this.language = language; } - public DescriptionTemplateType getType() { + public DescriptionTemplateTypeEntity getType() { return type; } - public void setType(DescriptionTemplateType type) { + public void setType(DescriptionTemplateTypeEntity type) { this.type = type; } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplateType.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplateType.java deleted file mode 100644 index 9b466f862..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DescriptionTemplateType.java +++ /dev/null @@ -1,89 +0,0 @@ -package eu.eudat.data.entities; - -import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; - -import jakarta.persistence.*; -import java.util.List; -import java.util.UUID; - -@Entity -@Table(name = "\"DescriptionTemplateType\"") -public class DescriptionTemplateType implements DataEntity { - - public enum Status { - SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99); - - private short value; - - private Status(short value) { - this.value = value; - } - public short getValue() { - return value; - } - - public static Status fromInteger(int value) { - switch (value) { - case 0: - return SAVED; - case 1: - return FINALIZED; - case 99: - return DELETED; - default: - throw new RuntimeException("Unsupported Description Template Type Status"); - } - } - } - - @Id - @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @Column(name = "\"Name\"", nullable = false) - private String name; - - @Column(name = "\"Status\"", nullable = false) - private Short status; - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public Short getStatus() { - return status; - } - public void setStatus(Short status) { - this.status = status; - } - - @Override - public void update(DescriptionTemplateType entity) { - this.name = entity.name; - this.status = entity.status; - } - - @Override - public UUID getKeys() { - return this.id; - } - - @Override - public DescriptionTemplateType buildFromTuple(List tuple, List fields, String base) { - this.id = UUID.fromString((String) tuple.get(0).get(!base.isEmpty() ? base + "." + "id" : "id")); - return this; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java b/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java index dc5a0de13..1a84e7127 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java +++ b/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java @@ -1,7 +1,9 @@ package eu.eudat; +import eu.eudat.data.BaseEntity; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.scheduling.annotation.EnableAsync; diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java index 8e58dc5a6..7038aaf5f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java @@ -1,13 +1,11 @@ package eu.eudat.configurations; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -16,13 +14,14 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import jakarta.persistence.EntityManagerFactory; + import javax.sql.DataSource; import java.util.Properties; @Configuration @EnableTransactionManagement @Profile("devel") -@ComponentScan(basePackages = {"eu.eudat.data.entities"}) +@ComponentScan(basePackages = {"eu.eudat.data"}) public class DevelDatabaseConfiguration { @Autowired @@ -32,7 +31,7 @@ public class DevelDatabaseConfiguration { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[]{"eu.eudat.data.entities"}); + em.setPackagesToScan("eu.eudat.data"); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); em.setJpaProperties(additionalProperties()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index 469b9aaa3..27273c3eb 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -19,6 +19,7 @@ import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.user.composite.PagedDatasetProfile; +import eu.eudat.service.DescriptionTemplateTypeService; import eu.eudat.types.ApiMessageCode; import eu.eudat.types.MetricNames; import org.springframework.beans.factory.annotation.Autowired; @@ -46,13 +47,16 @@ public class Admin extends BaseController { private ConfigLoader configLoader; private final MetricsManager metricsManager; + private final DescriptionTemplateTypeService descriptionTemplateTypeService; + @Autowired - public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader, MetricsManager metricsManager) { + public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader, MetricsManager metricsManager, DescriptionTemplateTypeService descriptionTemplateTypeService) { super(apiContext); this.datasetProfileManager = datasetProfileManager; this.userManager = userManager; this.configLoader = configLoader; this.metricsManager = metricsManager; + this.descriptionTemplateTypeService = descriptionTemplateTypeService; } @Transactional @@ -61,7 +65,8 @@ public class Admin extends BaseController { //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); DatasetProfile shortenProfile = profile.toShort(); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); - modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType())); +// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType())); + modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType())); modelDefinition.setGroupId(UUID.randomUUID()); modelDefinition.setVersion((short) 0); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java deleted file mode 100644 index 456a9caaa..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java +++ /dev/null @@ -1,94 +0,0 @@ -package eu.eudat.controllers; - -import eu.eudat.exceptions.descriptiontemplate.DescriptionTemplatesWithTypeException; -import eu.eudat.logic.managers.DescriptionTemplateTypeManager; -import eu.eudat.logic.security.claims.ClaimedAuthorities; -import eu.eudat.logic.services.ApiContext; -import eu.eudat.models.data.descriptiontemplatetype.DescriptionTemplateTypeModel; -import eu.eudat.models.data.helpers.common.DataTableData; -import eu.eudat.models.data.helpers.responses.ResponseItem; -import eu.eudat.models.data.security.Principal; -import eu.eudat.types.ApiMessageCode; -import eu.eudat.types.Authorities; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import jakarta.transaction.Transactional; -import java.util.UUID; - -import static eu.eudat.types.Authorities.ADMIN; - -@RestController -@CrossOrigin -@RequestMapping(value = {"/api/descriptionTemplateType/"}) -public class DescriptionTemplateTypeController extends BaseController { - - private DescriptionTemplateTypeManager descriptionTemplateTypeManager; - - @Autowired - public DescriptionTemplateTypeController(ApiContext apiContext, DescriptionTemplateTypeManager descriptionTemplateTypeManager){ - super(apiContext); - this.descriptionTemplateTypeManager = descriptionTemplateTypeManager; - } - - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"create"}, produces = "application/json") - public @ResponseBody - ResponseEntity> create(@RequestBody DescriptionTemplateTypeModel type, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { - try { - this.descriptionTemplateTypeManager.create(type); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); - } - catch(DescriptionTemplatesWithTypeException e){ - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage())); - } - } - - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"update"}, produces = "application/json") - public @ResponseBody - ResponseEntity> update(@RequestBody DescriptionTemplateTypeModel type, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { - try { - this.descriptionTemplateTypeManager.update(type); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated")); - } - catch(DescriptionTemplatesWithTypeException e){ - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage())); - } - } - - @RequestMapping(method = RequestMethod.GET, value = {"get"}, produces = "application/json") - public @ResponseBody - ResponseEntity>> get(@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { - DataTableData dataTable = this.descriptionTemplateTypeManager.get(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); - } - - @RequestMapping(method = RequestMethod.GET, value = {"get/{id}"}, produces = "application/json") - public @ResponseBody - ResponseEntity> getSingle(@PathVariable(value = "id") UUID id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { - try { - DescriptionTemplateTypeModel typeModel = this.descriptionTemplateTypeManager.getSingle(id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(typeModel)); - } - catch(DescriptionTemplatesWithTypeException e){ - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage())); - } - } - - @Transactional - @RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json") - public @ResponseBody - ResponseEntity> delete(@PathVariable(value = "id") UUID id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { - try{ - this.descriptionTemplateTypeManager.delete(id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted")); - } - catch(DescriptionTemplatesWithTypeException e){ - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.UNSUCCESS_DELETE).message(e.getMessage())); - } - } - -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DescriptionTemplateTypeManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DescriptionTemplateTypeManager.java deleted file mode 100644 index 1dda78fdb..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DescriptionTemplateTypeManager.java +++ /dev/null @@ -1,84 +0,0 @@ -package eu.eudat.logic.managers; - -import eu.eudat.data.entities.DescriptionTemplateType; -import eu.eudat.exceptions.descriptiontemplate.DescriptionTemplatesWithTypeException; -import eu.eudat.logic.services.ApiContext; -import eu.eudat.logic.services.operations.DatabaseRepository; -import eu.eudat.models.data.descriptiontemplatetype.DescriptionTemplateTypeModel; -import eu.eudat.models.data.helpers.common.DataTableData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -@Component -public class DescriptionTemplateTypeManager { - private static final Logger logger = LoggerFactory.getLogger(DescriptionTemplateTypeManager.class); - - private ApiContext apiContext; - private DatabaseRepository databaseRepository; - - - @Autowired - public DescriptionTemplateTypeManager(ApiContext apiContext, DatabaseRepository databaseRepository) { - this.apiContext = apiContext; - this.databaseRepository = databaseRepository; - } - - public DataTableData get() { - List types = this.databaseRepository.getDescriptionTemplateTypeDao().asQueryable().toList(); - List typesModelList = types.stream().map(type -> new DescriptionTemplateTypeModel().fromDataModel(type)).collect(Collectors.toList()); - DataTableData dataTableData = new DataTableData<>(); - dataTableData.setData(typesModelList); - dataTableData.setTotalCount((long) typesModelList.size()); - return dataTableData; - } - - public DescriptionTemplateTypeModel getSingle(UUID id) throws Exception { - DescriptionTemplateType type = this.databaseRepository.getDescriptionTemplateTypeDao().find(id); - if (type != null) { - return new DescriptionTemplateTypeModel().fromDataModel(type); - } - else { - throw new DescriptionTemplatesWithTypeException("No description template type found with this id"); - } - } - - public void create(DescriptionTemplateTypeModel type) throws Exception { - DescriptionTemplateType existed = this.databaseRepository.getDescriptionTemplateTypeDao().findFromName(type.getName()); - if (existed == null) { - this.databaseRepository.getDescriptionTemplateTypeDao().createOrUpdate(type.toDataModel()); - } - else { - throw new DescriptionTemplatesWithTypeException("There is already a description template type with that name."); - } - } - - public void update(DescriptionTemplateTypeModel type) throws Exception { - DescriptionTemplateType existed = this.databaseRepository.getDescriptionTemplateTypeDao().findFromName(type.getName()); - if (existed != null) { - this.databaseRepository.getDescriptionTemplateTypeDao().createOrUpdate(type.toDataModel()); - } - else { - throw new DescriptionTemplatesWithTypeException("No description template type found."); - } - } - - public void delete(UUID id) throws DescriptionTemplatesWithTypeException { - DescriptionTemplateType type = this.databaseRepository.getDescriptionTemplateTypeDao().find(id); - if (type != null) { - Long descriptionsWithType = this.databaseRepository.getDatasetProfileDao().countWithType(type); - if(descriptionsWithType == 0) { - type.setStatus(DescriptionTemplateType.Status.DELETED.getValue()); - this.databaseRepository.getDescriptionTemplateTypeDao().createOrUpdate(type); - } - else{ - throw new DescriptionTemplatesWithTypeException("This type can not deleted, because Descriptions are associated with it"); - } - } - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java index 1d5e10df8..119ebfee2 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java @@ -64,7 +64,5 @@ public interface DatabaseRepository { EntityDoiDao getEntityDoiDao(); - DescriptionTemplateTypeDao getDescriptionTemplateTypeDao(); - void detachEntity(T entity); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java index ca713d432..da57d1864 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java @@ -41,7 +41,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { private NotificationDao notificationDao; private FileUploadDao fileUploadDao; private EntityDoiDao entityDoiDao; - private DescriptionTemplateTypeDao descriptionTemplateTypeDao; private EntityManager entityManager; @@ -340,16 +339,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { this.entityDoiDao = entityDoiDao; } - @Override - public DescriptionTemplateTypeDao getDescriptionTemplateTypeDao() { - return descriptionTemplateTypeDao; - } - - @Autowired - public void setDescriptionTemplateTypeDao(DescriptionTemplateTypeDao descriptionTemplateTypeDao) { - this.descriptionTemplateTypeDao = descriptionTemplateTypeDao; - } - public void detachEntity(T entity) { this.entityManager.detach(entity); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/descriptiontemplatetype/DescriptionTemplateTypeModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/descriptiontemplatetype/DescriptionTemplateTypeModel.java deleted file mode 100644 index 272d405e1..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/descriptiontemplatetype/DescriptionTemplateTypeModel.java +++ /dev/null @@ -1,56 +0,0 @@ -package eu.eudat.models.data.descriptiontemplatetype; - -import eu.eudat.data.entities.DescriptionTemplateType; -import eu.eudat.models.DataModel; - -import java.util.UUID; - -public class DescriptionTemplateTypeModel implements DataModel { - - private UUID id; - private String name; - private short status; - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public short getStatus() { - return status; - } - public void setStatus(short status) { - this.status = status; - } - - @Override - public DescriptionTemplateTypeModel fromDataModel(DescriptionTemplateType entity) { - this.id = entity.getId(); - this.name = entity.getName(); - this.status = entity.getStatus(); - return this; - } - - @Override - public DescriptionTemplateType toDataModel() throws Exception { - DescriptionTemplateType descriptionTemplateType = new DescriptionTemplateType(); - descriptionTemplateType.setId(this.id); - descriptionTemplateType.setName(this.name); - descriptionTemplateType.setStatus(this.status); - return descriptionTemplateType; - } - - @Override - public String getHint() { - return null; - } -}