diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 481ac10..ff94af2 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -432,6 +432,11 @@ } v++; } + ResourcePath accessResPath = new ResourcePath(accessRes.getPrimaryResourcePath()); + for (int i = 0; i < mainGetterParams.size(); i++) { + Parameter pathParam = new Parameter(mainGetterParams.get(i).getName()); + accessResPath.replacePathParam(i, pathParam, null); + } MethodDeclaration accessor = null; if (mainGetterParams.size() == 0) { accessor = langSpec.newMethodDeclaration(getterPrefix + getComponentName(accessRes.getResourceHierarchy(), langSpec), getImplStateType(accessRes.getResourceHierarchy(), langSpec)); @@ -439,7 +444,7 @@ accessor = langSpec.newMethodDeclaration(getterPrefix + getComponentName(accessRes.getResourceHierarchy(), langSpec), false, getImplStateType(accessRes.getResourceHierarchy(), langSpec), mainGetterParams); } Block block = new Block(); - Expression getState = getPullAccessor(platformSpec).getDirectStateAccessorFor(accessRes.getPrimaryResourcePath(), null); + Expression getState = getPullAccessor(platformSpec).getDirectStateAccessorFor(accessResPath, null); block.addStatement(langSpec.getReturnStatement(getState.toImplementation(new String[] {null})) + langSpec.getStatementDelimiter()); // if (stateGetter.getParameters() == null || stateGetter.getParameters().size() == 0) { // block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessRes.getResourceName(), stateGetter.getName())) + langSpec.getStatementDelimiter()); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 0c6c682..c09fbaa 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -2547,7 +2547,12 @@ if (rootInputAccessor != null) { // In the root resource // The expression of the receiver (resource) of the input method. - Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(out.getResource(), out.getResource().getRoot()); + ResourcePath outResPath = new ResourcePath(out.getResource()); + for (int i = 0; i < outResPath.getPathParams().size(); i++) { + Parameter pathParam = new Parameter(rootInputAccessor.getParameters().get(i).getName()); + outResPath.replacePathParam(i, pathParam, null); + } + Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(outResPath, outResPath.getRoot()); List args = new ArrayList<>(); if (resExp instanceof Term) { // to access the parent @@ -3034,7 +3039,11 @@ getImplStateType(resourceNode.getResourceHierarchy(), langSpec)); } getterAccessor.setBody(new Block()); - ResourcePath resPath = resourceNode.getPrimaryResourcePath(); + ResourcePath resPath = new ResourcePath(resourceNode.getPrimaryResourcePath()); + for (int i = 0; i < mainGetterParams.size(); i++) { + Parameter pathParam = new Parameter(mainGetterParams.get(i).getName()); + resPath.replacePathParam(i, pathParam, null); + } Expression getState = getPullAccessor(platformSpec).getDirectStateAccessorFor(resPath, resPath.getRoot()); getterAccessor.getBody().addStatement(langSpec.getReturnStatement(getState.toImplementation(new String[] {null})) + langSpec.getStatementDelimiter()); if (!platformSpec.isMonolithic()) { @@ -3054,6 +3063,11 @@ VariableDeclaration param; parameters = new ArrayList<>(); String resourcePath = getUpdateResourcePathAndPathParams(dstResPath, parameters, true, platformSpec, langSpec); // Path parameters to identify the self resource. + ResourcePath resPath = new ResourcePath(dstResPath); + for (int i = 0; i < parameters.size(); i++) { + Parameter pathParam = new Parameter(parameters.get(i).getName()); + resPath.replacePathParam(i, pathParam, null); + } for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { Variable selVar = (Variable) selector.getExpression(); @@ -3098,7 +3112,7 @@ if (!platformSpec.isMonolithic()) ((RestApiSpecific) platformSpec).addPathAnnotation(updateAccessor, resourcePath); // To make the accessor call the update method. - Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(cm.getResource(), cm.getResource().getRoot()); + Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(resPath, resPath.getRoot()); List args = new ArrayList<>(); if (resExp instanceof Term) { // to access the parent @@ -3108,18 +3122,8 @@ resExp = ((Term) resExp).getChild(0); } String resourceAccess = resExp.toImplementation(new String[] {""}); - int v = 0; for (VariableDeclaration var: updateAccessor.getParameters()) { - if (v < cm.getResource().getPathParams().size()) { - if (cm.getResource().getPathParams().get(v) instanceof Variable) { - args.add(((Variable) cm.getResource().getPathParams().get(v)).getName()); - } else if (cm.getResource().getPathParams().get(v) instanceof JsonAccessor) { - args.add(((JsonAccessor) cm.getResource().getPathParams().get(v)).toImplementation(new String[] {})); // ToDo. - } - } else { - args.add(var.getName()); - } - v++; + args.add(var.getName()); } updateAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, updateMethodName, args)); rootComponent.addMethod(updateAccessor); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index 61bb142..a5389bf 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -1070,6 +1070,11 @@ } v++; } + ResourcePath resPath = new ResourcePath(resourceNode.getPrimaryResourcePath()); + for (int i = 0; i < mainGetterParams.size(); i++) { + Parameter pathParam = new Parameter(mainGetterParams.get(i).getName()); + resPath.replacePathParam(i, pathParam, null); + } if (mainGetterParams.size() > 0) { getterAccessor = new MethodDeclaration("get" + getComponentName(resourceNode.getResourceHierarchy()), false, @@ -1080,7 +1085,7 @@ getImplStateType(resourceNode.getResourceHierarchy())); } getterAccessor.setBody(new Block()); - Expression getState = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(resourceNode.getPrimaryResourcePath(), null); + Expression getState = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(resPath, null); getterAccessor.getBody().addStatement("return " + getState.toImplementation(new String[] {null}) + ";"); mainComponent.addMethod(getterAccessor); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index bd709ef..8b087e9 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -458,7 +458,11 @@ getImplStateType(resourceNode.getResourceHierarchy())); } getterAccessor.setBody(new Block()); - ResourcePath resPath = resourceNode.getPrimaryResourcePath(); + ResourcePath resPath = new ResourcePath(resourceNode.getPrimaryResourcePath()); + for (int i = 0; i < mainGetterParams.size(); i++) { + Parameter pathParam = new Parameter(mainGetterParams.get(i).getName()); + resPath.replacePathParam(i, pathParam, null); + } Expression getState = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(resPath, resPath.getRoot()); getterAccessor.getBody().addStatement("return " + getState.toImplementation(new String[] {null}) + ";"); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index f9b5fa0..4432e40 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -295,7 +295,12 @@ MethodDeclaration update2 = update; update = getMethod(rootComponent, update2.getName()); // get the accessor to the update method. // To make the accessor call the update method. - Expression resExp = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(out.getResource(), out.getResource().getRoot()); + ResourcePath outResPath = new ResourcePath(out.getResource()); + for (int i = 0; i < outResPath.getPathParams().size(); i++) { + Parameter pathParam = new Parameter(update.getParameters().get(i).getName()); + outResPath.replacePathParam(i, pathParam, null); + } + Expression resExp = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(outResPath, outResPath.getRoot()); String args = ""; String delimiter = ""; if (resExp instanceof Term) { @@ -307,19 +312,9 @@ resExp = ((Term) resExp).getChild(0); } String resourceAccess = resExp.toImplementation(new String[] {""}); - int v = 0; for (VariableDeclaration var: update2.getParameters()) { - if (v < out.getResource().getPathParams().size()) { - if (out.getResource().getPathParams().get(v) instanceof Variable) { - args += delimiter + ((Variable) out.getResource().getPathParams().get(v)).getName(); - } else if (out.getResource().getPathParams().get(v) instanceof JsonAccessor) { - args += delimiter + ((JsonAccessor) out.getResource().getPathParams().get(v)).toImplementation(new String[] {}); // ToDo. - } - } else { - args += delimiter + var.getName(); - } + args += delimiter + var.getName(); delimiter = ", "; - v++; } update.addStatement(resourceAccess + "." + update2.getName() + "(" + args + ");"); } @@ -1304,8 +1299,13 @@ } MethodDeclaration inputAccessor = getMethod(componentMap.get(JerseyCodeGenerator.getComponentName(resource.getRoot())), inputAccessorName); if (inputAccessor != null) { + ResourcePath outResPath = new ResourcePath(out.getResource()); + for (int i = 0; i < outResPath.getPathParams().size(); i++) { + Parameter pathParam = new Parameter(inputAccessor.getParameters().get(i).getName()); + outResPath.replacePathParam(i, pathParam, null); + } // The expression of the receiver (resource) of the input method. - Expression resExp = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(out.getResource(), out.getResource().getRoot()); + Expression resExp = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(outResPath, outResPath.getRoot()); String args = ""; String delimiter = ""; if (resExp instanceof Term) {