Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-09 14:26:49 +03:00
commit cae551ecc3
11 changed files with 31 additions and 28 deletions

View File

@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; 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 java.io.IOException; import java.io.IOException;
import java.net.URLConnection; import java.net.URLConnection;
@ -39,6 +40,7 @@ import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> { public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;

View File

@ -1,5 +1,8 @@
package org.opencdmp.model.builder.commonmodels.description; package org.opencdmp.model.builder.commonmodels.description;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetItemModel; import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetItemModel;
import org.opencdmp.commons.types.description.PropertyDefinitionFieldSetItemEntity; import org.opencdmp.commons.types.description.PropertyDefinitionFieldSetItemEntity;
@ -8,9 +11,6 @@ import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder; import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse; import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
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.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseCommonModelBuilder<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity> { public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseCommonModelBuilder<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity> {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -66,8 +66,8 @@ public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseC
if (d.getFields() != null && !d.getFields().isEmpty()) { if (d.getFields() != null && !d.getFields().isEmpty()) {
m.setFields(new HashMap<>()); m.setFields(new HashMap<>());
for (String key : d.getFields().keySet()){ for (String key : d.getFields().keySet()){
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null; FieldEntity fieldEntity = this.fieldSetEntity != null ? this.fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key))); m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).useSharedStorage(this.useSharedStorage).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key)));
} }
} }
models.add(new CommonModelBuilderItemResponse<>(m, d)); models.add(new CommonModelBuilderItemResponse<>(m, d));

View File

@ -12,12 +12,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; 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 java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefaultValueCommonModelBuilder extends BaseCommonModelBuilder<DefaultValueModel, DefaultValueEntity> { public class DefaultValueCommonModelBuilder extends BaseCommonModelBuilder<DefaultValueModel, DefaultValueEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);

View File

@ -48,6 +48,12 @@ public class DefaultValuePersist {
this.booleanValue = booleanValue; this.booleanValue = booleanValue;
} }
public Boolean isNullOrEmpty(){
if ((this.textValue == null || this.textValue.isEmpty()) && this.dateValue == null && this.booleanValue == null) return true;
return false;
}
@Component(DefaultValuePersistValidator.ValidatorName) @Component(DefaultValuePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DefaultValuePersistValidator extends BaseValidator<DefaultValuePersist> { public static class DefaultValuePersistValidator extends BaseValidator<DefaultValuePersist> {

View File

@ -413,7 +413,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValuePersist persist, FieldEntity fieldEntity) { private @NotNull DefaultValueEntity buildDefaultValueEntity(DefaultValuePersist persist, FieldEntity fieldEntity) {
FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
DefaultValueEntity data = new DefaultValueEntity(); DefaultValueEntity data = new DefaultValueEntity();
if (persist == null) return data; if (persist == null || persist.isNullOrEmpty()) return data;
if (FieldType.isTextType(fieldType) || FieldType.isTextListType(fieldType)) { if (FieldType.isTextType(fieldType) || FieldType.isTextListType(fieldType)) {
if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())) throw new NotImplementedException("Upload not supported"); if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())) throw new NotImplementedException("Upload not supported");

View File

@ -20,31 +20,31 @@ public class FileTransformerRepository implements FileTransformerClient {
@Override @Override
public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) { public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) {
return transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel) return this.transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block(); .exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block();
} }
@Override @Override
public DmpModel importDmp(FileEnvelopeModel fileEnvelope) { public DmpModel importDmp(FileEnvelopeModel fileEnvelope) {
return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope) return this.transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DmpModel.class)).block(); .exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DmpModel.class)).block();
} }
@Override @Override
public FileEnvelopeModel exportDescription(DescriptionModel descriptionModel, String format) { public FileEnvelopeModel exportDescription(DescriptionModel descriptionModel, String format) {
return transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionModel) return this.transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionModel)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block(); .exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block();
} }
@Override @Override
public DescriptionModel importDescription(FileEnvelopeModel fileEnvelope) { public DescriptionModel importDescription(FileEnvelopeModel fileEnvelope) {
return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope) return this.transformerClient.post().uri("/import/description").bodyValue(fileEnvelope)
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DescriptionModel.class)).block(); .exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DescriptionModel.class)).block();
} }
@Override @Override
public FileTransformerConfiguration getConfiguration() { public FileTransformerConfiguration getConfiguration() {
return transformerClient.get().uri("/formats") return this.transformerClient.get().uri("/formats")
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(new ParameterizedTypeReference<FileTransformerConfiguration>() {})).block(); .exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(new ParameterizedTypeReference<FileTransformerConfiguration>() {})).block();
} }

View File

