Skip to content

Commit

Permalink
JNG-4838 fix calloperation related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Nov 10, 2023
1 parent 0ce0e4a commit 75a66bb
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,48 @@ export class {{ serviceClassName classType }}Impl extends JudoAxiosService imple
});
}
{{/ if }}

{{# each relation.target.operations as | operation | }}
/**
* @throws {AxiosError}{{# if (hasFaults operation) }}With data containing {@link{{ faultContainerName operation }} } for business related errors (status code is 422).{{/ if }}
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 400, 401, 403.
*/
async {{ operation.name }}For{{ firstToUpper relation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName relation.target "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }},{{/ if }}target:{{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}> {
const path = '{{ operationRestPath relation.target operation '' }}';
const response = await this.axios.post(this.getPathForActor(path){{# if operation.input }}, target{{ else }}, undefined{{/ if }}{{# if operation.isMapped }}, {
headers: {
'X-Judo-SignedIdentifier': owner.__signedIdentifier!,
},
} {{/ if }});

{{# if operation.output }}
return response.data;
{{/ if }}
}

{{# if operation.input }}
{{# if operation.input.target.isTemplateable }}
async getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(): Promise<{{ classDataName operation.input.target "" }}> {
const path = '{{ restPath operation.input.target "/~template" "" "" }}';
const response = await this.axios.get(this.getPathForActor(path));

return response.data;
}
{{/ if }}
{{/ if }}

{{# if operation.isInputRangeable }}
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
*/
async getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(owner?: {{ classDataName relation.target "Stored" }}, queryCustomizer?:{{ classDataName operation.input.target "QueryCustomizer" }}): Promise<Array<{{ classDataName operation.input.target "Stored" }}>> {
const path = '{{ operationRestPath relation.target operation '/~range' }}';
const response = await this.axios.post(this.getPathForActor(path), { owner: owner ?? {}, queryCustomizer: queryCustomizer ?? {} });

return response.data;
}
{{/ if }}
{{/ each }}
{{/ each }}

{{# each classType.operations as | operation | }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,55 @@ export class {{ serviceRelationName relation }}Impl extends JudoAxiosService imp
}
{{/ neq }}
{{/ if }}

{{# each targetRelation.target.operations as | operation | }}
/**
* From: targetRelation.target.operations
* @throws {AxiosError}{{# if (hasFaults operation) }}With data containing {@link{{ faultContainerName operation }} } for business related errors (status code is 422).{{/ if }}
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 400, 401, 403.
*/
async {{ operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}>{{/ unless }}{{# if operation.input }}{{# unless operation.isStatic }}, {{/ unless }}target:{{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}> {
const path = '{{ operationRestPath relation.target operation '' }}';
const response = await this.axios.post(this.getPathForActor(path){{# if operation.input }}, target{{ else }}, undefined{{/ if }}{{# unless operation.isStatic }}, {
headers: {
'X-Judo-SignedIdentifier': owner.__signedIdentifier!,
},
} {{/ unless }});

{{# if operation.output }}
return response.data;
{{/ if }}
}

{{# if operation.input }}
{{# if operation.input.target.isTemplateable }}
async getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}(): Promise<{{ classDataName operation.input.target "" }}> {
const path = '{{ restPath operation.input.target "/~template" "" "" }}';
const response = await this.axios.get(this.getPathForActor(path));

return response.data;
}
{{/ if }}
{{/ if }}

{{# if operation.isInputRangeable }}
{{# neq relation.name targetRelation.name }}
/**
* From: targetRelation.target.operations operation.isInputRangeable
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
*/
async getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}> | {{ classDataName targetRelation.target "" }}, {{/ unless }}queryCustomizer?:{{ classDataName operation.input.target "QueryCustomizer" }}): Promise<Array<{{ classDataName operation.input.target "Stored" }}>> {
const path = '{{ operationRestPath targetRelation.target operation '/~range' }}';
const response = await this.axios.post(this.getPathForActor(path), {
{{# unless operation.isStatic }}owner: owner ?? {},{{/ unless }}
queryCustomizer: queryCustomizer ?? {}
});

return response.data;
}
{{/ neq }}
{{/ if }}
{{/ each }}
{{/ each }}

{{# each relation.target.operations as | operation | }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ public static String joinedTokensForApiImport(RelationType relation){
tokens.add(classDataName(targetRelation.getTarget(), "QueryCustomizer"));
tokens.add(classDataName(targetRelation.getTarget(), "Stored"));
tokens.add(classDataName(targetRelation.getTarget(), ""));

fillImportTokens(tokens, targetRelation);
}

for (OperationType operation: relation.getTarget().getOperations()) {
fillImportTokens(tokens, relation);

return String.join(", ", tokens);
}

private static void fillImportTokens(HashSet<String> tokens, RelationType targetRelation) {
for (OperationType operation: targetRelation.getTarget().getOperations()) {
if (operation.getInput() != null) {
tokens.add(classDataName(operation.getInput().getTarget(), ""));
tokens.add(classDataName(operation.getInput().getTarget(), "Stored"));
Expand All @@ -82,8 +90,6 @@ public static String joinedTokensForApiImport(RelationType relation){
tokens.add(classDataName(operation.getInput().getTarget(), ""));
}
}

return String.join(", ", tokens);
}

public static String joinedTokensForApiImportForAccessRelationServiceImpl(RelationType relation){
Expand Down Expand Up @@ -119,24 +125,32 @@ public static String joinedTokensForApiImportClassService(ClassType classType){
tokens.add(classDataName(relation.getTarget(), ""));
tokens.add(classDataName(relation.getTarget(),"Stored"));
tokens.add(classDataName(relation.getTarget(),"QueryCustomizer"));

for (OperationType operation: relation.getTarget().getOperations()) {
fillOperationTokens(operation, tokens);
}
}

for (OperationType operation: classType.getOperations()) {
if (operation.getInput() != null) {
tokens.add(classDataName(operation.getInput().getTarget(), ""));
}
fillOperationTokens(operation, tokens);
}

if (operation.getOutput() != null) {
tokens.add(classDataName(operation.getOutput().getTarget(), "Stored"));
}
return String.join(", ", tokens);
}

if (operation.getIsInputRangeable()) {
tokens.add(classDataName(operation.getInput().getTarget(), "QueryCustomizer"));
tokens.add(classDataName(operation.getInput().getTarget(), "Stored"));
}
private static void fillOperationTokens(OperationType operation, HashSet<String> tokens) {
if (operation.getInput() != null) {
tokens.add(classDataName(operation.getInput().getTarget(), ""));
}

return String.join(", ", tokens);
if (operation.getOutput() != null) {
tokens.add(classDataName(operation.getOutput().getTarget(), "Stored"));
}

if (operation.getIsInputRangeable()) {
tokens.add(classDataName(operation.getInput().getTarget(), "QueryCustomizer"));
tokens.add(classDataName(operation.getInput().getTarget(), "Stored"));
}
}

public static ClassType getRelationOwnerAsClassType(RelationType relationType){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ export interface {{ serviceClassName classType }} {
delete{{ firstToUpper relation.name }}(target: JudoIdentifiable<{{ classDataName relation.target "" }}>): Promise<void>;
{{/ if }}

{{# each relation.target.operations as | operation | }}
{{ operation.name }}For{{ firstToUpper relation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName relation.target "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }}, {{/ if }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>;

{{# if operation.input }}
{{# if operation.input.target.isTemplateable }}
getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(): Promise<{{ classDataName operation.input.target "" }}>;
{{/ if }}
{{/ if }}

{{# if operation.isInputRangeable }}
getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(owner?: {{ classDataName relation.target "Stored" }}, queryCustomizer?: {{ classDataName operation.input.target "QueryCustomizer" }}): Promise<Array<{{ classDataName operation.input.target "Stored" }}>>;
{{/ if }}
{{/ each }}

{{/ each }}
{{# each classType.operations as | operation | }}
{{ operation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName classType "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }}, {{/ if }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ export interface {{ serviceRelationName relation }} {
remove{{ firstToUpper targetRelation.name }}(owner: JudoIdentifiable<{{ classDataName relation.target "" }}>, selected: Array<JudoIdentifiable<{{ classDataName targetRelation.target "" }}>>): Promise<void>;
{{/ neq }}
{{/ if }}

{{# each targetRelation.target.operations as | operation | }}
{{ operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}>{{/ unless }}{{# if operation.input }}{{# unless operation.isStatic }}, {{/ unless }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>;

{{# if operation.input }}
{{# if operation.input.target.isTemplateable }}
getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}(): Promise<{{ classDataName operation.input.target "" }}>;
{{/ if }}
{{/ if }}

{{# if operation.isInputRangeable }}
{{# neq relation.name targetRelation.name }}
getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}> | {{ classDataName targetRelation.target "" }}, {{/ unless }}queryCustomizer?: {{ classDataName operation.input.target "QueryCustomizer" }}): Promise<Array<{{ classDataName operation.input.target "Stored" }}>>;
{{/ neq }}
{{/ if }}
{{/ each }}
{{/ each}}

{{# each relation.target.operations as | operation | }}
Expand Down

0 comments on commit 75a66bb

Please sign in to comment.