Merge remote-tracking branch 'origin/dmp-refactoring' into dmp-refactoring

This commit is contained in:
George Kalampokis 2023-10-06 18:11:11 +03:00
commit b5cbe6a3d8
11 changed files with 115 additions and 23 deletions

View File

@ -0,0 +1,13 @@
package eu.eudat.audit;
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");
}

View File

@ -0,0 +1,36 @@
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 java.util.List;
import java.util.Map;
@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ValidationServiceImpl extends BaseValidationService {
private ErrorThesaurusProperties errors;
@Autowired
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors){
super(validator);
this.errors = errors;
}
@Override
public <T> void validateForce(T item, Class<?>... groups) {
List<Map.Entry<String, List<String>>> validationErrors = this.validate(item, groups);
if (validationErrors != null && !validationErrors.isEmpty()) {
throw new MyValidationException(this.errors.getModelValidation().getCode(),
this.errors.getModelValidation().getMessage(),
validationErrors);
}
}
}

View File

@ -1,11 +1,13 @@
package eu.eudat.service;
import eu.eudat.audit.AuditableAction;
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.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@ -28,27 +30,38 @@ public class DescriptionTemplateTypeService {
private final PlatformTransactionManager transactionManager;
private final AuditService auditService;
@PersistenceContext
private EntityManager entityManager;
public DescriptionTemplateTypeService(ApplicationContext applicationContext, BuilderFactory builderFactory, PlatformTransactionManager platformTransactionManager) {
public DescriptionTemplateTypeService(ApplicationContext applicationContext, BuilderFactory builderFactory, PlatformTransactionManager platformTransactionManager, AuditService auditService) {
this.applicationContext = applicationContext;
this.builderFactory = builderFactory;
this.transactionManager = platformTransactionManager;
this.auditService = auditService;
}
public List<DescriptionTemplateType> getAll(DescriptionTemplateTypeLookup lookup) {
public List<DescriptionTemplateType> query(DescriptionTemplateTypeLookup lookup) {
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
List<DescriptionTemplateType> results = builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
.build(lookup.getProject(), query.fromLookup(lookup).collect());
auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
return results;
}
public DescriptionTemplateType getById(UUID id) {
public DescriptionTemplateType get(UUID id) {
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
DescriptionTemplateType result = builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
.build(null, query.ids(id).first());
auditService.track(AuditableAction.DescriptionTemplateType_Query, "id", id);
return result;
}
public DescriptionTemplateTypeEntity getEntityByName(String name) {
@ -56,9 +69,8 @@ public class DescriptionTemplateTypeService {
return query.names(name).first();
}
public DescriptionTemplateType create(DescriptionTemplateType payload) {
public DescriptionTemplateType persist(DescriptionTemplateType payload) {
DescriptionTemplateTypeEntity created = new DescriptionTemplateTypeEntity();
created.setId(UUID.randomUUID());
created.setName(payload.getName());
created.setStatus(DescriptionTemplateTypeStatus.SAVED.getValue());
@ -79,6 +91,8 @@ public class DescriptionTemplateTypeService {
throw ex;
}
auditService.track(AuditableAction.DescriptionTemplateType_Persist, "persist", payload);
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
@ -91,6 +105,9 @@ public class DescriptionTemplateTypeService {
entity.setStatus(payload.getStatus());
entityManager.merge(entity);
entityManager.flush();
auditService.track(AuditableAction.DescriptionTemplateType_Persist, "update", payload);
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(null, entity);
}
@ -101,6 +118,9 @@ public class DescriptionTemplateTypeService {
entity.setStatus(DescriptionTemplateTypeStatus.DELETED.getValue());
entityManager.merge(entity);
entityManager.flush();
auditService.track(AuditableAction.DescriptionTemplateType_Delete, "delete", id);
return true;
}

View File

@ -314,6 +314,16 @@
<artifactId>exceptions</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>logging</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>validation</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,10 @@
package eu.eudat.configurations;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppMessageSourceConfiguration {
}

View File

@ -29,19 +29,19 @@ public class DescriptionTemplateTypeV2Controller {
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
}
@PostMapping("all")
public QueryResult<DescriptionTemplateType> getAll(@RequestBody DescriptionTemplateTypeLookup lookup, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
return extractQueryResultWithCount(descriptionTemplateTypeService::getAll, lookup);
@PostMapping("query")
public QueryResult<DescriptionTemplateType> query(@RequestBody DescriptionTemplateTypeLookup lookup, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
return extractQueryResultWithCount(descriptionTemplateTypeService::query, lookup);
}
@GetMapping("{id}")
public QueryResult<DescriptionTemplateType> get(@PathVariable("id") UUID id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal ignoredPrincipal) {
return new QueryResult<>(descriptionTemplateTypeService.getById(id));
return new QueryResult<>(descriptionTemplateTypeService.get(id));
}
@PostMapping("create")
public QueryResult<DescriptionTemplateType> create(@RequestBody DescriptionTemplateType payload, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
return new QueryResult<>(descriptionTemplateTypeService.create(payload));
@PostMapping("persist")
public QueryResult<DescriptionTemplateType> persist(@RequestBody DescriptionTemplateType payload, @ClaimedAuthorities(claims = {Authorities.ADMIN}) Principal ignoredPrincipal) {
return new QueryResult<>(descriptionTemplateTypeService.persist(payload));
}
@PostMapping("update")

View File

@ -8,6 +8,9 @@ spring.datasource.maxIdle=10
spring.datasource.minIdle=5
spring.datasource.maxActive=10
#####################AUDITING#####################################
audit.enable = false
####################ELASTIIC SEARCH TAGS OVERRIDES CONFIGURATIONS##########
elasticsearch.host = localhost
elasticsearch.port = 9200

View File

@ -15,18 +15,18 @@ export class DescriptionTemplateTypeService {
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService) {}
getAll(lookup: DescriptionTemplateTypeLookup): Observable<QueryResult<DescriptionTemplateType>> {
const url = `${this.apiBase}/all`;
query(lookup: DescriptionTemplateTypeLookup): Observable<QueryResult<DescriptionTemplateType>> {
const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<DescriptionTemplateType>>(url, lookup, { headers: this.headers });
}
getSingle(id: string): Observable<QueryResult<DescriptionTemplateType>> {
get(id: string): Observable<QueryResult<DescriptionTemplateType>> {
const url = `${this.apiBase}/${id}`;
return this.http.get<QueryResult<DescriptionTemplateType>>(url , { headers: this.headers });
}
create(payload: DescriptionTemplateType): Observable<QueryResult<DescriptionTemplateType>> {
const url = `${this.apiBase}/create`;
persist(payload: DescriptionTemplateType): Observable<QueryResult<DescriptionTemplateType>> {
const url = `${this.apiBase}/persist`;
return this.http.post<QueryResult<DescriptionTemplateType>>(url, payload, { headers: this.headers });
}

View File

@ -617,7 +617,7 @@ export class DatasetProfileEditorComponent extends CheckDeactivateBaseComponent
nameof<DescriptionTemplateType>(x => x.status)
]
};
this.descriptionTemplateTypeService.getAll(lookup).pipe(takeUntil(this._destroyed))
this.descriptionTemplateTypeService.query(lookup).pipe(takeUntil(this._destroyed))
.subscribe(types => {
this.descriptionTemplateTypes = types.items.filter(type => type.status === DescriptionTemplateTypeStatus.Finalized);
});

View File

@ -44,7 +44,7 @@ export class DescriptionTypeEditorComponent extends BaseComponent implements OnI
if (this.descriptionTemplateTypeId != null) {
this.isNew = false;
this.descriptionTemplateTypeService.getSingle(this.descriptionTemplateTypeId)
this.descriptionTemplateTypeService.get(this.descriptionTemplateTypeId)
.pipe(takeUntil(this._destroyed)).subscribe(
type => {
this.descriptionTypeModel = new DescriptionTypeEditorModel().fromModel(type.items[0]);
@ -84,7 +84,7 @@ export class DescriptionTypeEditorComponent extends BaseComponent implements OnI
onSubmit(): void {
if (this.isNew) {
this.descriptionTemplateTypeService.create(this.formGroup.value)
this.descriptionTemplateTypeService.persist(this.formGroup.value)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(true),

View File

@ -151,7 +151,7 @@ export class DescriptionTypesDataSource extends DataSource<DescriptionTemplateTy
]
};
return this._service.getAll(lookup)
return this._service.query(lookup)
}),
map(result => {
return result;