From 2c914ead90ecb9bee75ce80d19af03dda213721a Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 29 Nov 2023 15:27:27 +0200 Subject: [PATCH] add ordinal in Language Entity --- .../java/eu/eudat/data/LanguageEntity.java | 12 +++++++++ .../main/java/eu/eudat/model/Language.java | 11 ++++++++ .../eudat/model/builder/LanguageBuilder.java | 1 + .../eudat/model/persist/LanguagePersist.java | 11 ++++++++ .../java/eu/eudat/query/LanguageQuery.java | 2 ++ .../service/language/LanguageServiceImpl.java | 1 + .../controllers/v2/LanguageV2Controller.java | 6 ++--- .../src/app/core/model/language/language.ts | 2 ++ .../services/language/language-v2.service.ts | 11 ++++---- .../editor/language-editor.component.html | 8 ++++++ .../editor/language-editor.component.ts | 25 ++++++++++++------- .../language/editor/language-editor.model.ts | 6 ++++- .../editor/language-editor.resolver.ts | 1 + .../supportive-material-editor.component.html | 3 +++ dmp-frontend/src/assets/i18n/en.json | 4 ++- 15 files changed, 84 insertions(+), 20 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java index 525998fe1..37923245c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java @@ -37,6 +37,10 @@ public class LanguageEntity { private IsActive isActive; public static final String _isActive = "isActive"; + @Column(name = "ordinal") + private Integer ordinal; + public static final String _ordinal = "ordinal"; + public UUID getId() { return id; } @@ -84,4 +88,12 @@ public class LanguageEntity { public void setIsActive(IsActive isActive) { this.isActive = isActive; } + + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Language.java b/dmp-backend/core/src/main/java/eu/eudat/model/Language.java index 0c99f8b14..e0bd91e07 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Language.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Language.java @@ -25,6 +25,9 @@ public class Language { private IsActive isActive; public static final String _isActive = "isActive"; + private Integer ordinal; + public static final String _ordinal = "ordinal"; + private String hash; public final static String _hash = "hash"; @@ -76,6 +79,14 @@ public class Language { this.isActive = isActive; } + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } + public String getHash() { return hash; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/LanguageBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/LanguageBuilder.java index 72fffb766..f7ff10ceb 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/LanguageBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/LanguageBuilder.java @@ -49,6 +49,7 @@ public class LanguageBuilder extends BaseBuilder{ if (fields.hasField(this.asIndexer(Language._id))) m.setId(d.getId()); if (fields.hasField(this.asIndexer(Language._code))) m.setCode(d.getCode()); if (fields.hasField(this.asIndexer(Language._payload))) m.setPayload(d.getPayload()); + if (fields.hasField(this.asIndexer(Language._ordinal))) m.setOrdinal(d.getOrdinal()); if (fields.hasField(this.asIndexer(Language._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(Language._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(Language._isActive))) m.setIsActive(d.getIsActive()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java index c24e7ada1..af86bab75 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java @@ -18,6 +18,9 @@ public class LanguagePersist { private String payload; + @NotNull(message = "{validation.empty}") + private Integer ordinal; + private String hash; public UUID getId() { @@ -44,6 +47,14 @@ public class LanguagePersist { this.payload = payload; } + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } + public String getHash() { return hash; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/LanguageQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/LanguageQuery.java index 32fd9cbd7..7ac85df97 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/LanguageQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/LanguageQuery.java @@ -161,6 +161,7 @@ public class LanguageQuery extends QueryBase { item.setId(QueryBase.convertSafe(tuple, columns, LanguageEntity._id, UUID.class)); item.setCode(QueryBase.convertSafe(tuple, columns, LanguageEntity._code, String.class)); item.setPayload(QueryBase.convertSafe(tuple, columns, LanguageEntity._payload, String.class)); + item.setOrdinal(QueryBase.convertSafe(tuple, columns, LanguageEntity._ordinal, Integer.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, LanguageEntity._createdAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, LanguageEntity._updatedAt, Instant.class)); item.setIsActive(QueryBase.convertSafe(tuple, columns, LanguageEntity._isActive, IsActive.class)); @@ -172,6 +173,7 @@ public class LanguageQuery extends QueryBase { if (item.match(Language._id)) return LanguageEntity._id; else if (item.match(Language._code)) return LanguageEntity._code; else if (item.match(Language._payload)) return LanguageEntity._payload; + else if (item.match(Language._ordinal)) return LanguageEntity._ordinal; else if (item.match(Language._createdAt)) return LanguageEntity._createdAt; else if (item.match(Language._updatedAt)) return LanguageEntity._updatedAt; else if (item.match(Language._hash)) return LanguageEntity._updatedAt; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java index 113e3f2eb..8d602f861 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java @@ -91,6 +91,7 @@ public class LanguageServiceImpl implements LanguageService { data.setCode(model.getCode()); data.setPayload(model.getPayload()); + data.setOrdinal(model.getOrdinal()); data.setUpdatedAt(Instant.now()); if (isUpdate) this.entityManager.merge(data); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java index ca361c401..801c6a8be 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java @@ -104,8 +104,8 @@ public class LanguageV2Controller { return model; } - @GetMapping("code/{code}") - public Language get(@PathVariable("code") String code, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException { + @GetMapping("get-payload/{code}") + public ResponseEntity getPayload(@PathVariable("code") String code, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException { logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("code", code).And("fields", fieldSet)); this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null); @@ -124,7 +124,7 @@ public class LanguageV2Controller { new AbstractMap.SimpleEntry("fields", fieldSet) )); - return model; + return new ResponseEntity<>(model.getPayload().getBytes(), HttpStatus.OK); } @PostMapping("available-languages") diff --git a/dmp-frontend/src/app/core/model/language/language.ts b/dmp-frontend/src/app/core/model/language/language.ts index 3203e130a..77f020db3 100644 --- a/dmp-frontend/src/app/core/model/language/language.ts +++ b/dmp-frontend/src/app/core/model/language/language.ts @@ -3,6 +3,7 @@ import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model"; export interface Language extends BaseEntity{ code: string; payload: string; + ordinal: number; } // Persist @@ -10,4 +11,5 @@ export interface Language extends BaseEntity{ export interface LanguagePersist extends BaseEntityPersist{ code: string; payload: string; + ordinal: number; } \ No newline at end of file diff --git a/dmp-frontend/src/app/core/services/language/language-v2.service.ts b/dmp-frontend/src/app/core/services/language/language-v2.service.ts index 0bbc1a824..64ada9fb9 100644 --- a/dmp-frontend/src/app/core/services/language/language-v2.service.ts +++ b/dmp-frontend/src/app/core/services/language/language-v2.service.ts @@ -12,6 +12,7 @@ import { catchError, map } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; +import { HttpResponse } from '@angular/common/http'; @Injectable() export class LanguageV2Service { @@ -35,13 +36,11 @@ export class LanguageV2Service { catchError((error: any) => throwError(error))); } - getSingleWithCode(code: string, reqFields: string[] = []): Observable { - const url = `${this.apiBase}/code/${code}`; - const options = { params: { f: reqFields } }; + getPayload(code: string, reqFields: string[] = []): Observable> { + const url = `${this.apiBase}/get-payload/${code}`; + const options = { params: { f: reqFields }, responseType: 'blob', observe: 'response' }; - return this.http - .get(url, options).pipe( - catchError((error: any) => throwError(error))); + return this.http.get(url, options); } queryAvailableCodes(q: LanguageLookup): Observable> { diff --git a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.html b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.html index 37b98b38b..f6f4f6899 100644 --- a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.html @@ -49,6 +49,14 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}} +
+ + {{'LANGUAGE-EDITOR.FIELDS.ORDINAL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
{{'LANGUAGE-EDITOR.FIELDS.PAYLOAD' | translate}} diff --git a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.ts b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.ts index d7f66a1ff..f3a980942 100644 --- a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.component.ts @@ -107,13 +107,16 @@ export class LanguageEditorComponent extends BaseEditor { - data.payload = language.payload; - this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel(); - this.isDeleted = data ? data.isActive === IsActive.Inactive : false; - this.buildForm(); + .subscribe(respone => { + const blob = new Blob([respone.body], { type: 'text/html' }); + blob.text().then(text => { + data.payload = text; + this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel(); + this.isDeleted = data ? data.isActive === IsActive.Inactive : false; + this.buildForm(); + }); }); }else{ this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel(); @@ -198,10 +201,14 @@ export class LanguageEditorComponent extends BaseEditor { - this.formGroup.get('payload').patchValue(language.payload); + .subscribe(response => { + const blob = new Blob([response.body], { type: 'text/html' }); + blob.text().then(text => { + this.formGroup.get('payload').patchValue(text); + }) + }); } diff --git a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.model.ts b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.model.ts index ff66e8802..7888758cf 100644 --- a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.model.ts @@ -8,6 +8,7 @@ import { Validation, ValidationContext } from "@common/forms/validation/validati export class LanguageEditorModel extends BaseEditorModel implements LanguagePersist { code: string; payload: string; + ordinal: number; permissions: string[]; @@ -21,6 +22,7 @@ export class LanguageEditorModel extends BaseEditorModel implements LanguagePers super.fromModel(item); this.code = item.code; this.payload = item.payload; + this.ordinal = item.ordinal; } return this; } @@ -31,7 +33,8 @@ export class LanguageEditorModel extends BaseEditorModel implements LanguagePers return this.formBuilder.group({ id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], - payload: [{ value: this.payload, disabled: disabled }, context.getValidation('payload').validators], + payload: [{ value: this.payload, disabled: disabled }, context.getValidation('payload').validators], + ordinal: [{ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators], hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] }); } @@ -42,6 +45,7 @@ export class LanguageEditorModel extends BaseEditorModel implements LanguagePers baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] }); baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] }); baseValidationArray.push({ key: 'payload', validators: [BackendErrorValidator(this.validationErrorModel, 'payload')] }); + baseValidationArray.push({ key: 'ordinal', validators: [Validators.required, Validators.pattern("^[0-9]*$"), BackendErrorValidator(this.validationErrorModel, 'ordinal')] }); baseValidationArray.push({ key: 'hash', validators: [] }); baseContext.validation = baseValidationArray; diff --git a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.resolver.ts index 25ea7e3a7..9f27d519d 100644 --- a/dmp-frontend/src/app/ui/admin/language/editor/language-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/language/editor/language-editor.resolver.ts @@ -21,6 +21,7 @@ export class LanguageEditorResolver extends BaseEditorResolver { nameof(x => x.id), nameof(x => x.code), nameof(x => x.payload), + nameof(x => x.ordinal), nameof(x => x.createdAt), nameof(x => x.updatedAt), nameof(x => x.hash), diff --git a/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.html b/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.html index ad1a281e6..588fbb9af 100644 --- a/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.html +++ b/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.html @@ -2,6 +2,9 @@
+ + {{'SUPPORTIVE-MATERIAL-EDITOR.TITLE' | translate}} +
diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index f9fc44bb3..8f7e1cd10 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -1175,6 +1175,7 @@ "UNSUCCESSFUL-DELETE": "This item could not be deleted." }, "SUPPORTIVE-MATERIAL-EDITOR": { + "TITLE": "Supportive Material", "FIELDS": { "MATERIAL-TYPE": "Material Type", "LANGUAGE": "Language" @@ -1189,7 +1190,8 @@ "NEW": "New Language", "FIELDS": { "CODE": "Code", - "PAYLOAD": "Payload" + "PAYLOAD": "Payload", + "ORDINAL": "Ordinal" }, "ACTIONS": { "SAVE": "Save",