From cabb35cf195e9448cc018657cad01c25c2840b6e Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 29 Nov 2023 16:05:00 +0200 Subject: [PATCH] add ordinal in Language Entity --- .../controllers/v2/LanguageV2Controller.java | 29 +++++++++++++-- .../language/language.http.service.ts | 10 +++--- .../editor/language-editor.component.ts | 35 ++++++++----------- 3 files changed, 46 insertions(+), 28 deletions(-) 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 801c6a8be..3167282f2 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("get-payload/{code}") - public ResponseEntity getPayload(@PathVariable("code") String code, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException { + @GetMapping("code/{code}") + public Language get(@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,9 +124,32 @@ public class LanguageV2Controller { new AbstractMap.SimpleEntry("fields", fieldSet) )); - return new ResponseEntity<>(model.getPayload().getBytes(), HttpStatus.OK); + return model; } +// @GetMapping("get-payload/code/{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); +// +// LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).codes(code); +// Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); +// +// if (model == null) +// throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, Language.class.getSimpleName()}, LocaleContextHolder.getLocale())); +// +// if (model.getPayload() == null){ +// model.setPayload(this.languageService.getPayload(code)); +// } +// this.auditService.track(AuditableAction.Language_Lookup, Map.ofEntries( +// new AbstractMap.SimpleEntry("code", code), +// new AbstractMap.SimpleEntry("fields", fieldSet) +// )); +// +// return new ResponseEntity<>(model.getPayload().getBytes(), HttpStatus.OK); +// } + @PostMapping("available-languages") public QueryResult queryLanguageCodes(@RequestBody LanguageLookup lookup) { logger.debug("querying {}", Language.class.getSimpleName()); diff --git a/dmp-frontend/src/app/core/services/language/language.http.service.ts b/dmp-frontend/src/app/core/services/language/language.http.service.ts index 38fbd8c21..0ca160433 100644 --- a/dmp-frontend/src/app/core/services/language/language.http.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.http.service.ts @@ -36,11 +36,13 @@ export class LanguageHttpService { catchError((error: any) => throwError(error))); } - getPayload(code: string, reqFields: string[] = []): Observable> { - const url = `${this.apiBase}/get-payload/${code}`; - const options = { params: { f: reqFields }, responseType: 'blob', observe: 'response' }; + getSingleWithCode(code: string, reqFields: string[] = []): Observable { + const url = `${this.apiBase}/code/${code}`; + const options = { params: { f: reqFields } }; - return this.http.get(url, options); + return this.http + .get(url, options).pipe( + catchError((error: any) => throwError(error))); } queryAvailableCodes(q: LanguageLookup): Observable> { 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 3daa934f3..8fd096efd 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 @@ -76,7 +76,7 @@ export class LanguageEditorComponent extends BaseEditor this.availableLanguageCodes = data.items, @@ -96,7 +96,7 @@ export class LanguageEditorComponent extends BaseEditor void) { - this.languageV2Service.getSingle(itemId, LanguageEditorResolver.lookupFields()) + this.languageHttpService.getSingle(itemId, LanguageEditorResolver.lookupFields()) .pipe(map(data => data as Language), takeUntil(this._destroyed)) .subscribe( data => successFunction(data), @@ -107,16 +107,13 @@ export class LanguageEditorComponent extends BaseEditor { - 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(); - }); + .subscribe(language => { + data.payload = language.payload; + 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(); @@ -156,7 +153,7 @@ export class LanguageEditorComponent extends BaseEditor void): void { const formData = this.formService.getValue(this.formGroup.value) as LanguagePersist; - this.languageV2Service.persist(formData) + this.languageHttpService.persist(formData) .pipe(takeUntil(this._destroyed)).subscribe( complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), error => this.onCallbackError(error) @@ -185,7 +182,7 @@ export class LanguageEditorComponent extends BaseEditor { if (result) { - this.languageV2Service.delete(value.id).pipe(takeUntil(this._destroyed)) + this.languageHttpService.delete(value.id).pipe(takeUntil(this._destroyed)) .subscribe( complete => this.onCallbackSuccess(), error => this.onCallbackError(error) @@ -201,14 +198,10 @@ export class LanguageEditorComponent extends BaseEditor { - const blob = new Blob([response.body], { type: 'text/html' }); - blob.text().then(text => { - this.formGroup.get('payload').patchValue(text); - }) - + .subscribe(language => { + this.formGroup.get('payload').patchValue(language.payload); }); }