Description Template Types backend refactored to new format.
This commit is contained in:
parent
419c4d64f8
commit
3eaf326c50
|
@ -21,6 +21,15 @@
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>gr.cite</groupId>
|
||||||
|
<artifactId>validation</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -5,9 +5,8 @@ import gr.cite.tools.logging.EventId;
|
||||||
public class AuditableAction {
|
public class AuditableAction {
|
||||||
|
|
||||||
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
|
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
|
||||||
|
public static final EventId DescriptionTemplateType_Lookup = new EventId(1001, "DescriptionTemplateType_Lookup");
|
||||||
public static final EventId DescriptionTemplateType_Persist = new EventId(1001, "DescriptionTemplateType_Persist");
|
public static final EventId DescriptionTemplateType_Persist = new EventId(1002, "DescriptionTemplateType_Persist");
|
||||||
|
public static final EventId DescriptionTemplateType_Delete = new EventId(1003, "DescriptionTemplateType_Delete");
|
||||||
public static final EventId DescriptionTemplateType_Delete = new EventId(1002, "DescriptionTemplateType_Delete");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> T fromJson(Class<T> type, String json) throws JsonProcessingException {
|
||||||
|
if (json == null) return null;
|
||||||
|
return objectMapper.readValue(json, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T fromJsonSafe(Class<T> type, String json) {
|
||||||
|
if (json == null) return null;
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(json, type);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
public class EnumNotNull implements ConstraintValidator<ValidEnum,Object> {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Object value, ConstraintValidatorContext context) {
|
||||||
|
return value != null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 {};
|
||||||
|
}
|
|
@ -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<FieldNotNullIfOtherSet, Object> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<FieldsValueMatch, Object> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 {};
|
||||||
|
}
|
|
@ -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 {};
|
||||||
|
}
|
|
@ -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<ValidId, Object> {
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,23 +3,20 @@ package eu.eudat.commons.validation;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.validation.BaseValidationService;
|
import gr.cite.tools.validation.BaseValidationService;
|
||||||
import jakarta.validation.Validator;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import jakarta.validation.Validator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
||||||
public class ValidationServiceImpl extends BaseValidationService {
|
public class ValidationServiceImpl extends BaseValidationService {
|
||||||
|
|
||||||
private ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors){
|
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors) {
|
||||||
super(validator);
|
super(validator);
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,38 @@
|
||||||
package eu.eudat.data;
|
package eu.eudat.data;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.Status;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DescriptionTemplateType\"")
|
@Table(name = "\"DescriptionTemplateType\"")
|
||||||
public class DescriptionTemplateTypeEntity implements BaseEntity {
|
public class DescriptionTemplateTypeEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
||||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
public final static String _id = "id";
|
||||||
|
|
||||||
public static final String _id = "id";
|
@Column(name = "name", length = 500, nullable = false)
|
||||||
|
|
||||||
@Column(name = "\"Name\"", nullable = false)
|
|
||||||
private String name;
|
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)
|
@Column(name = "updated_at", nullable = false)
|
||||||
private Short status;
|
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() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -43,12 +50,27 @@ public class DescriptionTemplateTypeEntity implements BaseEntity {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public Instant getCreatedAt() {
|
||||||
return status;
|
return createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setCreatedAt(Instant createdAt) {
|
||||||
this.status = status;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,30 @@
|
||||||
package eu.eudat.model;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
public class DescriptionTemplateType {
|
public class DescriptionTemplateType {
|
||||||
|
|
||||||
|
public final static String _id = "id";
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
public final static String _name = "name";
|
||||||
private String 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() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -29,12 +42,35 @@ public class DescriptionTemplateType {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public Instant getCreatedAt() {
|
||||||
return status;
|
return createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setCreatedAt(Instant createdAt) {
|
||||||
this.status = status;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.model.builder;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import gr.cite.tools.data.builder.Builder;
|
import gr.cite.tools.data.builder.Builder;
|
||||||
import gr.cite.tools.data.query.QueryBase;
|
import gr.cite.tools.data.query.QueryBase;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
|
||||||
|
@ -12,9 +13,7 @@ import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class BaseBuilder<M, D> implements Builder {
|
public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
|
|
||||||
protected final LoggerService logger;
|
protected final LoggerService logger;
|
||||||
|
|
||||||
protected final ConventionService conventionService;
|
protected final ConventionService conventionService;
|
||||||
|
|
||||||
public BaseBuilder(
|
public BaseBuilder(
|
||||||
|
@ -25,55 +24,49 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public M build(FieldSet directives, D data) {
|
public M build(FieldSet directives, D data) throws MyApplicationException {
|
||||||
if (data == null) {
|
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<M> models = this.build(directives == null ? getFullFieldSet() : directives, List.of(data));
|
List<M> models = this.build(directives, Arrays.asList(data));
|
||||||
return models.stream().findFirst().orElse(null);
|
return models.stream().findFirst().orElse(null); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<M> build(FieldSet directives, List<D> data);
|
public abstract List<M> build(FieldSet directives, List<D> datas) throws MyApplicationException;
|
||||||
|
|
||||||
/**
|
public <K> Map<K, M> asForeignKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) 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 <K> Map<K, M> asForeignKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
|
|
||||||
this.logger.trace("Building references from query");
|
this.logger.trace("Building references from query");
|
||||||
List<D> data = query.collectAs(directives);
|
List<D> datas = query.collectAs(directives);
|
||||||
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
return this.asForeignKey(data, directives, keySelector);
|
return this.asForeignKey(datas, directives, keySelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, M> asForeignKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, M> asForeignKey(List<D> datas, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("building references");
|
this.logger.trace("building references");
|
||||||
List<M> models = this.build(directives, data);
|
List<M> models = this.build(directives, datas);
|
||||||
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
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));
|
||||||
assert models != null;
|
Map<K, M> map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
|
||||||
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("Building details from query");
|
this.logger.trace("Building details from query");
|
||||||
List<D> data = query.collectAs(directives);
|
List<D> datas = query.collectAs(directives);
|
||||||
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||||
return this.asMasterKey(data, directives, keySelector);
|
return this.asMasterKey(datas, directives, keySelector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <K> Map<K, List<M>> asMasterKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
|
public <K> Map<K, List<M>> asMasterKey(List<D> datas, FieldSet directives, Function<M, K> keySelector) throws MyApplicationException {
|
||||||
this.logger.trace("building details");
|
this.logger.trace("building details");
|
||||||
List<M> models = this.build(directives, data);
|
List<M> models = this.build(directives, datas);
|
||||||
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
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<K, List<M>> map = new HashMap<>();
|
Map<K, List<M>> map = new HashMap<>();
|
||||||
assert models != null;
|
|
||||||
for (M model : models) {
|
for (M model : models) {
|
||||||
K key = keySelector.apply(model);
|
K key = keySelector.apply(model);
|
||||||
if (!map.containsKey(key))
|
if (!map.containsKey(key)) map.put(key, new ArrayList<M>());
|
||||||
map.put(key, new ArrayList<M>());
|
|
||||||
map.get(key).add(model);
|
map.get(key).add(model);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -81,12 +74,13 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
|
|
||||||
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
|
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
|
||||||
this.logger.trace("building static references");
|
this.logger.trace("building static references");
|
||||||
List<FM> models = keys.stream().map(mapper).collect(Collectors.toList());
|
List<FM> models = keys.stream().map(x -> mapper.apply(x)).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));
|
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(x -> x.size()).orElse(0), Optional.ofNullable(keys).map(x -> x.size()));
|
||||||
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
|
Map<FK, FM> 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);
|
return this.conventionService.hashValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,3 +93,4 @@ public abstract class BaseBuilder<M, D> implements Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,56 +1,67 @@
|
||||||
package eu.eudat.model.builder;
|
package eu.eudat.model.builder;
|
||||||
|
|
||||||
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
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.BaseFieldSet;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import gr.cite.tools.logging.DataLogEntry;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.slf4j.LoggerFactory;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DescriptionTemplateTypeBuilder extends BaseBuilder<DescriptionTemplateType, DescriptionTemplateTypeEntity> {
|
public class DescriptionTemplateTypeBuilder extends BaseBuilder<DescriptionTemplateType, DescriptionTemplateTypeEntity> {
|
||||||
|
|
||||||
public DescriptionTemplateTypeBuilder(ConventionService conventionService) {
|
private final QueryFactory queryFactory;
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
|
private final JsonHandlingService jsonHandlingService;
|
||||||
|
//private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeBuilder(
|
||||||
|
ConventionService conventionService,
|
||||||
|
QueryFactory queryFactory, BuilderFactory builderFactory, JsonHandlingService jsonHandlingService) {
|
||||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public DescriptionTemplateTypeBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
// this.authorize = values;
|
||||||
|
// return this;
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DescriptionTemplateType> build(FieldSet directives, List<DescriptionTemplateTypeEntity> data) {
|
public List<DescriptionTemplateType> build(FieldSet fields, List<DescriptionTemplateTypeEntity> datas) throws MyApplicationException {
|
||||||
if (directives == null || directives.isEmpty())
|
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));
|
||||||
return new ArrayList<>();
|
this.logger.trace(new DataLogEntry("requested fields", fields));
|
||||||
|
if (fields == null || datas == null || fields.isEmpty()) return new ArrayList<>();
|
||||||
|
|
||||||
List<DescriptionTemplateType> models = new ArrayList<>(100);
|
List<DescriptionTemplateType> models = new ArrayList<>();
|
||||||
|
for (DescriptionTemplateTypeEntity d : datas) {
|
||||||
if (data == null)
|
|
||||||
return models;
|
|
||||||
for (DescriptionTemplateTypeEntity d : data) {
|
|
||||||
DescriptionTemplateType m = new DescriptionTemplateType();
|
DescriptionTemplateType m = new DescriptionTemplateType();
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._id)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._id))) m.setId(d.getId());
|
||||||
m.setId(d.getId());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._name))) m.setName(d.getName());
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._name)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
||||||
m.setName(d.getName());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
||||||
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._status)))
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._isActive))) m.setIsActive(d.getIsActive());
|
||||||
m.setStatus(d.getStatus());
|
if (fields.hasField(this.asIndexer(DescriptionTemplateType._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FieldSet getFullFieldSet() {
|
|
||||||
BaseFieldSet fieldSet = new BaseFieldSet();
|
|
||||||
fieldSet.setFields(Set.of(
|
|
||||||
DescriptionTemplateTypeEntity._id,
|
|
||||||
DescriptionTemplateTypeEntity._name,
|
|
||||||
DescriptionTemplateTypeEntity._status
|
|
||||||
));
|
|
||||||
return fieldSet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<UUID> ids) throws InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||||
|
List<DescriptionTemplateTypeEntity> 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<DescriptionTemplateTypeEntity> 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<DescriptionTemplateTypeEntity> 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package eu.eudat.query;
|
package eu.eudat.query;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.Status;
|
||||||
|
import eu.eudat.commons.scope.UserScope;
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.data.query.QueryBase;
|
import gr.cite.tools.data.query.QueryBase;
|
||||||
import gr.cite.tools.data.query.QueryContext;
|
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.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateTypeEntity> {
|
public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateTypeEntity> {
|
||||||
|
|
||||||
|
private String like;
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
private Collection<Status> isActives;
|
||||||
|
private Collection<UUID> excludedIds;
|
||||||
|
//private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
private Collection<String> names;
|
public DescriptionTemplateTypeQuery like(String value) {
|
||||||
|
this.like = value;
|
||||||
private Collection<Short> statuses;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery ids(UUID value) {
|
public DescriptionTemplateTypeQuery ids(UUID value) {
|
||||||
this.ids = List.of(value);
|
this.ids = List.of(value);
|
||||||
|
@ -33,44 +42,55 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery ids(List<UUID> value) {
|
public DescriptionTemplateTypeQuery ids(Collection<UUID> values) {
|
||||||
this.ids = value;
|
this.ids = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(String value) {
|
public DescriptionTemplateTypeQuery isActive(Status value) {
|
||||||
this.names = List.of(value);
|
this.isActives = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(String... value) {
|
public DescriptionTemplateTypeQuery isActive(Status... value) {
|
||||||
this.names = Arrays.asList(value);
|
this.isActives = Arrays.asList(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery names(List<String> value) {
|
public DescriptionTemplateTypeQuery isActive(Collection<Status> values) {
|
||||||
this.names = value;
|
this.isActives = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(Short value) {
|
public DescriptionTemplateTypeQuery excludedIds(Collection<UUID> values) {
|
||||||
this.statuses = List.of(value);
|
this.excludedIds = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(Short... value) {
|
public DescriptionTemplateTypeQuery excludedIds(UUID value) {
|
||||||
this.statuses = Arrays.asList(value);
|
this.excludedIds = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery statuses(List<Short> value) {
|
public DescriptionTemplateTypeQuery excludedIds(UUID... value) {
|
||||||
this.statuses = value;
|
this.excludedIds = Arrays.asList(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// public DescriptionTemplateTypeQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
protected Boolean isFalseQuery() {
|
// this.authorize = values;
|
||||||
return Boolean.FALSE;
|
// return this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
// private final AuthorizationService authService;
|
||||||
|
|
||||||
|
public DescriptionTemplateTypeQuery(
|
||||||
|
UserScope userScope
|
||||||
|
//AuthorizationService authService
|
||||||
|
) {
|
||||||
|
this.userScope = userScope;
|
||||||
|
//this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,46 +99,58 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
protected Boolean isFalseQuery() {
|
||||||
List<Predicate> predicates = new ArrayList<>();
|
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds);
|
||||||
|
|
||||||
if (this.ids != null) {
|
|
||||||
CriteriaBuilder.In<UUID> 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<String> 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<Short> 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String fieldNameOf(FieldResolver item) {
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
if (this.ids != null) {
|
||||||
|
CriteriaBuilder.In<UUID> 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<Status> 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<UUID> 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set<String> columns) {
|
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set<String> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,60 @@
|
||||||
package eu.eudat.query.lookup;
|
package eu.eudat.query.lookup;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.Status;
|
||||||
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
||||||
import gr.cite.tools.data.query.Lookup;
|
import gr.cite.tools.data.query.Lookup;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DescriptionTemplateTypeLookup extends Lookup {
|
public class DescriptionTemplateTypeLookup extends Lookup {
|
||||||
|
|
||||||
private String name;
|
private String like;
|
||||||
|
private List<Status> isActive;
|
||||||
|
private List<UUID> ids;
|
||||||
|
private List<UUID> excludedIds;
|
||||||
|
|
||||||
private Short status;
|
public String getLike() {
|
||||||
|
return like;
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setLike(String like) {
|
||||||
this.name = name;
|
this.like = like;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getStatus() {
|
public List<Status> getIsActive() {
|
||||||
return status;
|
return isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setIsActive(List<Status> isActive) {
|
||||||
this.status = status;
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getIds() {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIds(List<UUID> ids) {
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getExcludedIds() {
|
||||||
|
return excludedIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcludedIds(List<UUID> excludeIds) {
|
||||||
|
this.excludedIds = excludeIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptionTemplateTypeQuery enrich(QueryFactory queryFactory) {
|
public DescriptionTemplateTypeQuery enrich(QueryFactory queryFactory) {
|
||||||
DescriptionTemplateTypeQuery query = queryFactory.query(DescriptionTemplateTypeQuery.class);
|
DescriptionTemplateTypeQuery query = queryFactory.query(DescriptionTemplateTypeQuery.class);
|
||||||
if (name != null) query.names(name);
|
if (this.like != null) query.like(this.like);
|
||||||
if (status != null ) query.statuses(status);
|
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;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,121 +1,18 @@
|
||||||
package eu.eudat.service;
|
package eu.eudat.service;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||||
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
|
||||||
import gr.cite.tools.exception.MyNotFoundException;
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import jakarta.persistence.EntityManager;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
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 java.util.List;
|
import javax.management.InvalidApplicationException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
public interface DescriptionTemplateTypeService {
|
||||||
public class DescriptionTemplateTypeService {
|
DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
||||||
|
|
||||||
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<DescriptionTemplateType> query(DescriptionTemplateTypeLookup lookup) {
|
|
||||||
DescriptionTemplateTypeQuery query = lookup.enrich(queryFactory);
|
|
||||||
List<DescriptionTemplateTypeEntity> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -301,7 +301,10 @@
|
||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
<artifactId>micrometer-core</artifactId>
|
<artifactId>micrometer-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<!--CITE DEPENDENCIES-->
|
<!--CITE DEPENDENCIES-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite</groupId>
|
<groupId>gr.cite</groupId>
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class Admin extends BaseController {
|
||||||
DatasetProfile shortenProfile = profile.toShort();
|
DatasetProfile shortenProfile = profile.toShort();
|
||||||
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
|
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
|
||||||
// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()));
|
// 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.setGroupId(UUID.randomUUID());
|
||||||
modelDefinition.setVersion((short) 0);
|
modelDefinition.setVersion((short) 0);
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,32 @@
|
||||||
package eu.eudat.controllers.v2;
|
package eu.eudat.controllers.v2;
|
||||||
|
|
||||||
import eu.eudat.audit.AuditableAction;
|
import eu.eudat.audit.AuditableAction;
|
||||||
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.model.DescriptionTemplateType;
|
import eu.eudat.model.DescriptionTemplateType;
|
||||||
|
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
||||||
import eu.eudat.model.censorship.DescriptionTemplateTypeCensor;
|
import eu.eudat.model.censorship.DescriptionTemplateTypeCensor;
|
||||||
|
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||||
import eu.eudat.model.result.QueryResult;
|
import eu.eudat.model.result.QueryResult;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.query.DescriptionTemplateTypeQuery;
|
||||||
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
|
||||||
import eu.eudat.service.DescriptionTemplateTypeService;
|
import eu.eudat.service.DescriptionTemplateTypeService;
|
||||||
import eu.eudat.types.Authorities;
|
import eu.eudat.types.Authorities;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
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.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.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import gr.cite.tools.validation.MyValidate;
|
||||||
import org.opensaml.xml.signature.Q;
|
import org.opensaml.xml.signature.Q;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -25,101 +35,102 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import javax.management.InvalidApplicationException;
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@Transactional
|
@RequestMapping(path = "api/description-template-type")
|
||||||
@RequestMapping(path = "api/v2/descriptionTemplateType", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public class DescriptionTemplateTypeV2Controller {
|
public class DescriptionTemplateTypeV2Controller {
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
|
||||||
|
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
private final AuditService auditService;
|
private final AuditService auditService;
|
||||||
|
|
||||||
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
||||||
|
private final CensorFactory censorFactory;
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
private final CensorFactory censorFactory;
|
@Autowired
|
||||||
|
public DescriptionTemplateTypeV2Controller(
|
||||||
public DescriptionTemplateTypeV2Controller(AuditService auditService, DescriptionTemplateTypeService descriptionTemplateTypeService, MessageSource messageSource, CensorFactory censorFactory) {
|
BuilderFactory builderFactory,
|
||||||
|
AuditService auditService,
|
||||||
|
DescriptionTemplateTypeService descriptionTemplateTypeService,
|
||||||
|
CensorFactory censorFactory,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
MessageSource messageSource) {
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
||||||
this.messageSource = messageSource;
|
|
||||||
this.censorFactory = censorFactory;
|
this.censorFactory = censorFactory;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("query")
|
@PostMapping("query")
|
||||||
public QueryResult<DescriptionTemplateType> query(@RequestBody DescriptionTemplateTypeLookup lookup, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
|
public QueryResult<DescriptionTemplateType> Query(@RequestBody DescriptionTemplateTypeLookup lookup) throws MyApplicationException, MyForbiddenException {
|
||||||
logger.debug("querying {}", DescriptionTemplateType.class.getSimpleName());
|
logger.debug("querying {}", DescriptionTemplateType.class.getSimpleName());
|
||||||
|
|
||||||
censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject());
|
//this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject(), null);
|
||||||
|
|
||||||
List<DescriptionTemplateType> models = descriptionTemplateTypeService.query(lookup);
|
DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory);
|
||||||
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? descriptionTemplateTypeService.count(lookup) : models.size();
|
//DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType);
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
|
List<DescriptionTemplateTypeEntity> data = query.collectAs(lookup.getProject());
|
||||||
|
//List<DescriptionTemplateType> models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrDescriptionTemplateType).build(lookup.getProject(), data);
|
||||||
|
List<DescriptionTemplateType> 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);
|
return new QueryResult<>(models, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
public QueryResult<DescriptionTemplateType> get(@PathVariable("id") UUID id, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
|
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));
|
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);
|
DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(id);
|
||||||
if (model == null)
|
DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(fieldSet, query.firstAs(fieldSet));
|
||||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
//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<String, Object>("id", id),
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
||||||
|
));
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
|
|
||||||
return new QueryResult<>(model);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("persist")
|
@PostMapping("persist")
|
||||||
public QueryResult<DescriptionTemplateType> persist(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
|
@Transactional
|
||||||
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
|
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);
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("model", model),
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries(
|
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", payload),
|
|
||||||
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
||||||
));
|
));
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
return new QueryResult<>(persisted);
|
return persisted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("update")
|
@DeleteMapping("{id}")
|
||||||
public QueryResult<DescriptionTemplateType> update(@RequestBody DescriptionTemplateType payload, FieldSet fieldSet, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
|
@Transactional
|
||||||
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", payload).And("fieldSet", fieldSet));
|
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(
|
this.auditService.track(AuditableAction.DescriptionTemplateType_Delete, "id", id);
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", payload),
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
|
||||||
));
|
|
||||||
|
|
||||||
return new QueryResult<>(persisted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class AdminManager {
|
||||||
|
|
||||||
DescriptionTemplateTypeEntity type;
|
DescriptionTemplateTypeEntity type;
|
||||||
try {
|
try {
|
||||||
type = descriptionTemplateTypeService.getEntityByName(profile.getType());
|
//TODO: dtziotzios type = descriptionTemplateTypeService.getEntityByName(profile.getType());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new Exception("Description template type '" + profile.getType() + "' could not be found.");
|
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())
|
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())
|
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
|
||||||
.type(type)
|
//TODO: dtziotzios .type(type)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (descriptionTemplate.getGroupId() == null) {
|
if (descriptionTemplate.getGroupId() == null) {
|
||||||
|
|
|
@ -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;
|
|
@ -1,8 +1,12 @@
|
||||||
|
import { Status } from "@app/core/common/enum/status";
|
||||||
import { Lookup } from "@common/model/lookup";
|
import { Lookup } from "@common/model/lookup";
|
||||||
|
import { Guid } from "@common/types/guid";
|
||||||
|
|
||||||
export class DescriptionTemplateTypeLookup extends Lookup {
|
export class DescriptionTemplateTypeLookup extends Lookup {
|
||||||
name: string;
|
ids: Guid[];
|
||||||
status: number;
|
excludedIds: Guid[];
|
||||||
|
like: string;
|
||||||
|
isActive: Status[];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { BaseHttpV2Service } from '../http/base-http-v2.service';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DescriptionTemplateTypeService {
|
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();
|
private headers = new HttpHeaders();
|
||||||
|
|
||||||
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService) {}
|
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService) {}
|
||||||
|
|
|
@ -150,7 +150,9 @@ export class DescriptionTypesDataSource extends DataSource<DescriptionTemplateTy
|
||||||
nameof<DescriptionTemplateType>(x => x.status)
|
nameof<DescriptionTemplateType>(x => x.status)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
lookup.order = {
|
||||||
|
items: ['name']
|
||||||
|
};
|
||||||
return this._service.query(lookup)
|
return this._service.query(lookup)
|
||||||
}),
|
}),
|
||||||
map(result => {
|
map(result => {
|
||||||
|
|
Loading…
Reference in New Issue