diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java index bc6363c..def1f43 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java @@ -70,7 +70,7 @@ // Declare the field to refer each resource in the main type. TypeDeclaration type = new TypeDeclaration(resourceName); -// type.addAnnotation(new Annotation("Component")); + type.addAnnotation(new Annotation("Component")); type.addAnnotation(new Annotation("Path", "\"/" + rn.getIdentifierTemplate().getResourceName() + "\"")); // Declare a client field and update methods from other resources. @@ -98,11 +98,12 @@ // Declare an update method in the type of the destination resource. ArrayList vars = new ArrayList<>(); String srcName = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName(); - VariableDeclaration param = new VariableDeclaration(((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(), srcName); + Type srcType = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(); + VariableDeclaration param = new VariableDeclaration(srcType, srcName); param.addAnnotation(new Annotation("FormParam", "\"" + srcName + "\"")); vars.add(param); MethodDeclaration update = new MethodDeclaration("update" + srcResName, false, typeVoid, vars); - if (((StoreAttribute) rn.getAttribute()).isNeeded()) { + if (((StoreAttribute) rn.getAttribute()).isStored()) { update.addAnnotation(new Annotation("POST")); } else { update.addAnnotation(new Annotation("PUT")); @@ -138,7 +139,11 @@ MethodDeclaration input = new MethodDeclaration( ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(), false, typeVoid, params); - input.addAnnotation(new Annotation("PUT")); + if (((StoreAttribute) rn.getAttribute()).isNeeded()) { + input.addAnnotation(new Annotation("POST")); + } else { + input.addAnnotation(new Annotation("PUT")); + } type.addMethod(input); } } @@ -166,6 +171,10 @@ cu.addImport(new ImportDeclaration("javax.ws.rs.*")); cu.addImport(new ImportDeclaration("javax.ws.rs.client.*")); cu.addImport(new ImportDeclaration("javax.ws.rs.core.*")); + cu.addImport(new ImportDeclaration("org.springframework.stereotype.Component")); + cu.addImport(new ImportDeclaration("com.fasterxml.jackson.databind.ObjectMapper")); + cu.addImport(new ImportDeclaration("com.fasterxml.jackson.core.JsonProcessingException")); + cu.addImport(new ImportDeclaration("com.fasterxml.jackson.core.JsonProcessingException")); codes.add(cu); }