add ordinal in Language Entity

This commit is contained in:
amentis 2023-11-29 16:05:00 +02:00
parent 8bcc11d9a1
commit cabb35cf19
3 changed files with 46 additions and 28 deletions

View File

@ -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<String, Object>("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<String, Object>("code", code),
// new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
// ));
//
// return new ResponseEntity<>(model.getPayload().getBytes(), HttpStatus.OK);
// }
@PostMapping("available-languages")
public QueryResult<String> queryLanguageCodes(@RequestBody LanguageLookup lookup) {
logger.debug("querying {}", Language.class.getSimpleName());

View File

@ -36,11 +36,13 @@ export class LanguageHttpService {
catchError((error: any) => throwError(error)));
}
getPayload(code: string, reqFields: string[] = []): Observable<HttpResponse<Blob>> {
const url = `${this.apiBase}/get-payload/${code}`;
const options = { params: { f: reqFields }, responseType: 'blob', observe: 'response' };
getSingleWithCode(code: string, reqFields: string[] = []): Observable<Language> {
const url = `${this.apiBase}/code/${code}`;
const options = { params: { f: reqFields } };
return this.http.get(url, options);
return this.http
.get<Language>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
queryAvailableCodes(q: LanguageLookup): Observable<QueryResult<string>> {

View File

@ -76,7 +76,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
// Rest dependencies. Inject any other needed deps here:
public authService: AuthService,
public enumUtils: EnumUtils,
private languageV2Service: LanguageHttpService,
private languageHttpService: LanguageHttpService,
private logger: LoggingService,
private languageEditorService: LanguageEditorService,
private fileUtils: FileUtils,
@ -88,7 +88,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
ngOnInit(): void {
this.matomoService.trackPageView('Admin: Languages');
super.ngOnInit();
this.languageV2Service.queryAvailableCodes(this.languageV2Service.buildAutocompleteLookup())
this.languageHttpService.queryAvailableCodes(this.languageHttpService.buildAutocompleteLookup())
.pipe(takeUntil(this._destroyed))
.subscribe(
data => this.availableLanguageCodes = data.items,
@ -96,7 +96,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
}
getItem(itemId: Guid, successFunction: (item: Language) => 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,17 +107,14 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
prepareForm(data: Language) {
try {
if(data && data.payload == null){
this.languageV2Service.getPayload(data.code, LanguageEditorResolver.lookupFields())
this.languageHttpService.getSingleWithCode(data.code, LanguageEditorResolver.lookupFields())
.pipe(takeUntil(this._destroyed))
.subscribe(respone => {
const blob = new Blob([respone.body], { type: 'text/html' });
blob.text().then(text => {
data.payload = text;
.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();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
@ -156,7 +153,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
persistEntity(onSuccess?: (response) => 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<LanguageEditorModel, Lan
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
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<LanguageEditorModel, Lan
}
public selectedCodeChanged(code: string){
this.languageV2Service.getPayload(code, LanguageEditorResolver.lookupFields())
this.languageHttpService.getSingleWithCode(code, LanguageEditorResolver.lookupFields())
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
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);
});
}