diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml
index e6c6fac3a..59540a4b8 100644
--- a/dmp-backend/core/pom.xml
+++ b/dmp-backend/core/pom.xml
@@ -21,6 +21,15 @@
1.0-SNAPSHOT
compile
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ gr.cite
+ validation
+ 2.1.0
+
diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java
index 2ff1dfb63..1dc08d4ce 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java
@@ -5,9 +5,8 @@ import gr.cite.tools.logging.EventId;
public class AuditableAction {
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
-
- public static final EventId DescriptionTemplateType_Persist = new EventId(1001, "DescriptionTemplateType_Persist");
-
- public static final EventId DescriptionTemplateType_Delete = new EventId(1002, "DescriptionTemplateType_Delete");
+ public static final EventId DescriptionTemplateType_Lookup = new EventId(1001, "DescriptionTemplateType_Lookup");
+ public static final EventId DescriptionTemplateType_Persist = new EventId(1002, "DescriptionTemplateType_Persist");
+ public static final EventId DescriptionTemplateType_Delete = new EventId(1003, "DescriptionTemplateType_Delete");
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/JsonHandlingService.java b/dmp-backend/core/src/main/java/eu/eudat/commons/JsonHandlingService.java
new file mode 100644
index 000000000..5061839cb
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/JsonHandlingService.java
@@ -0,0 +1,47 @@
+package eu.eudat.commons;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
+public class JsonHandlingService {
+ private final ObjectMapper objectMapper;
+
+ public JsonHandlingService() {
+ this.objectMapper = new ObjectMapper();
+ objectMapper.registerModule(new JavaTimeModule());
+ }
+
+ public String toJson(Object item) throws JsonProcessingException {
+ if (item == null) return null;
+ return objectMapper.writeValueAsString(item);
+ }
+
+ public String toJsonSafe(Object item) {
+ if (item == null) return null;
+ try {
+ return objectMapper.writeValueAsString(item);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public T fromJson(Class type, String json) throws JsonProcessingException {
+ if (json == null) return null;
+ return objectMapper.readValue(json, type);
+ }
+
+ public T fromJsonSafe(Class type, String json) {
+ if (json == null) return null;
+ try {
+ return objectMapper.readValue(json, type);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/EnumNotNull.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/EnumNotNull.java
new file mode 100644
index 000000000..ffa2553b5
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/EnumNotNull.java
@@ -0,0 +1,11 @@
+package eu.eudat.commons.validation;
+
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+
+public class EnumNotNull implements ConstraintValidator {
+ @Override
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ return value != null;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSet.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSet.java
new file mode 100644
index 000000000..2b3893879
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSet.java
@@ -0,0 +1,22 @@
+package eu.eudat.commons.validation;
+
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+import java.lang.annotation.*;
+
+@Constraint( validatedBy = { FieldNotNullIfOtherSetValidator.class } )
+@Documented
+@Target( { ElementType.TYPE } )
+@Retention( RetentionPolicy.RUNTIME )
+public @interface FieldNotNullIfOtherSet {
+ Class>[] groups() default {};
+
+ String notNullField() default "id";
+ String otherSetField() default "hash";
+ String failOn() default "hash";
+
+ String message() default "hash is required if id is set";
+
+ Class extends Payload>[] payload() default {};
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSetValidator.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSetValidator.java
new file mode 100644
index 000000000..1b55849f5
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldNotNullIfOtherSetValidator.java
@@ -0,0 +1,35 @@
+package eu.eudat.commons.validation;
+
+import org.springframework.beans.BeanWrapperImpl;
+
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+import java.util.Objects;
+
+public class FieldNotNullIfOtherSetValidator implements ConstraintValidator {
+
+ private String notNullField;
+ private String otherSetField;
+
+ @Override
+ public void initialize(FieldNotNullIfOtherSet constraintAnnotation) {
+ this.notNullField = constraintAnnotation.notNullField();
+ this.otherSetField = constraintAnnotation.otherSetField();
+ }
+
+ @Override
+ public boolean isValid(Object entity, ConstraintValidatorContext context) {
+ Object notNullValue = new BeanWrapperImpl(entity)
+ .getPropertyValue(this.notNullField);
+ Object otherSetValue = new BeanWrapperImpl(entity)
+ .getPropertyValue(this.otherSetField);
+
+ boolean hashIsString = Objects.equals(new BeanWrapperImpl(entity)
+ .getPropertyType(this.otherSetField), String.class);
+
+ boolean hashValueEmpty = otherSetValue == null || (hashIsString && ((String)otherSetValue).isBlank());
+
+ if (notNullValue != null && hashValueEmpty) return false;
+ return true;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatch.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatch.java
new file mode 100644
index 000000000..d08df40d0
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatch.java
@@ -0,0 +1,29 @@
+package eu.eudat.commons.validation;
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Constraint(validatedBy = FieldsValueMatchValidator.class)
+@Target({ ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface FieldsValueMatch {
+ Class>[] groups() default {};
+
+ String field();
+ String fieldMatch();
+ String failOn();
+
+ String message() default "Fields values don't match!";
+
+ Class extends Payload>[] payload() default {};
+
+ @Target({ ElementType.TYPE })
+ @Retention(RetentionPolicy.RUNTIME)
+ @interface List {
+ FieldsValueMatch[] value();
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatchValidator.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatchValidator.java
new file mode 100644
index 000000000..1f4691378
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/FieldsValueMatchValidator.java
@@ -0,0 +1,31 @@
+package eu.eudat.commons.validation;
+
+import org.springframework.beans.BeanWrapperImpl;
+
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+
+public class FieldsValueMatchValidator implements ConstraintValidator {
+
+ private String field;
+ private String fieldMatch;
+
+ @Override
+ public void initialize(FieldsValueMatch constraintAnnotation) {
+ this.field = constraintAnnotation.field();
+ this.fieldMatch = constraintAnnotation.fieldMatch();
+ }
+
+ @Override
+ public boolean isValid(Object entity, ConstraintValidatorContext context) {
+
+ Object fieldValue = new BeanWrapperImpl(entity).getPropertyValue(field);
+ Object fieldMatchValue = new BeanWrapperImpl(entity).getPropertyValue(fieldMatch);
+
+ if (fieldValue != null) {
+ return fieldValue.equals(fieldMatchValue);
+ } else {
+ return fieldMatchValue == null;
+ }
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidEnum.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidEnum.java
new file mode 100644
index 000000000..079f9e64a
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidEnum.java
@@ -0,0 +1,16 @@
+package eu.eudat.commons.validation;
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+import java.lang.annotation.*;
+
+
+@Constraint(validatedBy = EnumNotNull.class)
+@Documented
+@Target({ ElementType.FIELD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ValidEnum {
+ String message() default "enum is required";
+ Class>[] groups() default {};
+ Class extends Payload>[] payload() default {};
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidId.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidId.java
new file mode 100644
index 000000000..2f470b57b
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidId.java
@@ -0,0 +1,18 @@
+package eu.eudat.commons.validation;
+
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+import java.lang.annotation.*;
+
+@Constraint( validatedBy = { ValidIdValidator.class } )
+@Documented
+@Target( { ElementType.FIELD } )
+@Retention( RetentionPolicy.RUNTIME )
+public @interface ValidId {
+ Class>[] groups() default {};
+
+ String message() default "id set but not valid";
+
+ Class extends Payload>[] payload() default {};
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidIdValidator.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidIdValidator.java
new file mode 100644
index 000000000..7fce85251
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidIdValidator.java
@@ -0,0 +1,40 @@
+package eu.eudat.commons.validation;
+
+import eu.eudat.convention.ConventionService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+import java.util.UUID;
+
+public class ValidIdValidator implements ConstraintValidator {
+
+ @Autowired
+ private ConventionService conventionService;
+
+ @Override
+ public void initialize(ValidId constraintAnnotation) { }
+
+ @Override
+ public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
+ if(o == null) return true;
+ else if(o instanceof UUID){
+ UUID uuidId = (UUID)o;
+ return this.conventionService.isValidGuid(uuidId);
+ }
+ else if(o instanceof Integer){
+ Integer intId = (Integer)o;
+ return this.conventionService.isValidId(intId);
+ }
+ else{
+ String stringId = o.toString();
+ UUID uuidId = null;
+ try {
+ uuidId = UUID.fromString(stringId);
+ }catch (Exception ex){
+ return false;
+ }
+ return this.conventionService.isValidGuid(uuidId);
+ }
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidationServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidationServiceImpl.java
index e8c17c407..33cfa570c 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidationServiceImpl.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/ValidationServiceImpl.java
@@ -3,23 +3,20 @@ package eu.eudat.commons.validation;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.validation.BaseValidationService;
-import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
+import jakarta.validation.Validator;
import java.util.List;
import java.util.Map;
@Service
-@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ValidationServiceImpl extends BaseValidationService {
- private ErrorThesaurusProperties errors;
+ private final ErrorThesaurusProperties errors;
@Autowired
- public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors){
+ public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors) {
super(validator);
this.errors = errors;
}
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 2abf17f9e..bbf0a84e7 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,38 @@
package eu.eudat.data;
+import eu.eudat.commons.enums.Status;
import jakarta.persistence.*;
import org.hibernate.annotations.GenericGenerator;
+import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"DescriptionTemplateType\"")
-public class DescriptionTemplateTypeEntity implements BaseEntity {
+public class DescriptionTemplateTypeEntity {
@Id
- @GeneratedValue
- @GenericGenerator(name = "uuid2", strategy = "uuid2")
- @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
+ @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
+ public final static String _id = "id";
- public static final String _id = "id";
-
- @Column(name = "\"Name\"", nullable = false)
+ @Column(name = "name", length = 500, nullable = false)
private String name;
+ public final static String _name = "name";
- public static final String _name = "name";
+ @Column(name = "created_at", nullable = false)
+ private Instant createdAt;
+ public final static String _createdAt = "createdAt";
- @Column(name = "\"Status\"", nullable = false)
- private Short status;
+ @Column(name = "updated_at", nullable = false)
+ private Instant updatedAt;
+ public final static String _updatedAt = "updatedAt";
+
+ @Column(name = "is_active", length = 100, nullable = false)
+ @Enumerated(EnumType.STRING)
+ private Status isActive;
+ public final static String _isActive = "isActive";
- public static final String _status = "status";
public UUID getId() {
return id;
@@ -43,12 +50,27 @@ public class DescriptionTemplateTypeEntity implements BaseEntity {
this.name = name;
}
- public Short getStatus() {
- return status;
+ public Instant getCreatedAt() {
+ return createdAt;
}
- public void setStatus(Short status) {
- this.status = status;
+ public void setCreatedAt(Instant createdAt) {
+ this.createdAt = createdAt;
}
+ public Instant getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(Instant updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ public Status getIsActive() {
+ return isActive;
+ }
+
+ public void setIsActive(Status isActive) {
+ this.isActive = isActive;
+ }
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/DescriptionTemplateTypeTouchedEvent.java b/dmp-backend/core/src/main/java/eu/eudat/event/DescriptionTemplateTypeTouchedEvent.java
new file mode 100644
index 000000000..7b2107993
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/DescriptionTemplateTypeTouchedEvent.java
@@ -0,0 +1,22 @@
+package eu.eudat.event;
+
+import java.util.UUID;
+
+public class DescriptionTemplateTypeTouchedEvent {
+ public DescriptionTemplateTypeTouchedEvent() {
+ }
+
+ public DescriptionTemplateTypeTouchedEvent(UUID id) {
+ this.id = id;
+ }
+
+ private UUID id;
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/EventBroker.java b/dmp-backend/core/src/main/java/eu/eudat/event/EventBroker.java
new file mode 100644
index 000000000..c8fca7df1
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/EventBroker.java
@@ -0,0 +1,40 @@
+package eu.eudat.event;
+
+import gr.cite.commons.web.oidc.apikey.events.ApiKeyStaleEvent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.stereotype.Service;
+
+@Service
+public class EventBroker {
+ @Autowired
+ private ApplicationEventPublisher applicationEventPublisher;
+
+ public void emitApiKeyStale(String apiKey) {
+ this.applicationEventPublisher.publishEvent(new ApiKeyStaleEvent(apiKey));
+ }
+
+ public void emit(ApiKeyStaleEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+
+ public void emit(TenantTouchedEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+
+ public void emit(UserTouchedEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+
+ public void emit(UserAddedToTenantEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+
+ public void emit(UserRemovedFromTenantEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+
+ public void emit(DescriptionTemplateTypeTouchedEvent event) {
+ this.applicationEventPublisher.publishEvent(event);
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/TenantTouchedEvent.java b/dmp-backend/core/src/main/java/eu/eudat/event/TenantTouchedEvent.java
new file mode 100644
index 000000000..52c3b0775
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/TenantTouchedEvent.java
@@ -0,0 +1,42 @@
+package eu.eudat.event;
+
+import java.util.UUID;
+
+public class TenantTouchedEvent {
+ public TenantTouchedEvent() {
+ }
+
+ public TenantTouchedEvent(UUID tenantId, String tenantCode, String previousTenantCode) {
+ this.tenantId = tenantId;
+ this.tenantCode = tenantCode;
+ this.previousTenantCode = previousTenantCode;
+ }
+
+ private UUID tenantId;
+ private String tenantCode;
+ private String previousTenantCode;
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getTenantCode() {
+ return tenantCode;
+ }
+
+ public void setTenantCode(String tenantCode) {
+ this.tenantCode = tenantCode;
+ }
+
+ public String getPreviousTenantCode() {
+ return previousTenantCode;
+ }
+
+ public void setPreviousTenantCode(String previousTenantCode) {
+ this.previousTenantCode = previousTenantCode;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/UserAddedToTenantEvent.java b/dmp-backend/core/src/main/java/eu/eudat/event/UserAddedToTenantEvent.java
new file mode 100644
index 000000000..9d1e255bb
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/UserAddedToTenantEvent.java
@@ -0,0 +1,32 @@
+package eu.eudat.event;
+
+import java.util.UUID;
+
+public class UserAddedToTenantEvent {
+ public UserAddedToTenantEvent() {
+ }
+
+ public UserAddedToTenantEvent(UUID userId, UUID tenantId) {
+ this.userId = userId;
+ this.tenantId = tenantId;
+ }
+
+ private UUID userId;
+ private UUID tenantId;
+
+ public UUID getUserId() {
+ return userId;
+ }
+
+ public void setUserId(UUID userId) {
+ this.userId = userId;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/UserRemovedFromTenantEvent.java b/dmp-backend/core/src/main/java/eu/eudat/event/UserRemovedFromTenantEvent.java
new file mode 100644
index 000000000..1fe6b3ab1
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/UserRemovedFromTenantEvent.java
@@ -0,0 +1,32 @@
+package eu.eudat.event;
+
+import java.util.UUID;
+
+public class UserRemovedFromTenantEvent {
+ public UserRemovedFromTenantEvent() {
+ }
+
+ public UserRemovedFromTenantEvent(UUID userId, UUID tenantId) {
+ this.userId = userId;
+ this.tenantId = tenantId;
+ }
+
+ private UUID userId;
+ private UUID tenantId;
+
+ public UUID getUserId() {
+ return userId;
+ }
+
+ public void setUserId(UUID userId) {
+ this.userId = userId;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/event/UserTouchedEvent.java b/dmp-backend/core/src/main/java/eu/eudat/event/UserTouchedEvent.java
new file mode 100644
index 000000000..b22e5ba0a
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/event/UserTouchedEvent.java
@@ -0,0 +1,42 @@
+package eu.eudat.event;
+
+import java.util.UUID;
+
+public class UserTouchedEvent {
+ public UserTouchedEvent() {
+ }
+
+ public UserTouchedEvent(UUID userId, String subjectId, String previousSubjectId) {
+ this.userId = userId;
+ this.subjectId = subjectId;
+ this.previousSubjectId = previousSubjectId;
+ }
+
+ private UUID userId;
+ private String subjectId;
+ private String previousSubjectId;
+
+ public UUID getUserId() {
+ return userId;
+ }
+
+ public void setUserId(UUID userId) {
+ this.userId = userId;
+ }
+
+ public String getSubjectId() {
+ return subjectId;
+ }
+
+ public void setSubjectId(String subjectId) {
+ this.subjectId = subjectId;
+ }
+
+ public String getPreviousSubjectId() {
+ return previousSubjectId;
+ }
+
+ public void setPreviousSubjectId(String previousSubjectId) {
+ this.previousSubjectId = previousSubjectId;
+ }
+}
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 c5fd4a351..c7679284a 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,17 +1,30 @@
package eu.eudat.model;
-import com.fasterxml.jackson.annotation.JsonInclude;
+import eu.eudat.commons.enums.Status;
+import java.time.Instant;
+import java.util.List;
import java.util.UUID;
-@JsonInclude(JsonInclude.Include.NON_NULL)
public class DescriptionTemplateType {
+ public final static String _id = "id";
private UUID id;
+ public final static String _name = "name";
private String name;
- private Short status;
+ public final static String _createdAt = "createdAt";
+ private Instant createdAt;
+
+ public final static String _updatedAt = "updatedAt";
+ private Instant updatedAt;
+
+ public final static String _isActive = "isActive";
+ private Status isActive;
+
+ public final static String _hash = "hash";
+ private String hash;
public UUID getId() {
return id;
@@ -29,12 +42,35 @@ public class DescriptionTemplateType {
this.name = name;
}
- public Short getStatus() {
- return status;
+ public Instant getCreatedAt() {
+ return createdAt;
}
- public void setStatus(Short status) {
- this.status = status;
+ public void setCreatedAt(Instant createdAt) {
+ this.createdAt = createdAt;
}
+ public Instant getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(Instant updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ public Status getIsActive() {
+ return isActive;
+ }
+
+ public void setIsActive(Status isActive) {
+ this.isActive = isActive;
+ }
+
+ public String getHash() {
+ return hash;
+ }
+
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
}
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 c91948d76..1d961a033 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,6 +3,7 @@ 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.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
@@ -12,9 +13,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
public abstract class BaseBuilder implements Builder {
-
protected final LoggerService logger;
-
protected final ConventionService conventionService;
public BaseBuilder(
@@ -25,55 +24,49 @@ public abstract class BaseBuilder implements Builder {
this.logger = logger;
}
- public M build(FieldSet directives, D data) {
+ public M build(FieldSet directives, D data) throws MyApplicationException {
if (data == null) {
- return null;
+ //this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives));
+// return default(M);
+ M model = null;
+ return null; //TODO
}
- List models = this.build(directives == null ? getFullFieldSet() : directives, List.of(data));
- return models.stream().findFirst().orElse(null);
+ List models = this.build(directives, Arrays.asList(data));
+ return models.stream().findFirst().orElse(null); //TODO
}
- public abstract List build(FieldSet directives, List data);
+ public abstract List build(FieldSet directives, List datas) throws MyApplicationException;
- /**
- * 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) {
+ public Map asForeignKey(QueryBase query, FieldSet directives, Function keySelector) throws MyApplicationException {
this.logger.trace("Building references from query");
- List data = query.collectAs(directives);
- this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
- return this.asForeignKey(data, directives, keySelector);
+ List datas = query.collectAs(directives);
+ this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
+ return this.asForeignKey(datas, directives, keySelector);
}
- public Map asForeignKey(List data, FieldSet directives, Function keySelector) {
+ public Map asForeignKey(List datas, FieldSet directives, Function keySelector) throws MyApplicationException {
this.logger.trace("building references");
- List models = this.build(directives, data);
- this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
- assert models != null;
- return models.stream().collect(Collectors.toMap(keySelector, o -> o));
+ List models = this.build(directives, datas);
+ this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
+ Map map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
+ return map;
}
- public Map> asMasterKey(QueryBase query, FieldSet directives, Function keySelector) {
+ public Map> asMasterKey(QueryBase query, FieldSet directives, Function keySelector) throws MyApplicationException {
this.logger.trace("Building details from query");
- List data = query.collectAs(directives);
- this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
- return this.asMasterKey(data, directives, keySelector);
+ List datas = query.collectAs(directives);
+ this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
+ return this.asMasterKey(datas, directives, keySelector);
}
- public Map> asMasterKey(List data, FieldSet directives, Function keySelector) {
+ public Map> asMasterKey(List datas, FieldSet directives, Function keySelector) throws MyApplicationException {
this.logger.trace("building details");
- List models = this.build(directives, data);
- this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
+ List models = this.build(directives, datas);
+ this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
Map> map = new HashMap<>();
- assert models != null;
for (M model : models) {
K key = keySelector.apply(model);
- if (!map.containsKey(key))
- map.put(key, new ArrayList());
+ if (!map.containsKey(key)) map.put(key, new ArrayList());
map.get(key).add(model);
}
return map;
@@ -81,12 +74,13 @@ public abstract class BaseBuilder implements Builder {
public Map asEmpty(List keys, Function mapper, Function keySelector) {
this.logger.trace("building static references");
- List models = keys.stream().map(mapper).collect(Collectors.toList());
- this.logger.trace("mapping {} build items from {} requested", Optional.of(models).map(List::size).orElse(0), Optional.of(keys).map(List::size));
- return models.stream().collect(Collectors.toMap(keySelector, o -> o));
+ List models = keys.stream().map(x -> mapper.apply(x)).collect(Collectors.toList());
+ this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(x -> x.size()).orElse(0), Optional.ofNullable(keys).map(x -> x.size()));
+ Map map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
+ return map;
}
- protected String hashValue(Instant value) {
+ protected String hashValue(Instant value) throws MyApplicationException {
return this.conventionService.hashValue(value);
}
@@ -99,3 +93,4 @@ public abstract class BaseBuilder implements Builder {
}
}
+
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateTypeBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateTypeBuilder.java
index edafeb799..d60023632 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateTypeBuilder.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateTypeBuilder.java
@@ -1,56 +1,67 @@
package eu.eudat.model.builder;
+import eu.eudat.commons.JsonHandlingService;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.model.DescriptionTemplateType;
+import gr.cite.tools.data.builder.BuilderFactory;
+import gr.cite.tools.data.query.QueryFactory;
+import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
+import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionTemplateTypeBuilder extends BaseBuilder {
- public DescriptionTemplateTypeBuilder(ConventionService conventionService) {
+ private final QueryFactory queryFactory;
+ private final BuilderFactory builderFactory;
+ private final JsonHandlingService jsonHandlingService;
+ //private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+
+ @Autowired
+ public DescriptionTemplateTypeBuilder(
+ ConventionService conventionService,
+ QueryFactory queryFactory, BuilderFactory builderFactory, JsonHandlingService jsonHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
+ this.queryFactory = queryFactory;
+ this.builderFactory = builderFactory;
+ this.jsonHandlingService = jsonHandlingService;
}
+// public DescriptionTemplateTypeBuilder authorize(EnumSet values) {
+// this.authorize = values;
+// return this;
+// }
+
@Override
- public List build(FieldSet directives, List data) {
- if (directives == null || directives.isEmpty())
- return new ArrayList<>();
+ public List build(FieldSet fields, List datas) throws MyApplicationException {
+ this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(datas).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
+ this.logger.trace(new DataLogEntry("requested fields", fields));
+ if (fields == null || datas == null || fields.isEmpty()) return new ArrayList<>();
- List models = new ArrayList<>(100);
-
- if (data == null)
- return models;
- for (DescriptionTemplateTypeEntity d : data) {
+ List models = new ArrayList<>();
+ for (DescriptionTemplateTypeEntity d : datas) {
DescriptionTemplateType m = new DescriptionTemplateType();
- if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._id)))
- m.setId(d.getId());
- if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._name)))
- m.setName(d.getName());
- if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._status)))
- m.setStatus(d.getStatus());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._id))) m.setId(d.getId());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._name))) m.setName(d.getName());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._createdAt))) m.setCreatedAt(d.getCreatedAt());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._isActive))) m.setIsActive(d.getIsActive());
+ if (fields.hasField(this.asIndexer(DescriptionTemplateType._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
models.add(m);
}
-
+ this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
-
- @Override
- public FieldSet getFullFieldSet() {
- BaseFieldSet fieldSet = new BaseFieldSet();
- fieldSet.setFields(Set.of(
- DescriptionTemplateTypeEntity._id,
- DescriptionTemplateTypeEntity._name,
- DescriptionTemplateTypeEntity._status
- ));
- return fieldSet;
- }
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java
new file mode 100644
index 000000000..1bc007fe1
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java
@@ -0,0 +1,77 @@
+package eu.eudat.model.deleter;
+
+import eu.eudat.commons.enums.Status;
+import eu.eudat.data.DescriptionTemplateTypeEntity;
+import eu.eudat.query.DescriptionTemplateTypeQuery;
+import gr.cite.tools.data.deleter.Deleter;
+import gr.cite.tools.data.deleter.DeleterFactory;
+import gr.cite.tools.data.query.QueryFactory;
+import gr.cite.tools.logging.LoggerService;
+import gr.cite.tools.logging.MapLogEntry;
+import jakarta.persistence.EntityManager;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.management.InvalidApplicationException;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class DescriptionTemplateTypeDeleter implements Deleter {
+
+ private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeDeleter.class));
+
+ private final EntityManager entityManager;
+ protected final QueryFactory queryFactory;
+ protected final DeleterFactory deleterFactory;
+
+ @Autowired
+ public DescriptionTemplateTypeDeleter(
+ EntityManager entityManager,
+ QueryFactory queryFactory,
+ DeleterFactory deleterFactory
+ ) {
+ this.entityManager = entityManager;
+ this.queryFactory = queryFactory;
+ this.deleterFactory = deleterFactory;
+ }
+
+ public void deleteAndSaveByIds(List ids) throws InvalidApplicationException {
+ logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
+ List data = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(ids).collect();
+ logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
+ this.deleteAndSave(data);
+ }
+
+ public void deleteAndSave(List data) throws InvalidApplicationException {
+ logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
+ this.delete(data);
+ logger.trace("saving changes");
+ this.entityManager.flush();
+ logger.trace("changes saved");
+ }
+
+ public void delete(List data) throws InvalidApplicationException {
+ logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
+ if (data == null || data.isEmpty()) return;
+
+ Instant now = Instant.now();
+
+ for (DescriptionTemplateTypeEntity item : data) {
+ logger.trace("deleting item {}", item.getId());
+ item.setIsActive(Status.Inactive);
+ item.setUpdatedAt(now);
+ logger.trace("updating item");
+ this.entityManager.merge(item);
+ logger.trace("updated item");
+ }
+ }
+
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplateTypePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplateTypePersist.java
new file mode 100644
index 000000000..773db1304
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplateTypePersist.java
@@ -0,0 +1,49 @@
+package eu.eudat.model.persist;
+
+
+import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
+import eu.eudat.commons.validation.ValidId;
+
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
+import java.util.UUID;
+
+@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
+public class DescriptionTemplateTypePersist {
+
+ @ValidId(message = "{validation.invalidid}")
+ private UUID id;
+
+ @NotNull(message = "{validation.empty}")
+ @NotEmpty(message = "{validation.empty}")
+ @Size(max = 500, message = "{validation.largerthanmax}")
+ private String name;
+
+ private String hash;
+
+ 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 String getHash() {
+ return hash;
+ }
+
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
+}
+
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 48131e628..faeb2fcd6 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,9 @@
package eu.eudat.query;
+import eu.eudat.commons.enums.Status;
+import eu.eudat.commons.scope.UserScope;
import eu.eudat.data.DescriptionTemplateTypeEntity;
+import eu.eudat.model.DescriptionTemplateType;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
@@ -11,17 +14,23 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
+import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionTemplateTypeQuery extends QueryBase {
+ private String like;
private Collection ids;
+ private Collection isActives;
+ private Collection excludedIds;
+ //private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
- private Collection names;
-
- private Collection statuses;
+ public DescriptionTemplateTypeQuery like(String value) {
+ this.like = value;
+ return this;
+ }
public DescriptionTemplateTypeQuery ids(UUID value) {
this.ids = List.of(value);
@@ -33,44 +42,55 @@ public class DescriptionTemplateTypeQuery extends QueryBase value) {
- this.ids = value;
+ public DescriptionTemplateTypeQuery ids(Collection values) {
+ this.ids = values;
return this;
}
- public DescriptionTemplateTypeQuery names(String value) {
- this.names = List.of(value);
+ public DescriptionTemplateTypeQuery isActive(Status value) {
+ this.isActives = List.of(value);
return this;
}
- public DescriptionTemplateTypeQuery names(String... value) {
- this.names = Arrays.asList(value);
+ public DescriptionTemplateTypeQuery isActive(Status... value) {
+ this.isActives = Arrays.asList(value);
return this;
}
- public DescriptionTemplateTypeQuery names(List value) {
- this.names = value;
+ public DescriptionTemplateTypeQuery isActive(Collection values) {
+ this.isActives = values;
return this;
}
- public DescriptionTemplateTypeQuery statuses(Short value) {
- this.statuses = List.of(value);
+ public DescriptionTemplateTypeQuery excludedIds(Collection values) {
+ this.excludedIds = values;
return this;
}
- public DescriptionTemplateTypeQuery statuses(Short... value) {
- this.statuses = Arrays.asList(value);
+ public DescriptionTemplateTypeQuery excludedIds(UUID value) {
+ this.excludedIds = List.of(value);
return this;
}
- public DescriptionTemplateTypeQuery statuses(List value) {
- this.statuses = value;
+ public DescriptionTemplateTypeQuery excludedIds(UUID... value) {
+ this.excludedIds = Arrays.asList(value);
return this;
}
- @Override
- protected Boolean isFalseQuery() {
- return Boolean.FALSE;
+// public DescriptionTemplateTypeQuery authorize(EnumSet values) {
+// this.authorize = values;
+// return this;
+// }
+
+ private final UserScope userScope;
+// private final AuthorizationService authService;
+
+ public DescriptionTemplateTypeQuery(
+ UserScope userScope
+ //AuthorizationService authService
+ ) {
+ this.userScope = userScope;
+ //this.authService = authService;
}
@Override
@@ -79,46 +99,58 @@ public class DescriptionTemplateTypeQuery extends QueryBase Predicate applyFilters(QueryContext queryContext) {
- List predicates = new ArrayList<>();
-
- if (this.ids != null) {
- CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
- 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);
- 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);
- predicates.add(inClause);
- }
-
- if (!predicates.isEmpty()) {
- Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
- return queryContext.CriteriaBuilder.and(predicatesArray);
- } else {
- return queryContext.CriteriaBuilder.and();
- }
+ protected Boolean isFalseQuery() {
+ return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds);
}
@Override
- protected String fieldNameOf(FieldResolver item) {
- return null;
+ protected Predicate applyFilters(QueryContext queryContext) {
+ List predicates = new ArrayList<>();
+ if (this.ids != null) {
+ CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
+ for (UUID item : this.ids) inClause.value(item);
+ predicates.add(inClause);
+ }
+ if (this.like != null && !this.like.isEmpty()) {
+ predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(DescriptionTemplateTypeEntity._name), this.like));
+ }
+ if (this.isActives != null) {
+ CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._isActive));
+ for (Status item : this.isActives) inClause.value(item);
+ predicates.add(inClause);
+ }
+ if (this.excludedIds != null) {
+ CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
+ for (UUID item : this.excludedIds) notInClause.value(item);
+ predicates.add(notInClause.not());
+ }
+ if (predicates.size() > 0) {
+ Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
+ return queryContext.CriteriaBuilder.and(predicatesArray);
+ } else {
+ return null;
+ }
}
@Override
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set columns) {
- return null;
+ DescriptionTemplateTypeEntity item = new DescriptionTemplateTypeEntity();
+ item.setId(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._id, UUID.class));
+ item.setName(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._name, String.class));
+ item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._createdAt, Instant.class));
+ item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._updatedAt, Instant.class));
+ item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionTemplateTypeEntity._isActive, Status.class));
+ return item;
+ }
+
+ @Override
+ protected String fieldNameOf(FieldResolver item) {
+ if (item.match(DescriptionTemplateType._id)) return DescriptionTemplateType._id;
+ else if (item.match(DescriptionTemplateType._name)) return DescriptionTemplateType._name;
+ else if (item.match(DescriptionTemplateType._createdAt)) return DescriptionTemplateType._createdAt;
+ else if (item.match(DescriptionTemplateType._updatedAt)) return DescriptionTemplateType._updatedAt;
+ else if (item.match(DescriptionTemplateType._isActive)) return DescriptionTemplateType._isActive;
+ else return null;
}
}
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 3fcd57ad0..35057ae08 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
@@ -1,37 +1,60 @@
package eu.eudat.query.lookup;
+import eu.eudat.commons.enums.Status;
import eu.eudat.query.DescriptionTemplateTypeQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
+import java.util.List;
+import java.util.UUID;
+
public class DescriptionTemplateTypeLookup extends Lookup {
- private String name;
+ private String like;
+ private List isActive;
+ private List ids;
+ private List excludedIds;
- private Short status;
-
- public String getName() {
- return name;
+ public String getLike() {
+ return like;
}
- public void setName(String name) {
- this.name = name;
+ public void setLike(String like) {
+ this.like = like;
}
- public Short getStatus() {
- return status;
+ public List getIsActive() {
+ return isActive;
}
- public void setStatus(Short status) {
- this.status = status;
+ public void setIsActive(List isActive) {
+ this.isActive = isActive;
+ }
+
+ public List getIds() {
+ return ids;
+ }
+
+ public void setIds(List ids) {
+ this.ids = ids;
+ }
+
+ public List getExcludedIds() {
+ return excludedIds;
+ }
+
+ public void setExcludedIds(List excludeIds) {
+ this.excludedIds = excludeIds;
}
public DescriptionTemplateTypeQuery enrich(QueryFactory queryFactory) {
DescriptionTemplateTypeQuery query = queryFactory.query(DescriptionTemplateTypeQuery.class);
- if (name != null) query.names(name);
- if (status != null ) query.statuses(status);
+ if (this.like != null) query.like(this.like);
+ if (this.isActive != null) query.isActive(this.isActive);
+ if (this.ids != null) query.ids(this.ids);
+ if (this.excludedIds != null) query.excludedIds(this.excludedIds);
- enrichCommon(query);
+ this.enrichCommon(query);
return query;
}
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 a7fab06fb..35b8473b2 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
@@ -1,121 +1,18 @@
package eu.eudat.service;
-import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
-import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.model.DescriptionTemplateType;
-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 gr.cite.tools.data.query.QueryFactory;
+import eu.eudat.model.persist.DescriptionTemplateTypePersist;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
-import jakarta.persistence.EntityManager;
-import jakarta.persistence.PersistenceContext;
-import org.springframework.context.ApplicationContext;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionStatus;
-import org.springframework.transaction.support.DefaultTransactionDefinition;
+import gr.cite.tools.exception.MyValidationException;
+import gr.cite.tools.fieldset.FieldSet;
-import java.util.List;
+import javax.management.InvalidApplicationException;
import java.util.UUID;
-@Service
-public class DescriptionTemplateTypeService {
-
- private final ApplicationContext applicationContext;
-
- private final BuilderFactory builderFactory;
-
- private final QueryFactory queryFactory;
-
- private final PlatformTransactionManager transactionManager;
-
- @PersistenceContext
- private EntityManager entityManager;
-
- public DescriptionTemplateTypeService(ApplicationContext applicationContext, BuilderFactory builderFactory, QueryFactory queryFactory, PlatformTransactionManager platformTransactionManager) {
- this.applicationContext = applicationContext;
- this.builderFactory = builderFactory;
- this.queryFactory = queryFactory;
- this.transactionManager = platformTransactionManager;
- }
-
- public List query(DescriptionTemplateTypeLookup lookup) {
- DescriptionTemplateTypeQuery query = lookup.enrich(queryFactory);
- List data = query.collectAs(lookup.getProject());
-
- return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(lookup.getProject(), data);
- }
-
- public long count(DescriptionTemplateTypeLookup lookup) {
- DescriptionTemplateTypeQuery query = lookup.enrich(queryFactory);
- return query.count();
- }
-
- public DescriptionTemplateType get(UUID id) {
- DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
-
- return builderFactory
- .builder(DescriptionTemplateTypeBuilder.class)
- .build(null, query.ids(id).first());
- }
-
- public DescriptionTemplateTypeEntity getEntityByName(String name) {
- DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
-
- return query.names(name).first();
- }
-
- public DescriptionTemplateType persist(DescriptionTemplateType payload) {
- DescriptionTemplateTypeEntity created = new DescriptionTemplateTypeEntity();
- created.setName(payload.getName());
- created.setStatus(DescriptionTemplateTypeStatus.SAVED.getValue());
-
- DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
- definition.setName(UUID.randomUUID().toString());
- definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
- definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
- TransactionStatus status = null;
- try {
- status = transactionManager.getTransaction(definition);
- entityManager.persist(created);
-
- entityManager.flush();
- transactionManager.commit(status);
- } catch (Exception ex) {
- if (status != null)
- transactionManager.rollback(status);
- throw ex;
- }
-
- DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
-
- return builderFactory
- .builder(DescriptionTemplateTypeBuilder.class)
- .build(null, query.ids(created.getId()).first());
- }
-
- public DescriptionTemplateType update(DescriptionTemplateType payload) {
- DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, payload.getId());
- entity.setName(payload.getName());
- entity.setStatus(payload.getStatus());
- entityManager.merge(entity);
- entityManager.flush();
-
- return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(null, entity);
- }
-
- public boolean delete(UUID id) {
- DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, id);
- if (entity == null)
- return false;
- entity.setStatus(DescriptionTemplateTypeStatus.DELETED.getValue());
- entityManager.merge(entity);
- entityManager.flush();
-
- return true;
- }
+public interface DescriptionTemplateTypeService {
+ DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
+ void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeServiceImpl.java
new file mode 100644
index 000000000..dd9580143
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/service/DescriptionTemplateTypeServiceImpl.java
@@ -0,0 +1,117 @@
+package eu.eudat.service;
+
+import eu.eudat.commons.JsonHandlingService;
+import eu.eudat.commons.enums.Status;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.data.DescriptionTemplateTypeEntity;
+import eu.eudat.errorcode.ErrorThesaurusProperties;
+import eu.eudat.event.DescriptionTemplateTypeTouchedEvent;
+import eu.eudat.event.EventBroker;
+import eu.eudat.model.DescriptionTemplateType;
+import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
+import eu.eudat.model.deleter.DescriptionTemplateTypeDeleter;
+import eu.eudat.model.persist.DescriptionTemplateTypePersist;
+import eu.eudat.query.DescriptionTemplateTypeQuery;
+import gr.cite.tools.data.builder.BuilderFactory;
+import gr.cite.tools.data.deleter.DeleterFactory;
+import gr.cite.tools.data.query.QueryFactory;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.exception.MyForbiddenException;
+import gr.cite.tools.exception.MyNotFoundException;
+import gr.cite.tools.exception.MyValidationException;
+import gr.cite.tools.fieldset.BaseFieldSet;
+import gr.cite.tools.fieldset.FieldSet;
+import gr.cite.tools.logging.LoggerService;
+import gr.cite.tools.logging.MapLogEntry;
+import jakarta.persistence.EntityManager;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.stereotype.Service;
+import org.springframework.web.context.annotation.RequestScope;
+
+import javax.management.InvalidApplicationException;
+import java.time.Instant;
+import java.util.List;
+import java.util.UUID;
+
+@Service
+@RequestScope
+public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTypeService {
+ private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeServiceImpl.class));
+
+ private final EntityManager entityManager;
+ //private final AuthorizationService authorizationService;
+ private final DeleterFactory deleterFactory;
+ private final BuilderFactory builderFactory;
+ private final ConventionService conventionService;
+ private final ErrorThesaurusProperties errors;
+ private final MessageSource messageSource;
+ private final EventBroker eventBroker;
+ private final QueryFactory queryFactory;
+ private final JsonHandlingService jsonHandlingService;
+
+ @Autowired
+ public DescriptionTemplateTypeServiceImpl(
+ EntityManager entityManager,
+ //AuthorizationService authorizationService,
+ DeleterFactory deleterFactory,
+ BuilderFactory builderFactory,
+ ConventionService conventionService,
+ ErrorThesaurusProperties errors,
+ MessageSource messageSource,
+ EventBroker eventBroker,
+ QueryFactory queryFactory,
+ JsonHandlingService jsonHandlingService) {
+ this.entityManager = entityManager;
+ //this.authorizationService = authorizationService;
+ this.deleterFactory = deleterFactory;
+ this.builderFactory = builderFactory;
+ this.conventionService = conventionService;
+ this.errors = errors;
+ this.messageSource = messageSource;
+ this.eventBroker = eventBroker;
+ this.queryFactory = queryFactory;
+ this.jsonHandlingService = jsonHandlingService;
+ }
+
+ public DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
+ logger.debug(new MapLogEntry("persisting data descriptionTemplateType").And("model", model).And("fields", fields));
+
+ //this.authorizationService.authorizeForce(Permission.EditDescriptionTemplateType);
+
+ Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
+
+ DescriptionTemplateTypeEntity data;
+ if (isUpdate) {
+ data = this.entityManager.find(DescriptionTemplateTypeEntity.class, model.getId());
+ if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
+ } else {
+ data = new DescriptionTemplateTypeEntity();
+ data.setId(UUID.randomUUID());
+ data.setIsActive(Status.Active);
+ data.setCreatedAt(Instant.now());
+ }
+
+ data.setName(model.getName());
+ data.setUpdatedAt(Instant.now());
+ if (isUpdate) this.entityManager.merge(data);
+ else this.entityManager.persist(data);
+
+ this.entityManager.flush();
+
+ this.eventBroker.emit(new DescriptionTemplateTypeTouchedEvent(data.getId()));
+ //return this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType).build(BaseFieldSet.build(fields, DescriptionTemplateType._id), data);
+ return this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(BaseFieldSet.build(fields, DescriptionTemplateType._id), data);
+ }
+
+ public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
+ logger.debug("deleting dataset: {}", id);
+
+ //this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplateType);
+
+ this.deleterFactory.deleter(DescriptionTemplateTypeDeleter.class).deleteAndSaveByIds(List.of(id));
+ }
+}
+
diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml
index 719322697..687d89c66 100644
--- a/dmp-backend/pom.xml
+++ b/dmp-backend/pom.xml
@@ -301,7 +301,10 @@
io.micrometer
micrometer-core
-
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
gr.cite
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 b3ae6f92c..85202a611 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
@@ -66,7 +66,7 @@ public class Admin extends BaseController {
DatasetProfile shortenProfile = profile.toShort();
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()));
- modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType()));
+//TODO: dtziotzios 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/v2/DescriptionTemplateTypeV2Controller.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateTypeV2Controller.java
index d063e46f4..628bd2696 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateTypeV2Controller.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateTypeV2Controller.java
@@ -1,22 +1,32 @@
package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction;
+import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.model.DescriptionTemplateType;
+import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
import eu.eudat.model.censorship.DescriptionTemplateTypeCensor;
+import eu.eudat.model.persist.DescriptionTemplateTypePersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.security.Principal;
+import eu.eudat.query.DescriptionTemplateTypeQuery;
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
import eu.eudat.service.DescriptionTemplateTypeService;
import eu.eudat.types.Authorities;
import gr.cite.tools.auditing.AuditService;
+import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
+import gr.cite.tools.data.query.QueryFactory;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
+import gr.cite.tools.validation.MyValidate;
import org.opensaml.xml.signature.Q;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpStatus;
@@ -25,101 +35,102 @@ import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
-import java.util.AbstractMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import javax.management.InvalidApplicationException;
+import java.io.IOException;
+import java.util.*;
@RestController
@CrossOrigin
-@Transactional
-@RequestMapping(path = "api/v2/descriptionTemplateType", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequestMapping(path = "api/description-template-type")
public class DescriptionTemplateTypeV2Controller {
-
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
+ private final BuilderFactory builderFactory;
private final AuditService auditService;
-
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
-
+ private final CensorFactory censorFactory;
+ private final QueryFactory queryFactory;
private final MessageSource messageSource;
- private final CensorFactory censorFactory;
-
- public DescriptionTemplateTypeV2Controller(AuditService auditService, DescriptionTemplateTypeService descriptionTemplateTypeService, MessageSource messageSource, CensorFactory censorFactory) {
+ @Autowired
+ public DescriptionTemplateTypeV2Controller(
+ BuilderFactory builderFactory,
+ AuditService auditService,
+ DescriptionTemplateTypeService descriptionTemplateTypeService,
+ CensorFactory censorFactory,
+ QueryFactory queryFactory,
+ MessageSource messageSource) {
+ this.builderFactory = builderFactory;
this.auditService = auditService;
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
- this.messageSource = messageSource;
this.censorFactory = censorFactory;
+ this.queryFactory = queryFactory;
+ this.messageSource = messageSource;
}
@PostMapping("query")
- public QueryResult query(@RequestBody DescriptionTemplateTypeLookup lookup, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
+ public QueryResult Query(@RequestBody DescriptionTemplateTypeLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", DescriptionTemplateType.class.getSimpleName());
- censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject());
+ //this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject(), null);
- List models = descriptionTemplateTypeService.query(lookup);
- long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? descriptionTemplateTypeService.count(lookup) : models.size();
+ DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory);
+ //DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType);
- auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
+ List data = query.collectAs(lookup.getProject());
+ //List models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType).build(lookup.getProject(), data);
+ List models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(lookup.getProject(), data);
+ long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
+
+ this.auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
+ //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
- public QueryResult get(@PathVariable("id") UUID id, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
- logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
+ public DescriptionTemplateType Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
+ logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id).And("fields", fieldSet));
- censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet);
+ //this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet, null);
- DescriptionTemplateType model = descriptionTemplateTypeService.get(id);
- if (model == null)
- throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
+ DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(id);
+ DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(fieldSet, query.firstAs(fieldSet));
+ //DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType).ids(id);
+ //DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType).build(fieldSet, query.firstAs(fieldSet));
+ if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
- auditService.track(AuditableAction.DescriptionTemplateType_Query, "id", id);
+ this.auditService.track(AuditableAction.DescriptionTemplateType_Lookup, Map.ofEntries(
+ new AbstractMap.SimpleEntry("id", id),
+ new AbstractMap.SimpleEntry("fields", fieldSet)
+ ));
+ //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
- return new QueryResult<>(model);
+ return model;
}
@PostMapping("persist")
- public QueryResult persist(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
- logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
+ @Transactional
+ public DescriptionTemplateType Persist(@MyValidate @RequestBody DescriptionTemplateTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
+ logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
+ DescriptionTemplateType persisted = this.descriptionTemplateTypeService.persist(model, fieldSet);
- DescriptionTemplateType persisted = descriptionTemplateTypeService.persist(payload);
-
- auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
- new AbstractMap.SimpleEntry("model", payload),
+ this.auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
+ new AbstractMap.SimpleEntry("model", model),
new AbstractMap.SimpleEntry("fields", fieldSet)
));
-
- return new QueryResult<>(persisted);
+ //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
+ return persisted;
}
- @PostMapping("update")
- public QueryResult update(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
- logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
+ @DeleteMapping("{id}")
+ @Transactional
+ public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
+ logger.debug(new MapLogEntry("retrieving" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
- DescriptionTemplateType persisted = descriptionTemplateTypeService.update(payload);
+ this.descriptionTemplateTypeService.deleteAndSave(id);
- auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
- new AbstractMap.SimpleEntry("model", payload),
- new AbstractMap.SimpleEntry("fields", fieldSet)
- ));
-
- return new QueryResult<>(persisted);
+ this.auditService.track(AuditableAction.DescriptionTemplateType_Delete, "id", id);
+ //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
}
-
- @DeleteMapping("delete/{id}")
- public ResponseEntity> delete(@PathVariable(value = "id") UUID id, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
- logger.debug(new MapLogEntry("deleting" + DescriptionTemplateType.class.getSimpleName()).And("id", id));
-
- auditService.track(AuditableAction.DescriptionTemplateType_Delete, "delete", id);
-
- if (descriptionTemplateTypeService.delete(id))
- return ResponseEntity.status(HttpStatus.OK).build();
- else
- return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
- }
-
}
diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java
index d82e2832b..067f9860a 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java
@@ -39,7 +39,7 @@ public class AdminManager {
DescriptionTemplateTypeEntity type;
try {
- type = descriptionTemplateTypeService.getEntityByName(profile.getType());
+ //TODO: dtziotzios type = descriptionTemplateTypeService.getEntityByName(profile.getType());
}
catch (Exception e) {
throw new Exception("Description template type '" + profile.getType() + "' could not be found.");
@@ -47,7 +47,7 @@ public class AdminManager {
DescriptionTemplate descriptionTemplate = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
- .type(type)
+ //TODO: dtziotzios .type(type)
.build();
if (descriptionTemplate.getGroupId() == null) {
diff --git a/dmp-db-scema/updates/00.01.001_Align_Description_Template_Type.sql b/dmp-db-scema/updates/00.01.001_Align_Description_Template_Type.sql
new file mode 100644
index 000000000..f45526f8b
--- /dev/null
+++ b/dmp-db-scema/updates/00.01.001_Align_Description_Template_Type.sql
@@ -0,0 +1,23 @@
+ALTER TABLE public."DescriptionTemplateType"
+ RENAME "ID" TO id;
+
+ALTER TABLE public."DescriptionTemplateType"
+ RENAME "Name" TO name;
+
+ALTER TABLE public."DescriptionTemplateType"
+ RENAME "Status" TO is_active;
+
+ALTER TABLE public."DescriptionTemplateType"
+ ADD COLUMN created_at timestamp without time zone;
+
+ALTER TABLE public."DescriptionTemplateType"
+ ADD COLUMN updated_at timestamp without time zone;
+
+UPDATE public."DescriptionTemplateType" SET created_at = now();
+UPDATE public."DescriptionTemplateType" SET updated_at = now();
+
+ALTER TABLE public."DescriptionTemplateType"
+ ALTER COLUMN created_at SET NOT NULL;
+
+ALTER TABLE public."DescriptionTemplateType"
+ ALTER COLUMN updated_at SET NOT NULL;
diff --git a/dmp-frontend/src/app/core/query/description-template/description-template-type.lookup.ts b/dmp-frontend/src/app/core/query/description-template/description-template-type.lookup.ts
index f3da70996..2acefc395 100644
--- a/dmp-frontend/src/app/core/query/description-template/description-template-type.lookup.ts
+++ b/dmp-frontend/src/app/core/query/description-template/description-template-type.lookup.ts
@@ -1,8 +1,12 @@
+import { Status } from "@app/core/common/enum/status";
import { Lookup } from "@common/model/lookup";
+import { Guid } from "@common/types/guid";
export class DescriptionTemplateTypeLookup extends Lookup {
- name: string;
- status: number;
+ ids: Guid[];
+ excludedIds: Guid[];
+ like: string;
+ isActive: Status[];
constructor() {
super();
diff --git a/dmp-frontend/src/app/core/services/description-template-type/description-template-type.service.ts b/dmp-frontend/src/app/core/services/description-template-type/description-template-type.service.ts
index 0428d4bca..6ca3b1ab4 100644
--- a/dmp-frontend/src/app/core/services/description-template-type/description-template-type.service.ts
+++ b/dmp-frontend/src/app/core/services/description-template-type/description-template-type.service.ts
@@ -10,7 +10,7 @@ import { BaseHttpV2Service } from '../http/base-http-v2.service';
@Injectable()
export class DescriptionTemplateTypeService {
- private get apiBase(): string { return `${this.configurationService.server}v2/descriptionTemplateType`; }
+ private get apiBase(): string { return `${this.configurationService.server}description-template-type`; }
private headers = new HttpHeaders();
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService) {}
diff --git a/dmp-frontend/src/app/ui/admin/description-types/listing/description-types.component.ts b/dmp-frontend/src/app/ui/admin/description-types/listing/description-types.component.ts
index 703b76f45..3e5176d97 100644
--- a/dmp-frontend/src/app/ui/admin/description-types/listing/description-types.component.ts
+++ b/dmp-frontend/src/app/ui/admin/description-types/listing/description-types.component.ts
@@ -150,7 +150,9 @@ export class DescriptionTypesDataSource extends DataSource(x => x.status)
]
};
-
+ lookup.order = {
+ items: ['name']
+ };
return this._service.query(lookup)
}),
map(result => {