@ -141,7 +141,7 @@ public class MaintenanceServiceImpl implements MaintenanceService {
private void sendTenantDmpTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException { private void sendTenantDmpTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException {
try { try {
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode); this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode);
List<DmpEntity> items = this.queryFactory.query(DmpQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._isActive)); List<DmpEntity> items = this.queryFactory.query(DmpQuery.class).disableTracking().collectAs(new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._isActive));
for (DmpEntity item : items) { for (DmpEntity item : items) {
if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDmp(item.getId()); if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDmp(item.getId());
else this.annotationEntityRemovalIntegrationEventHandler.handleDmp(item.getId()); else this.annotationEntityRemovalIntegrationEventHandler.handleDmp(item.getId());
@ -171,7 +171,7 @@ public class MaintenanceServiceImpl implements MaintenanceService {
private void sendTenantDescriptionTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException { private void sendTenantDescriptionTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException {
try { try {
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode); this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode);
List<DescriptionEntity> items = this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id).ensure(Description._isActive)); List<DescriptionEntity> items = this.queryFactory.query(DescriptionQuery.class).disableTracking().collectAs(new BaseFieldSet().ensure(Description._id).ensure(Description._isActive));
for (DescriptionEntity item : items) { for (DescriptionEntity item : items) {
if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDescription(item.getId()); if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDescription(item.getId());
else this.annotationEntityRemovalIntegrationEventHandler.handleDescription(item.getId()); else this.annotationEntityRemovalIntegrationEventHandler.handleDescription(item.getId());

View File

@ -87,7 +87,8 @@ export class DescriptionFormFieldComponent extends BaseComponent implements OnIn
public dialog: MatDialog, public dialog: MatDialog,
private fileUtils: FileUtils, private fileUtils: FileUtils,
private referenceService: ReferenceService, private referenceService: ReferenceService,
private storageFileService: StorageFileService private storageFileService: StorageFileService,
private changeDetectorRef: ChangeDetectorRef
) { ) {
super(); super();
} }
@ -117,15 +118,6 @@ export class DescriptionFormFieldComponent extends BaseComponent implements OnIn
} }
} }
checkBoxChanged(event: MatCheckboxChange){
if (event.checked){
this.propertiesFormGroup?.get(this.field.id).get('textValue').setValue("true");
} else{
this.propertiesFormGroup?.get(this.field.id).get('textValue').setValue("false");
}
this.visibilityRulesService.reloadVisibility();
}
private applyFieldType(){ private applyFieldType(){
this.isRequired = this.field.validations?.includes(DescriptionTemplateFieldValidationType.Required); this.isRequired = this.field.validations?.includes(DescriptionTemplateFieldValidationType.Required);
@ -287,6 +279,7 @@ export class DescriptionFormFieldComponent extends BaseComponent implements OnIn
private createFileNameDisplay(name: string, extension: string){ private createFileNameDisplay(name: string, extension: string){
if (extension.startsWith('.')) this.fileNameDisplay = name + extension; if (extension.startsWith('.')) this.fileNameDisplay = name + extension;
else this.fileNameDisplay = name + '.' + extension; else this.fileNameDisplay = name + '.' + extension;
this.changeDetectorRef.markForCheck();
} }

View File

@ -33,7 +33,7 @@
<div *ngIf="section?.sections?.length > 0" class="col-12"> <div *ngIf="section?.sections?.length > 0" class="col-12">
<ng-container *ngFor="let innerSection of section.sections; let j = index;"> <ng-container *ngFor="let innerSection of section.sections; let j = index;">
<div class="row" *ngIf="visibilityRulesService.isVisibleMap[innerSection.id]"> <div class="row" *ngIf="visibilityRulesService.isVisibleMap[innerSection.id]">
<app-description-form-section class="col-12" [section]="innerSection" [canReview]="canReview" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j" (askedToScroll)="onAskedToScroll($event)" [propertiesFormGroup]="propertiesFormGroup" [descriptionId]="descriptionId" [visibilityRulesService]="visibilityRulesService" [linkToScroll]="subsectionLinkToScroll"></app-description-form-section> <app-description-form-section class="col-12" [section]="innerSection" [canReview]="canReview" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j" (askedToScroll)="onAskedToScroll(null, $event)" [propertiesFormGroup]="propertiesFormGroup" [descriptionId]="descriptionId" [visibilityRulesService]="visibilityRulesService" [linkToScroll]="subsectionLinkToScroll"></app-description-form-section>
</div> </div>
</ng-container> </ng-container>
</div> </div>

View File

@ -70,7 +70,7 @@ export class DescriptionFormSectionComponent extends BaseComponent implements On
} }
onAskedToScroll(event:MouseEvent, id: string) { onAskedToScroll(event:MouseEvent, id: string) {
event.stopPropagation(); event?.stopPropagation();
this.panelExpanded = true; this.panelExpanded = true;
this.askedToScroll.emit(id); this.askedToScroll.emit(id);
} }

View File

@ -228,7 +228,7 @@
</ng-container> </ng-container>
</div> </div>
</div> </div>
<div *ngIf="canSave" class="col-12 col-xl-auto"> <div *ngIf="canSave || isNew" class="col-12 col-xl-auto">
<button [disabled]="!this.canSave" mat-icon-button class="action-list-icon" matTooltip="{{'DMP-EDITOR.ACTIONS.REMOVE-CONTACT' | translate}}" (click)="removeContact(contactIndex)" [disabled]="formGroup.disabled"> <button [disabled]="!this.canSave" mat-icon-button class="action-list-icon" matTooltip="{{'DMP-EDITOR.ACTIONS.REMOVE-CONTACT' | translate}}" (click)="removeContact(contactIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
@ -239,7 +239,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<button mat-icon-button (click)="addContact()" [disabled]="!this.canSave"> <button mat-icon-button (click)="addContact()" [disabled]="!this.canSave && !isNew">
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
</button> </button>
</div> </div>