diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index 4f7d7ec..125e133 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -628,14 +628,45 @@ String resourceName = getComponentName(resourceNode.getResourceHierarchy()); update = new MethodDeclaration("update" + resourceName + "From" + srcResName, false, typeVoid, params); } - // Determine whether the update method is put or post. + // Determine whether the update method is put or post or delete. boolean isPut = false; + boolean isDelete = false; for (ChannelMember cm: ch.getOutputChannelMembers()) { if (resourceNode.getInSideResources().contains(cm.getResource())) { if (cm.getStateTransition().isRightUnary()) { isPut = true; } else { isPut = false; + Expression nextExp = cm.getStateTransition().getNextStateExpression(); + if (nextExp instanceof Term) { + Symbol rootSymbol = ((Term) nextExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } else if (rootSymbol.equals(DataConstraintModel.cond)) { + Expression childExp = ((Term) nextExp).getChild(1); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + childExp = ((Term) nextExp).getChild(2); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + } +// HashMap subTerms = ((Term) nextExp).getSubTerms(Term.class); +// for (Term subTerm: subTerms.values()) { +// Symbol rootSymbol = subTerm.getSymbol(); +// if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { +// isDelete = true; +// break; +// } +// } + } } } } @@ -643,7 +674,11 @@ if (isPut) { update.addAnnotation(new Annotation("PUT")); } else { - update.addAnnotation(new Annotation("POST")); + if (!isDelete) { + update.addAnnotation(new Annotation("POST")); + } else { + update.addAnnotation(new Annotation("DELETE")); + } } } // Calculate in-degree of the destination resource. @@ -716,7 +751,11 @@ if (isPut) { updateAccessor.addAnnotation(new Annotation("PUT")); } else { - updateAccessor.addAnnotation(new Annotation("POST")); + if (!isDelete) { + updateAccessor.addAnnotation(new Annotation("POST")); + } else { + updateAccessor.addAnnotation(new Annotation("DELETE")); + } } if (inDegree > 1) { // For each source resource, a child resource is defined in the destination resource so that its state can be updated separately. @@ -830,7 +869,42 @@ if (cm.getStateTransition().isRightUnary()) { inputAccessor.addAnnotation(new Annotation("PUT")); } else { - inputAccessor.addAnnotation(new Annotation("POST")); + boolean isDelete = false; + Expression nextExp = cm.getStateTransition().getNextStateExpression(); + if (nextExp instanceof Term) { + Symbol rootSymbol = ((Term) nextExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } else if (rootSymbol.equals(DataConstraintModel.cond)) { + Expression childExp = ((Term) nextExp).getChild(1); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + childExp = ((Term) nextExp).getChild(2); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + } +// HashMap subTerms = ((Term) nextExp).getSubTerms(Term.class); +// for (Term subTerm: subTerms.values()) { +// Symbol rootSymbol = subTerm.getSymbol(); +// if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { +// isDelete = true; +// break; +// } +// } + } + if (!isDelete) { + inputAccessor.addAnnotation(new Annotation("POST")); + } else { + inputAccessor.addAnnotation(new Annotation("DELETE")); + } } if (resourcePath.length() > 0) { inputAccessor.addAnnotation(new Annotation("Path", "\"" + resourcePath + "\"")); @@ -899,7 +973,42 @@ if (cm.getStateTransition().isRightUnary()) { inputAccessor.addAnnotation(new Annotation("PUT")); } else { - inputAccessor.addAnnotation(new Annotation("POST")); + boolean isDelete = false; + Expression nextExp = cm.getStateTransition().getNextStateExpression(); + if (nextExp instanceof Term) { + Symbol rootSymbol = ((Term) nextExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } else if (rootSymbol.equals(DataConstraintModel.cond)) { + Expression childExp = ((Term) nextExp).getChild(1); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + childExp = ((Term) nextExp).getChild(2); + if (childExp instanceof Term) { + rootSymbol = ((Term) childExp).getSymbol(); + if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { + isDelete = true; + } + } + } +// HashMap subTerms = ((Term) nextExp).getSubTerms(Term.class); +// for (Term subTerm: subTerms.values()) { +// Symbol rootSymbol = subTerm.getSymbol(); +// if (rootSymbol.equals(DataConstraintModel.delete) || rootSymbol.equals(DataConstraintModel.remove)) { +// isDelete = true; +// break; +// } +// } + } + if (!isDelete) { + inputAccessor.addAnnotation(new Annotation("POST")); + } else { + inputAccessor.addAnnotation(new Annotation("DELETE")); + } } if (resourcePath.length() > 0) { inputAccessor.addAnnotation(new Annotation("Path", "\"" + resourcePath + "\""));