From 56248bf409c083548ec51619bae82712ee4e3e5e Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 3 Jan 2024 16:10:14 +0100 Subject: [PATCH 1/3] JNG-5368 add access instance helper methods --- .../data-axios/accessServiceImpl.ts.hbs | 28 +++++++++++++++++-- .../rest/service/UiServiceHelper.java | 20 ++++++++++--- .../data-service/accessService.ts.hbs | 14 ++++++++-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs index 758a765..dc0258f 100644 --- a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs +++ b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs @@ -2,9 +2,9 @@ import type { AxiosResponse } from 'axios'; import type { JudoDownloadFile, JudoMetaData, JudoToken } from '../data-api/common'; +import type { AccessService } from '../data-service'; import { JudoAxiosService } from './JudoAxiosService'; -{{# if application.principal }}import type { {{ classDataName application.principal "Stored" }} } from '../data-api';{{/ if }} -import { AccessService } from '../data-service'; +import { {{ accessJoinedImportTokens application }} } from '../data-api'; export class AccessServiceImpl extends JudoAxiosService implements AccessService { {{# if application.principal }} @@ -69,4 +69,28 @@ export class AccessServiceImpl extends JudoAxiosService implements AccessService }); return response; } + {{# each (getAccessRelationsTypes application) as |relation| }} + {{# if relation.isListable }} + {{# if relation.isCollection }} + /** + * @return {Promise<{{ classDataName relation.target "Stored" }} | undefined>} + */ + async findInstanceOf{{ firstToUpper relation.name }}(identifier: string): Promise<{{ classDataName relation.target "Stored" }} | undefined> { + try { + const path = '{{ restPath (getRelationOwnerAsClassType relation) "/" relation.name "/~list" }}'; + const response = await this.axios.post(this.getPathForActor(path), { + _identifier: identifier, + }); + + if (Array.isArray(response.data) && response.data.length === 1) { + return response.data[0]; + } + return undefined; + } catch(error) { + return undefined; + } + } + {{/ if }} + {{/ if }} + {{/ each }} } diff --git a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java index db78f26..f3df253 100644 --- a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java +++ b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java @@ -36,18 +36,30 @@ @TemplateHelper public class UiServiceHelper extends StaticMethodValueResolver { - public static Collection getNotAccessRelationsTypes(Application application) { + public static List getNotAccessRelationsTypes(Application application) { return (List) application.getRelationTypes().stream() .filter(r -> !((RelationType) r).isIsAccess()) .sorted(Comparator.comparing(NamedElement::getFQName)) - .collect(Collectors.toList()); + .toList(); } - public static Collection getAccessRelationsTypes(Application application) { + public static List getAccessRelationsTypes(Application application) { return (List) application.getRelationTypes().stream() .filter(r -> ((RelationType) r).isIsAccess()) .sorted(Comparator.comparing(NamedElement::getFQName)) - .collect(Collectors.toList()); + .toList(); + } + + public static String accessJoinedImportTokens(Application application) { + HashSet tokens = new HashSet<>(); + if (application.getPrincipal() != null) { + tokens.add(classDataName(application.getPrincipal(), "Stored")); + } + List relations = getAccessRelationsTypes(application); + relations.forEach(relation -> { + tokens.add(classDataName(relation.getTarget(), "Stored")); + }); + return String.join(", ", tokens); } public static String joinedTokensForApiImport(RelationType relation){ diff --git a/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs b/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs index 6e22329..d027973 100644 --- a/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs +++ b/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs @@ -1,16 +1,24 @@ {{> fragment.header.hbs }} import type { JudoDownloadFile, JudoMetaData } from '../data-api/common'; -{{# if application.principal }}import { {{ classDataName application.principal "Stored" }} } from '../data-api';{{/ if }} +import { {{ accessJoinedImportTokens application }} } from '../data-api'; export interface AccessService { -{{# if application.principal }} + {{# if application.principal }} getPrincipal(): Promise<{{ classDataName application.principal "Stored" }}>; -{{/if}} + {{/ if }} getMetaData(): Promise; uploadFile(attributePath: string, file: File): Promise; downloadFile(downloadToken: string, disposition: 'inline' | 'attachment'): Promise; + + {{# each (getAccessRelationsTypes application) as |relation| }} + {{# if relation.isListable }} + {{# if relation.isCollection }} + findInstanceOf{{ firstToUpper relation.name }}(identifier: string): Promise<{{ classDataName relation.target "Stored" }} | undefined>; + {{/ if }} + {{/ if }} + {{/ each }} } From 680bd5d53e1f25a7ea88a8b20c62d01252fb6086 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 3 Jan 2024 16:45:37 +0100 Subject: [PATCH 2/3] JNG-5368 add mask param to API --- .../src/main/resources/data-axios/accessServiceImpl.ts.hbs | 7 +++++-- .../src/main/resources/data-service/accessService.ts.hbs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs index dc0258f..5eeedf3 100644 --- a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs +++ b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/accessServiceImpl.ts.hbs @@ -75,13 +75,16 @@ export class AccessServiceImpl extends JudoAxiosService implements AccessService /** * @return {Promise<{{ classDataName relation.target "Stored" }} | undefined>} */ - async findInstanceOf{{ firstToUpper relation.name }}(identifier: string): Promise<{{ classDataName relation.target "Stored" }} | undefined> { + async findInstanceOf{{ firstToUpper relation.name }}(identifier: string, mask?: string): Promise<{{ classDataName relation.target "Stored" }} | undefined> { try { const path = '{{ restPath (getRelationOwnerAsClassType relation) "/" relation.name "/~list" }}'; const response = await this.axios.post(this.getPathForActor(path), { _identifier: identifier, + _mask: mask, + _seek: { + limit: 1, + }, }); - if (Array.isArray(response.data) && response.data.length === 1) { return response.data[0]; } diff --git a/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs b/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs index d027973..76462b3 100644 --- a/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs +++ b/judo-ui-typescript-rest-service/src/main/resources/data-service/accessService.ts.hbs @@ -17,7 +17,7 @@ export interface AccessService { {{# each (getAccessRelationsTypes application) as |relation| }} {{# if relation.isListable }} {{# if relation.isCollection }} - findInstanceOf{{ firstToUpper relation.name }}(identifier: string): Promise<{{ classDataName relation.target "Stored" }} | undefined>; + findInstanceOf{{ firstToUpper relation.name }}(identifier: string, mask?: string): Promise<{{ classDataName relation.target "Stored" }} | undefined>; {{/ if }} {{/ if }} {{/ each }} From acde141280772ec3c88363c95ff7febdc892f281 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 3 Jan 2024 16:59:20 +0100 Subject: [PATCH 3/3] JNG-5368 fix review items --- .../typescript/rest/service/UiServiceHelper.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java index f3df253..64181ce 100644 --- a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java +++ b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java @@ -51,19 +51,17 @@ public static List getAccessRelationsTypes(Application application } public static String accessJoinedImportTokens(Application application) { - HashSet tokens = new HashSet<>(); + HashSet tokens = new LinkedHashSet<>(); if (application.getPrincipal() != null) { tokens.add(classDataName(application.getPrincipal(), "Stored")); } - List relations = getAccessRelationsTypes(application); - relations.forEach(relation -> { - tokens.add(classDataName(relation.getTarget(), "Stored")); - }); + getAccessRelationsTypes(application) + .forEach(relation -> tokens.add(classDataName(relation.getTarget(), "Stored"))); return String.join(", ", tokens); } public static String joinedTokensForApiImport(RelationType relation){ - HashSet tokens = new HashSet<>(); + HashSet tokens = new LinkedHashSet<>(); if (!relation.isIsAccess()) { tokens.add(classDataName((ClassType) relation.getOwner(), "")); @@ -105,7 +103,7 @@ private static void fillImportTokens(HashSet tokens, RelationType target } public static String joinedTokensForApiImportForAccessRelationServiceImpl(RelationType relation){ - HashSet tokens = new HashSet<>(); + HashSet tokens = new LinkedHashSet<>(); if (!relation.isIsAccess()) { tokens.add(classDataName((ClassType) relation.getOwner(), "")); @@ -124,7 +122,7 @@ public static String joinedTokensForApiImportForAccessRelationServiceImpl(Relati } public static String joinedTokensForApiImportClassService(ClassType classType){ - HashSet tokens = new HashSet<>(); + HashSet tokens = new LinkedHashSet<>(); tokens.add(classDataName(classType, "")); tokens.add(classDataName(classType, "Stored"));