From 09067c11dd6ce37e62ee42221da305d3541cae20 Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 15 May 2024 16:29:11 +0300 Subject: [PATCH 1/2] add url validation in free text --- .../descriptionproperties/FieldPersist.java | 19 +++++++++++++++++++ .../src/main/resources/messages.properties | 3 ++- .../form-field/form-field.component.ts | 8 +++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java index 0ffead771..aaa3a2fa0 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java @@ -15,6 +15,9 @@ import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; import java.time.Instant; import java.util.Arrays; import java.util.List; @@ -125,12 +128,17 @@ public class FieldPersist { protected List specifications(FieldPersist item) { FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; boolean required = this.fieldEntity != null && this.fieldEntity.getValidations() != null ? this.fieldEntity.getValidations().contains(FieldValidationType.Required) : false; + boolean isUrlRequired = this.fieldEntity != null && this.fieldEntity.getValidations() != null ? this.fieldEntity.getValidations().contains(FieldValidationType.Url) : false; boolean isVisible = this.fieldEntity != null ? this.visibilityService.isVisible(this.fieldEntity.getId(), this.ordinal) : true; return Arrays.asList( this.spec() .iff(()-> FieldType.isTextType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isEmpty(item.getTextValue())) .failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), + this.spec() + .iff(()-> fieldType.equals(FieldType.FREE_TEXT) && DescriptionStatus.Finalized.equals(this.status) && isVisible && isUrlRequired) + .must(() -> this.isValidURL(item.getTextValue())) + .failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_UrlRequired", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isNull(item.getDateValue())) @@ -196,6 +204,17 @@ public class FieldPersist { this.ordinal = ordinal; return this; } + + boolean isValidURL(String url){ + try { + new URL(url).toURI(); + return true; + } catch (MalformedURLException e) { + return false; + } catch (URISyntaxException e) { + return false; + } + } } } diff --git a/backend/web/src/main/resources/messages.properties b/backend/web/src/main/resources/messages.properties index ec9508b6f..d590e2ebc 100644 --- a/backend/web/src/main/resources/messages.properties +++ b/backend/web/src/main/resources/messages.properties @@ -26,4 +26,5 @@ Validation.LessThenEqual= value {0} must be equal or less than {1} Validation.LargerThenEqual= value {0} must be equal or larger than {1} Validation.MissingFields= missing fields: {0} Validation.InvalidDescriptionTemplateMultiplicity= {0} can not be used -Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors \ No newline at end of file +Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors +Validation_UrlRequired={0} is not valid url \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts index a4eed8824..19ada7038 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts @@ -1,11 +1,12 @@ import { COMMA, ENTER } from '@angular/cdk/keycodes'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, SimpleChanges } from '@angular/core'; -import { UntypedFormControl, UntypedFormGroup } from '@angular/forms'; +import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { MatCheckboxChange } from '@angular/material/checkbox'; import { MatDialog } from "@angular/material/dialog"; import { DescriptionTemplateFieldType } from '@app/core/common/enum/description-template-field-type'; import { DescriptionTemplateFieldValidationType } from '@app/core/common/enum/description-template-field-validation-type'; +import { ValidatorURL } from '@app/core/common/enum/validation-type'; import { DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateLabelAndMultiplicityData, DescriptionTemplateUploadData } from '@app/core/model/description-template/description-template'; import { StorageFile } from '@app/core/model/storage-file/storage-file'; import { DescriptionService } from '@app/core/services/description/description.service'; @@ -122,6 +123,11 @@ export class DescriptionFormFieldComponent extends BaseComponent implements OnIn this.isRequired = this.field.validations?.includes(DescriptionTemplateFieldValidationType.Required); switch (this.field?.data?.fieldType) { + case DescriptionTemplateFieldType.FREE_TEXT: + const isUrlRequired = this.field.validations?.includes(DescriptionTemplateFieldValidationType.Url) || false; + if (isUrlRequired) this.propertiesFormGroup?.get(this.field.id).get('textValue').addValidators(ValidatorURL.validator) + break; + case DescriptionTemplateFieldType.TAGS: this.tagsAutoCompleteConfiguration = { filterFn: this.filterTags.bind(this), From d7759fe4bd8dd088ea950cbe6c01b2eff5a69f67 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 15 May 2024 16:40:49 +0300 Subject: [PATCH 2/2] add maxInMemorySizeInBytes --- .../types/deposit/DepositSourceEntity.java | 25 +++++++++++++------ .../FileTransformerSourceEntity.java | 21 +++++++++++----- .../service/deposit/DepositServiceImpl.java | 7 ++++-- .../FileTransformerServiceImpl.java | 5 +++- .../main/resources/config/deposit-devel.yml | 4 ++- .../config/file-transformer-devel.yml | 6 +++-- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/deposit/DepositSourceEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/deposit/DepositSourceEntity.java index 0aef2fe0e..d67741bc9 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/deposit/DepositSourceEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/deposit/DepositSourceEntity.java @@ -10,9 +10,10 @@ public class DepositSourceEntity { private String scope; private String pdfTransformerId; private String rdaTransformerId; + private int maxInMemorySizeInBytes; public String getRepositoryId() { - return repositoryId; + return this.repositoryId; } public void setRepositoryId(String repositoryId) { @@ -20,7 +21,7 @@ public class DepositSourceEntity { } public String getUrl() { - return url; + return this.url; } public void setUrl(String url) { @@ -28,7 +29,7 @@ public class DepositSourceEntity { } public String getIssuerUrl() { - return issuerUrl; + return this.issuerUrl; } public void setIssuerUrl(String issuerUrl) { @@ -36,7 +37,7 @@ public class DepositSourceEntity { } public String getClientId() { - return clientId; + return this.clientId; } public void setClientId(String clientId) { @@ -44,7 +45,7 @@ public class DepositSourceEntity { } public String getClientSecret() { - return clientSecret; + return this.clientSecret; } public void setClientSecret(String clientSecret) { @@ -52,7 +53,7 @@ public class DepositSourceEntity { } public String getScope() { - return scope; + return this.scope; } public void setScope(String scope) { @@ -60,7 +61,7 @@ public class DepositSourceEntity { } public String getPdfTransformerId() { - return pdfTransformerId; + return this.pdfTransformerId; } public void setPdfTransformerId(String pdfTransformerId) { @@ -68,10 +69,18 @@ public class DepositSourceEntity { } public String getRdaTransformerId() { - return rdaTransformerId; + return this.rdaTransformerId; } public void setRdaTransformerId(String rdaTransformerId) { this.rdaTransformerId = rdaTransformerId; } + + public int getMaxInMemorySizeInBytes() { + return this.maxInMemorySizeInBytes; + } + + public void setMaxInMemorySizeInBytes(int maxInMemorySizeInBytes) { + this.maxInMemorySizeInBytes = maxInMemorySizeInBytes; + } } diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/filetransformer/FileTransformerSourceEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/filetransformer/FileTransformerSourceEntity.java index fa34a4f7d..c60a4a2be 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/filetransformer/FileTransformerSourceEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/filetransformer/FileTransformerSourceEntity.java @@ -8,9 +8,10 @@ public class FileTransformerSourceEntity { private String clientId; private String clientSecret; private String scope; + private int maxInMemorySizeInBytes; public String getUrl() { - return url; + return this.url; } public void setUrl(String url) { @@ -18,7 +19,7 @@ public class FileTransformerSourceEntity { } public String getTransformerId() { - return transformerId; + return this.transformerId; } public void setTransformerId(String transformerId) { @@ -26,7 +27,7 @@ public class FileTransformerSourceEntity { } public String getIssuerUrl() { - return issuerUrl; + return this.issuerUrl; } public void setIssuerUrl(String issuerUrl) { @@ -34,7 +35,7 @@ public class FileTransformerSourceEntity { } public String getClientId() { - return clientId; + return this.clientId; } public void setClientId(String clientId) { @@ -42,7 +43,7 @@ public class FileTransformerSourceEntity { } public String getClientSecret() { - return clientSecret; + return this.clientSecret; } public void setClientSecret(String clientSecret) { @@ -50,10 +51,18 @@ public class FileTransformerSourceEntity { } public String getScope() { - return scope; + return this.scope; } public void setScope(String scope) { this.scope = scope; } + + public int getMaxInMemorySizeInBytes() { + return this.maxInMemorySizeInBytes; + } + + public void setMaxInMemorySizeInBytes(int maxInMemorySizeInBytes) { + this.maxInMemorySizeInBytes = maxInMemorySizeInBytes; + } } \ No newline at end of file diff --git a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java index dc9b170c3..6a34f06a9 100644 --- a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java @@ -158,8 +158,11 @@ public class DepositServiceImpl implements DepositService { exchangeFilterFunctions.add(apiKeyExchangeFilterFunction); exchangeFilterFunctions.add(logRequest()); exchangeFilterFunctions.add(logResponse()); - }).build(); - DepositClientImpl repository = new DepositClientImpl(webClient); + }).codecs(codecs -> codecs + .defaultCodecs() + .maxInMemorySize(source.getMaxInMemorySizeInBytes()) + ).build(); + DepositClientImpl repository = new DepositClientImpl(webClient); this.clients.put(repositoryIdByTenant, repository); return repository; } diff --git a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java index 875439623..29553f216 100644 --- a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java @@ -109,7 +109,10 @@ public class FileTransformerServiceImpl implements FileTransformerService { exchangeFilterFunctions.add(tokenExchangeFilterFunction); exchangeFilterFunctions.add(logRequest()); exchangeFilterFunctions.add(logResponse()); - }).build()); + }).codecs(codecs -> codecs + .defaultCodecs() + .maxInMemorySize(source.getMaxInMemorySizeInBytes()) + ).build()); this.clients.put(repositoryIdByTenant, repository); return repository; } diff --git a/backend/web/src/main/resources/config/deposit-devel.yml b/backend/web/src/main/resources/config/deposit-devel.yml index 79d67a7d0..6eb01fe91 100644 --- a/backend/web/src/main/resources/config/deposit-devel.yml +++ b/backend/web/src/main/resources/config/deposit-devel.yml @@ -8,6 +8,7 @@ deposit: client-id: ${IDP_APIKEY_CLIENT_ID} client-secret: ${IDP_APIKEY_CLIENT_SECRET} scope: ${IDP_APIKEY_SCOPE} + maxInMemorySizeInBytes: 6554000 - url: http://dev04.local.cite.gr:55330/zenodo1 repositoryId: Zenodo1 pdfTransformerId: docx-file-transformer @@ -15,4 +16,5 @@ deposit: issuer-url: ${IDP_ISSUER_URI_TOKEN} client-id: ${IDP_APIKEY_CLIENT_ID} client-secret: ${IDP_APIKEY_CLIENT_SECRET} - scope: ${IDP_APIKEY_SCOPE} \ No newline at end of file + scope: ${IDP_APIKEY_SCOPE} + maxInMemorySizeInBytes: 6554000 \ No newline at end of file diff --git a/backend/web/src/main/resources/config/file-transformer-devel.yml b/backend/web/src/main/resources/config/file-transformer-devel.yml index 91120d01d..c7111db5b 100644 --- a/backend/web/src/main/resources/config/file-transformer-devel.yml +++ b/backend/web/src/main/resources/config/file-transformer-devel.yml @@ -1,14 +1,16 @@ file-transformer: sources: - - url: http://dev04.local.cite.gr:55330/file/docx + - url: http://localhost:8084 transformerId: docx-file-transformer issuer-url: ${IDP_ISSUER_URI_TOKEN} client-id: ${IDP_APIKEY_CLIENT_ID} client-secret: ${IDP_APIKEY_CLIENT_SECRET} scope: ${IDP_APIKEY_SCOPE} + maxInMemorySizeInBytes: 6554000 - url: http://dev04.local.cite.gr:55330/file/rdajson transformerId: rda-file-transformer issuer-url: ${IDP_ISSUER_URI_TOKEN} client-id: ${IDP_APIKEY_CLIENT_ID} client-secret: ${IDP_APIKEY_CLIENT_SECRET} - scope: ${IDP_APIKEY_SCOPE} \ No newline at end of file + scope: ${IDP_APIKEY_SCOPE} + maxInMemorySizeInBytes: 6554000 \ No newline at end of file