diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Account.java index 5f97d07..4867382 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Account.java @@ -3,16 +3,16 @@ public class Account { private Map notifications; public Map getValue() { - Map temp_nil3 = new HashMap<>(); - temp_nil3.put("notifications",this.getNotifications()); - return temp_nil3; - } - public Map getNotifications() { - return notifications; + Map temp_nil1 = new HashMap<>(); + temp_nil1.put("notifications",this.getNotifications()); + return temp_nil1; } public void updateNotificationsFromMessages(String self, String gid, int mno, List messages, String member) { this.notifications.put(gid,true); } + public Map getNotifications() { + return this.notifications; + } public void hasRead(String aid, String gid) { this.notifications.remove(gid); } diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java index c18d220..30519de 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java @@ -1,7 +1,7 @@ import java.util.*; -import javax.ws.rs.*; -import javax.ws.rs.client.*; -import javax.ws.rs.core.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.client.*; +import jakarta.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; @@ -13,35 +13,35 @@ @Produces(MediaType.APPLICATION_JSON) @GET public Map getValue() { - return new HashMap<>(value); + return new HashMap<>(this.value); } public Account getAccount(String v1) { return this.value.get(v1); } - @Path("accounts/{v1}/notifications") - @POST - public void updateNotificationsFromMessages(@PathParam("v1") String v1, @FormParam("gid") String gid, @FormParam("mno") int mno, @FormParam("messages") List messages, @FormParam("member") String member) { - getAccount(v1).updateNotificationsFromMessages(v1, gid, mno, messages, member); - } @Path("/{v1}") @Produces(MediaType.APPLICATION_JSON) @GET public Map getAccountValue(@PathParam("v1") String v1) { return getAccount(v1).getValue(); } - @Path("/{aid}/notifications") + @Path("/{v1}/notifications") + @POST + public void updateNotificationsFromMessages(@PathParam("v1") String v1, @FormParam("gid") String gid, @FormParam("mno") int mno, @FormParam("messages") List messages, @FormParam("member") String member) { + getAccount(v1).updateNotificationsFromMessages(v1, gid, mno, messages, member); + } + @Path("/{v1}/notifications") @Produces(MediaType.APPLICATION_JSON) @GET - public Map getNotificationsValue(@PathParam("aid") String aid) { - return getAccount(aid).getNotifications(); - } - @POST - public void signUp(@FormParam("aid") String aid) { - this.value.put(aid,new Account(new HashMap<>())); + public Map getNotificationsValue(@PathParam("v1") String v1) { + return getAccount(v1).getNotifications(); } @Path("/{aid}/notifications") @DELETE public void hasRead(@PathParam("aid") String aid, @FormParam("gid") String gid) { getAccount(aid).hasRead(aid, gid); } + @POST + public void signUp(@FormParam("aid") String aid) { + this.value.put(aid,new Account(new HashMap<>())); + } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java index bb06954..6d15fd7 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java @@ -1,39 +1,38 @@ import java.util.*; -import javax.ws.rs.client.*; public class Group { - private List members; - private List messages; private Client client = ClientBuilder.newClient(); + private List messages; + private List members; public Map getValue() { - Map temp_nil2 = new HashMap<>(); - temp_nil2.put("members",this.getMembers()); - temp_nil2.put("messages",this.getMessages()); - return temp_nil2; - } - public List getMembers() { - return this.members; - } - public String getMember(int mno) { - return this.members.get(mno); + Map temp_nil0 = new HashMap<>(); + temp_nil0.put("members",this.getMembers()); + temp_nil0.put("messages",this.getMessages()); + return temp_nil0; } public List getMessages() { return this.messages; } - public void postMessage(String gid, String message) throws JsonProcessingException { + public void postMessage(String gid, String message) { + this.messages.add(message); for (int mno = 0; mno < members.size(); mno++) { String member = getMember(mno); Form form = new Form(); form.param("gid", gid.toString()); form.param("mno", Integer.toString(mno)); - for (String i: messages) { + for (String i: this.messages) { form.param("messages", i.toString()); } form.param("member", member.toString()); Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/accounts/"+member+"/notifications").request().post(entity, String.class); } - this.messages.add(message); + } + public String getMember(int mno) { + return this.members.get(mno); + } + public List getMembers() { + return this.members; } public void addGroupMember(String gid, String aid) { this.members.add(aid); diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java index 19b1f42..e6f2b90 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java @@ -1,7 +1,7 @@ import java.util.*; -import javax.ws.rs.*; -import javax.ws.rs.client.*; -import javax.ws.rs.core.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.client.*; +import jakarta.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; @@ -13,7 +13,7 @@ @Produces(MediaType.APPLICATION_JSON) @GET public Map getValue() { - return new HashMap<>(value); + return new HashMap<>(this.value); } public Group getGroup(String gid) { return this.value.get(gid); @@ -24,36 +24,36 @@ public Map getGroupValue(@PathParam("gid") String gid) { return getGroup(gid).getValue(); } - @Path("/{gid}/members") - @Produces(MediaType.APPLICATION_JSON) - @GET - public List getMembersValue(@PathParam("gid") String gid) { - return getGroup(gid).getMembers(); - } @Path("/{gid}/messages") @Produces(MediaType.APPLICATION_JSON) @GET public List getMessagesValue(@PathParam("gid") String gid) { return getGroup(gid).getMessages(); } + @Path("/{gid}/messages") + @POST + public void postMessage(@PathParam("gid") String gid, @FormParam("message") String message) { + getGroup(gid).postMessage(gid, message); + } @Path("/{gid}/members/{mno}") @Produces(MediaType.APPLICATION_JSON) @GET public String getMemberValue(@PathParam("gid") String gid, @PathParam("mno") int mno) { return getGroup(gid).getMember(mno); } + @POST + public void createGroup(@FormParam("gid") String gid) { + this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>())); + } + @Path("/{gid}/members") + @Produces(MediaType.APPLICATION_JSON) + @GET + public List getMembersValue(@PathParam("gid") String gid) { + return getGroup(gid).getMembers(); + } @Path("/{gid}/members") @POST public void addGroupMember(@PathParam("gid") String gid, @FormParam("aid") String aid) { getGroup(gid).addGroupMember(gid, aid); } - @Path("/{gid}/messages") - @POST - public void postMessage(@PathParam("gid") String gid, @FormParam("message") String message) throws JsonProcessingException { - getGroup(gid).postMessage(gid, message); - } - @POST - public void createGroup(@FormParam("gid") String gid) { - this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>())); - } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java index 31bc4bd..ca1ca70 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java @@ -1,19 +1,13 @@ import java.util.*; public class Account { - private String name; private int point; + private String name; public Map getValue() { - Map temp_nil5 = new HashMap<>(); - temp_nil5.put("point",this.getPoint()); - temp_nil5.put("name",this.getName()); - return temp_nil5; - } - public String getName() { - return this.name; - } - public int getPoint() { - return point; + Map temp_nil2 = new HashMap<>(); + temp_nil2.put("name",this.getName()); + temp_nil2.put("point",this.getPoint()); + return temp_nil2; } public void updatePointFromBattle(String self, String rid, int mno, boolean battle, String id) { int temp_if0; @@ -23,6 +17,12 @@ temp_if0 = this.point; }this.point = temp_if0; } + public int getPoint() { + return this.point; + } + public String getName() { + return this.name; + } public void changeName(String aid, String name) { this.name = name; } diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java index fc4d20e..3575712 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java @@ -1,7 +1,7 @@ import java.util.*; -import javax.ws.rs.*; -import javax.ws.rs.client.*; -import javax.ws.rs.core.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.client.*; +import jakarta.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; @@ -13,12 +13,22 @@ @Produces(MediaType.APPLICATION_JSON) @GET public Map getValue() { - return new HashMap<>(value); + return new HashMap<>(this.value); } public Account getAccount(String mid) { return this.value.get(mid); } - @Path("accounts/{mid}/point") + @POST + public void signUp(@FormParam("name") String name, @FormParam("aid") String aid) { + this.value.put(aid,new Account(name, 0)); + } + @Path("/{mid}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getAccountValue(@PathParam("mid") String mid) { + return getAccount(mid).getValue(); + } + @Path("/{mid}/point") @POST public void updatePointFromBattle(@PathParam("mid") String mid, @FormParam("rid") String rid, @FormParam("mno") int mno, @FormParam("battle") boolean battle, @FormParam("id") String id) { getAccount(mid).updatePointFromBattle(mid, rid, mno, battle, id); @@ -29,22 +39,12 @@ public int getPointValue(@PathParam("mid") String mid) { return getAccount(mid).getPoint(); } - @Path("/{mid}") - @Produces(MediaType.APPLICATION_JSON) - @GET - public Map getAccountValue(@PathParam("mid") String mid) { - return getAccount(mid).getValue(); - } @Path("/{mid}/name") @Produces(MediaType.APPLICATION_JSON) @GET public String getNameValue(@PathParam("mid") String mid) { return getAccount(mid).getName(); } - @POST - public void signUp(@FormParam("name") String name, @FormParam("aid") String aid) { - this.value.put(aid,new Account(name, 0)); - } @Path("/{aid}/name") @PUT public void changeName(@PathParam("aid") String aid, @FormParam("name") String name) { diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java index d12c2cf..03ee021 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java @@ -1,14 +1,13 @@ import java.util.*; -import javax.ws.rs.client.*; public class Member { private String id; private Client client = ClientBuilder.newClient(); public Map getValue() { - Map temp_nil6 = new HashMap<>(); - temp_nil6.put("id",this.getId()); - temp_nil6.put("name",this.getName()); - return temp_nil6; + Map temp_nil3 = new HashMap<>(); + temp_nil3.put("name",this.getName()); + temp_nil3.put("id",this.getId()); + return temp_nil3; } public String getId() { return this.id; diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java index 0dd75c8..c1ef7ee 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java @@ -3,7 +3,7 @@ public class Members { private List value = new ArrayList<>(); public List getValue() { - return new ArrayList<>(value); + return new ArrayList<>(this.value); } public Member getMember(int mno) { return this.value.get(mno); diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java index edbdd93..3ccf47d 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java @@ -1,14 +1,13 @@ import java.util.*; -import javax.ws.rs.client.*; public class Room { private Members members = new Members(); - private boolean battle; private Client client = ClientBuilder.newClient(); + private boolean battle; public Map getValue() { Map temp_nil4 = new HashMap<>(); - temp_nil4.put("battle",this.getBattle()); temp_nil4.put("members",this.members.getValue()); + temp_nil4.put("battle",this.getBattle()); return temp_nil4; } public Members getMembers() { @@ -17,18 +16,18 @@ public boolean getBattle() { return this.battle; } - public void battle(String rid, boolean hasWon) throws JsonProcessingException { + public void battle(String rid, boolean hasWon) { + this.battle = hasWon; for (int mno = 0; mno < members.getValue().size(); mno++) { String id = getMembers().getMember(mno).getId(); Form form = new Form(); form.param("rid", rid.toString()); form.param("mno", Integer.toString(mno)); - form.param("battle", Boolean.toString(battle)); + form.param("battle", Boolean.toString(this.battle)); form.param("id", id.toString()); Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/accounts/"+id+"/point").request().post(entity, String.class); } - this.battle = hasWon; } public Room(boolean battle) { this.battle = battle; diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java index 818eebd..c0b5e43 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java @@ -1,7 +1,7 @@ import java.util.*; -import javax.ws.rs.*; -import javax.ws.rs.client.*; -import javax.ws.rs.core.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.client.*; +import jakarta.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; @@ -13,16 +13,25 @@ @Produces(MediaType.APPLICATION_JSON) @GET public Map getValue() { - return new HashMap<>(value); + return new HashMap<>(this.value); } public Room getRoom(String rid) { return this.value.get(rid); } - @Path("/{rid}") + @Path("/{rid}/members") @Produces(MediaType.APPLICATION_JSON) @GET - public Map getRoomValue(@PathParam("rid") String rid) { - return getRoom(rid).getValue(); + public List getMembersValue(@PathParam("rid") String rid) { + return getRoom(rid).getMembers().getValue(); + } + @Path("/{rid}/members") + @POST + public void addRoomMember(@PathParam("rid") String rid, @FormParam("id") String id) { + getRoom(rid).getMembers().addRoomMember(rid, id); + } + @POST + public void createRoom(@FormParam("rid") String rid) { + this.value.put(rid,new Room(false)); } @Path("/{rid}/members/{mno}/id") @Produces(MediaType.APPLICATION_JSON) @@ -42,30 +51,21 @@ public boolean getBattleValue(@PathParam("rid") String rid) { return getRoom(rid).getBattle(); } + @Path("/{rid}/battle") + @PUT + public void battle(@PathParam("rid") String rid, @FormParam("hasWon") boolean hasWon) { + getRoom(rid).battle(rid, hasWon); + } + @Path("/{rid}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getRoomValue(@PathParam("rid") String rid) { + return getRoom(rid).getValue(); + } @Path("/{rid}/members/{mno}/name") @Produces(MediaType.APPLICATION_JSON) @GET public String getNameValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { return getRoom(rid).getMembers().getMember(mno).getName(); } - @Path("/{rid}/members") - @Produces(MediaType.APPLICATION_JSON) - @GET - public List getMembersValue(@PathParam("rid") String rid) { - return getRoom(rid).getMembers().getValue(); - } - @POST - public void createRoom(@FormParam("rid") String rid) { - this.value.put(rid,new Room(false)); - } - @Path("/{rid}/battle") - @PUT - public void battle(@PathParam("rid") String rid, @FormParam("hasWon") boolean hasWon) throws JsonProcessingException { - getRoom(rid).battle(rid, hasWon); - } - @Path("/{rid}/members") - @POST - public void addRoomMember(@PathParam("rid") String rid, @FormParam("id") String id) { - getRoom(rid).getMembers().addRoomMember(rid, id); - } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 80eabeb..1378f07 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -177,7 +177,9 @@ } } for (Map.Entry>> entry: initStatementsAndUpdateUpdates.getValue().entrySet()) { - updateStatements.put(entry.getKey(), entry.getValue()); + Map.Entry> updateInfo = entry.getValue(); + updateStatements.put(entry.getKey(), updateInfo); +// extractConstructorParameterFromUpdateExpression(updateInfo, constructorParams, langSpec); } // Declare the fields to refer to other resources for push/pull transfer in the parent/this component, and the state field in the parent component. @@ -209,7 +211,9 @@ } } for (Map.Entry>> entry: initStatementsAndInputUpdates.getValue().entrySet()) { - updateStatements.put(entry.getKey(), entry.getValue()); + Map.Entry> updateInfo = entry.getValue(); + updateStatements.put(entry.getKey(), updateInfo); +// extractConstructorParameterFromUpdateExpression(updateInfo, constructorParams, langSpec); } } @@ -236,6 +240,39 @@ } } + private void extractConstructorParameterFromUpdateExpression( + Map.Entry> updateInfo, + Map> constructorParams, ILanguageSpecific langSpec) { + Expression updateExp = updateInfo.getKey(); + ResourceHierarchy newResource = updateInfo.getValue().getValue(); + if (updateExp instanceof Term) { + Map subTerms = ((Term) updateExp).getSubTerms(Term.class); + for (Term term: subTerms.values()) { + if (term.getType() != null) { + if (term.getType().equals(newResource.getResourceStateType())) { + if (term instanceof JsonTerm) { + JsonTerm jsonTerm = (JsonTerm) term; + for (String key: jsonTerm.keySet()) { + Map params = constructorParams.getOrDefault(newResource, new HashMap<>()); + Expression member = jsonTerm.get(key); + if (member != null && member instanceof Term) { + if (!params.containsKey(key) && ((Term) member).getType() != null) { + params.put(key, new VariableDeclaration(((Term) member).getType(), key)); + } + } else if (member != null && member instanceof Variable) { + if (!params.containsKey(key) && ((Variable) member).getType() != null) { + params.put(key, langSpec.newVariableDeclaration(((Variable) member).getType(), key)); + } + } + constructorParams.put(newResource, params); + } + } + } + } + } + } + } + private static List addConstructorParameters(ResourceHierarchy resource, Map resourceComponents, Map resourceConstructors, Map> constructorParams, ILanguageSpecific langSpec) { List params = new ArrayList<>(); @@ -273,6 +310,15 @@ if (!existsParam) { constructor.addParameter(param); constructor.getBody().addStatement(langSpec.getFieldAccessor(langSpec.toVariableName(param.getName())) + langSpec.getAssignment() + langSpec.toVariableName(param.getName()) + langSpec.getStatementDelimiter()); + boolean existsField = false; + for (FieldDeclaration field: resourceComponents.get(resource).getFields()) { + if (field.getName().equals(param.getName())) { + existsField = true; + } + } + if (!existsField) { + resourceComponents.get(resource).addField(langSpec.newFieldDeclaration(param.getType(), param.getName())); + } } } } @@ -360,7 +406,7 @@ } else { updateStatement = sideEffects[0] + langSpec.getFieldAccessor(fieldOfResourceState) + langSpec.getAssignment() + newState + langSpec.getStatementDelimiter(); } - method.addFirstStatement(updateStatement); + method.addStatement(updateStatement); } private MethodDeclaration declareConstructor(ResourceNode resourceNode, TypeDeclaration component, Map> dependedRootComponentGraph, @@ -1077,7 +1123,7 @@ Type srcResType2 = src2.getResourceStateType(); String srcResName2 = langSpec.toVariableName(getComponentName(src2.getResourceHierarchy(), langSpec)); if (platformSpec.isMonolithic()) { - String srcGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(src2, resourceNode.getInSideResource(curChannel)).toImplementation(new String[] {}); + String srcGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(src2, resourceNode.getInSideResource(curChannel)).toImplementation(new String[] {""}); stateGetter.addStatement(langSpec.getVariableDeclaration(srcResType2.getInterfaceTypeName(), srcResName2) + langSpec.getAssignment() + srcGetter + langSpec.getStatementDelimiter()); } else { @@ -1094,7 +1140,7 @@ Type srcResType2 = src2.getResourceStateType(); String srcResName2 = langSpec.toVariableName(getComponentName(src2.getResourceHierarchy(), langSpec)); if (platformSpec.isMonolithic()) { - String dependingGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(src2, resourceNode.getInSideResource(curChannel)).toImplementation(new String[] {}); + String dependingGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(src2, resourceNode.getInSideResource(curChannel)).toImplementation(new String[] {""}); stateGetter.addStatement(langSpec.getVariableDeclaration(srcResType2.getInterfaceTypeName(), srcResName2) + langSpec.getAssignment() + dependingGetter + langSpec.getStatementDelimiter()); } else { @@ -1181,9 +1227,9 @@ Expression parentGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, dstResPath); Term valueGetter = new Term(new Symbol(getterOfResourceState, 1, Symbol.Type.METHOD)); valueGetter.addChild(parentGetter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, dstResPath).toImplementation(new String[] {}); + parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, dstResPath).toImplementation(new String[] {""}); } } else { // for REST API @@ -1348,10 +1394,6 @@ && (outsideOutputResource || (resourceNode.getInSideResource(ch).getCommonPrefix(srcResPath) == null && platformSpec.isDifferentTreesAsDifferentServices()))) { // Inter-service hasRestAPI = true; - if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { - // Declare a client field to connect to the destination resource of push transfer. - ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); - } if (resourceNode.getParent() == null) { // A root resource isRestAPI = true; @@ -1435,6 +1477,173 @@ parentComponent.addMethod(update); } } + + // Add a statement to update the state field + if (((StoreAttribute) resourceNode.getAttribute()).isStored()) { + try { + if (resourceNode.getInSideResources().contains(out.getResource())) { + Term unifiedMassage = null; + for (ChannelNode srcChNode: ancestorSrcChannels) { + DataTransferChannel abcestorSrcCh = (DataTransferChannel) srcChNode.getChannel(); + Term message = abcestorSrcCh.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), null).getValue(); + if (unifiedMassage == null) { + unifiedMassage = message; + } else { + unifiedMassage = (Term) unifiedMassage.unify(message); + } + } + Expression updateExp = null; + if (ch.getReferenceChannelMembers().size() == 0) { + Term message = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), null).getValue(); + if (unifiedMassage == null) { + unifiedMassage = message; + } else { + unifiedMassage = (Term) unifiedMassage.unify(message); + } + updateExp = ch.deriveUpdateExpressionOf(out, unifiedMassage, getPushAccessor(platformSpec)); + } else { + // if there exists one or more reference channel member. + HashMap inputResourceToStateAccessor = new HashMap<>(); + for (ChannelMember in: ch.getInputChannelMembers()) { + inputResourceToStateAccessor.put(in, getPushAccessor(platformSpec)); + } + for (ChannelMember ref: ch.getReferenceChannelMembers()) { + inputResourceToStateAccessor.put(ref, getRefAccessor(platformSpec)); + } + Term message = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), inputResourceToStateAccessor).getValue(); + if (unifiedMassage == null) { + unifiedMassage = message; + } else { + unifiedMassage = (Term) unifiedMassage.unify(message); + } + updateExp = ch.deriveUpdateExpressionOf(out, unifiedMassage, getPushAccessor(platformSpec)); + } + // Replace Json constructor with a constructor of the child resource. + ResourceHierarchy outRes = out.getResource().getResourceHierarchy(); + if (outRes.getChildren().size() == 1 && outRes.getChildren().iterator().next().getNumParameters() > 0) { + ResourceHierarchy descendantRes = outRes; + Set children = descendantRes.getChildren(); + do { + descendantRes = children.iterator().next(); + if (generatesComponent(descendantRes)) { + // If there exists at least one descendant resource whose component is not to be generated. + updateStatements.put(update, new AbstractMap.SimpleEntry<>(updateExp, new AbstractMap.SimpleEntry<>(outRes, descendantRes))); + updateExp = null; + break; + } + children = descendantRes.getChildren(); + } while (children != null && children.size() == 1); + } + // Add statements to the update method. + if (updateExp != null) { + // Replace the type of the state field. + Type fieldType = getImplStateType(outRes, langSpec); + if (updateExp instanceof Term) { + ((Term) updateExp).setType(fieldType); + for (Map.Entry varEnt: ((Term) updateExp).getVariables().entrySet()) { + if (varEnt.getValue().getName().equals(fieldOfResourceState)) { + varEnt.getValue().setType(fieldType); + } + } + } else if (updateExp instanceof Variable) { + ((Variable) updateExp).setType(fieldType); + } + // Add statements to the update method. + String[] sideEffects = new String[] {""}; + String newState = updateExp.toImplementation(sideEffects); + int numOfOutResourcesWithTheSameHierarchy = 0; + for (ResourcePath outResPath: ch.getOutputResources()) { + if (outResPath.getResourceHierarchy().equals(outRes)) { + numOfOutResourcesWithTheSameHierarchy++; + } + } + String updateStatement = ""; + if (generatesComponent(outRes)) { + if (updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect()) { + updateStatement = sideEffects[0]; + if (updateStatement.endsWith("\n")) { + updateStatement = updateStatement.substring(0, updateStatement.length() - 1); + } + } else { + updateStatement = sideEffects[0] + langSpec.getFieldAccessor(fieldOfResourceState) + langSpec.getAssignment() + newState + langSpec.getStatementDelimiter(); // this.value = ... + } + } else { + if (sideEffects[0] != null) { + updateStatement = sideEffects[0]; + String resourceName = langSpec.toVariableName(getComponentName(outRes, langSpec)); + updateStatement = updateStatement.replace(langSpec.getFieldAccessor(fieldOfResourceState), langSpec.getFieldAccessor(resourceName)); + if (updateStatement.endsWith("\n")) { + updateStatement = updateStatement.substring(0, updateStatement.length() - 1); + } + } + if (DataConstraintModel.typeList.isAncestorOf(resourceNode.getParent().getResourceStateType())) { + Term selector = new Term(DataConstraintModel.set); + selector.addChild(new Constant(langSpec.getFieldAccessor(fieldOfResourceState))); + selector.addChild(new Variable(update.getParameters().get(update.getParameters().size() - 2).getName())); + selector.addChild(new Constant(newState)); + String[] sideEffects2 = new String[] {""}; + String newList = selector.toImplementation(sideEffects2); + updateStatement += sideEffects2[0]; + } else if (DataConstraintModel.typeMap.isAncestorOf(resourceNode.getParent().getResourceStateType())) { + Term selector = new Term(DataConstraintModel.insert); + selector.addChild(new Constant(langSpec.getFieldAccessor(fieldOfResourceState))); + selector.addChild(new Variable(update.getParameters().get(update.getParameters().size() - 2).getName())); + selector.addChild(new Constant(newState)); + String[] sideEffects2 = new String[] {""}; + String newMap = selector.toImplementation(sideEffects2); + updateStatement += sideEffects2[0]; + } else if (!(updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect())) { + String resourceName = langSpec.toVariableName(getComponentName(outRes, langSpec)); + updateStatement += langSpec.getFieldAccessor(resourceName) + langSpec.getAssignment() + newState + langSpec.getStatementDelimiter(); + } + } + // add an update statement of the state of dst side resource. + if (numOfOutResourcesWithTheSameHierarchy == 1) { + update.addFirstStatement(updateStatement); + } else { + Term conditions = null; + int i = 1; + Map>> resourcePaths = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec)); + for (Expression pathParam: out.getResource().getPathParams()) { + if (pathParam instanceof Variable) { + String selfParamName = ((Variable) pathParam).getName(); + Expression arg = null; + for (Selector selector: ch.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable selVar = (Variable) selector.getExpression(); + if (selVar.getName().equals(selfParamName)) { + arg = selVar; + break; + } + } + } + if (arg == null) { + ResourcePath filledPath = resourcePaths.get(out).getKey(); + arg = filledPath.getPathParams().get(i - 1); + } + Term condition = new Term(DataConstraintModel.eq, new Expression[] { + new Parameter("self" + (i > 1 ? i : ""), DataConstraintModel.typeString), + arg}); + if (conditions == null) { + conditions = condition; + } else { + conditions = new Term(DataConstraintModel.and, new Expression[] { + conditions, + condition}); + } + } + i++; + } + update.addFirstStatement(langSpec.getIfStatement(conditions, updateStatement)); + } + } + } + } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork + | InvalidMessage | UnificationFailed | ValueUndefined e1) { + e1.printStackTrace(); + } + } + // For a post/put REST API. if (hasRestAPI) { if (!isRestAPI) { @@ -1507,174 +1716,12 @@ paramConverter += langSpec.getClosingScoreDelimiter(); ((RestApiSpecific) platformSpec).addJsonException(update); } - if (paramConverter.length() > 0 && !update.getBody().getStatements().contains(paramConverter)) { + if (paramConverter.length() > 0 && (update.getBody() == null || !update.getBody().getStatements().contains(paramConverter))) { update.addFirstStatement(paramConverter); } } } - // Add a statement to update the state field - if (((StoreAttribute) resourceNode.getAttribute()).isStored()) { - try { - if (resourceNode.getInSideResources().contains(out.getResource())) { - Term unifiedMassage = null; - for (ChannelNode srcChNode: ancestorSrcChannels) { - DataTransferChannel abcestorSrcCh = (DataTransferChannel) srcChNode.getChannel(); - Term message = abcestorSrcCh.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), null).getValue(); - if (unifiedMassage == null) { - unifiedMassage = message; - } else { - unifiedMassage = (Term) unifiedMassage.unify(message); - } - } - Expression updateExp = null; - if (ch.getReferenceChannelMembers().size() == 0) { - Term message = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), null).getValue(); - if (unifiedMassage == null) { - unifiedMassage = message; - } else { - unifiedMassage = (Term) unifiedMassage.unify(message); - } - updateExp = ch.deriveUpdateExpressionOf(out, unifiedMassage, getPushAccessor(platformSpec)); - } else { - // if there exists one or more reference channel member. - HashMap inputResourceToStateAccessor = new HashMap<>(); - for (ChannelMember in: ch.getInputChannelMembers()) { - inputResourceToStateAccessor.put(in, getPushAccessor(platformSpec)); - } - for (ChannelMember ref: ch.getReferenceChannelMembers()) { - inputResourceToStateAccessor.put(ref, getRefAccessor(platformSpec)); - } - Term message = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec), inputResourceToStateAccessor).getValue(); - if (unifiedMassage == null) { - unifiedMassage = message; - } else { - unifiedMassage = (Term) unifiedMassage.unify(message); - } - updateExp = ch.deriveUpdateExpressionOf(out, unifiedMassage, getPushAccessor(platformSpec)); - } - // Replace Json constructor with a constructor of the child resource. - ResourceHierarchy outRes = out.getResource().getResourceHierarchy(); - if (outRes.getChildren().size() == 1 && outRes.getChildren().iterator().next().getNumParameters() > 0) { - ResourceHierarchy descendantRes = outRes; - Set children = descendantRes.getChildren(); - do { - descendantRes = children.iterator().next(); - if (generatesComponent(descendantRes)) { - updateStatements.put(update, new AbstractMap.SimpleEntry<>(updateExp, new AbstractMap.SimpleEntry<>(outRes, descendantRes))); - updateExp = null; - break; - } - children = descendantRes.getChildren(); - } while (children != null && children.size() == 1); - } - // Replace the type of the state field. - Type fieldType = getImplStateType(outRes, langSpec); - if (updateExp instanceof Term) { - ((Term) updateExp).setType(fieldType); - for (Map.Entry varEnt: ((Term) updateExp).getVariables().entrySet()) { - if (varEnt.getValue().getName().equals(fieldOfResourceState)) { - varEnt.getValue().setType(fieldType); - } - } - } else if (updateExp instanceof Variable) { - ((Variable) updateExp).setType(fieldType); - } - // Add statements to the update method. - String[] sideEffects = new String[] {""}; - String newState = updateExp.toImplementation(sideEffects); - int numOfOutResourcesWithTheSameHierarchy = 0; - for (ResourcePath outResPath: ch.getOutputResources()) { - if (outResPath.getResourceHierarchy().equals(outRes)) { - numOfOutResourcesWithTheSameHierarchy++; - } - } - String updateStatement = ""; - if (generatesComponent(outRes)) { - if (updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect()) { - updateStatement = sideEffects[0]; - if (updateStatement.endsWith("\n")) { - updateStatement = updateStatement.substring(0, updateStatement.length() - 1); - } - } else { - updateStatement = sideEffects[0] + langSpec.getFieldAccessor(fieldOfResourceState) + langSpec.getAssignment() + newState + langSpec.getStatementDelimiter(); // this.value = ... - } - } else { - if (sideEffects[0] != null) { - updateStatement = sideEffects[0]; - String resourceName = langSpec.toVariableName(getComponentName(outRes, langSpec)); - updateStatement = updateStatement.replace(langSpec.getFieldAccessor(fieldOfResourceState), langSpec.getFieldAccessor(resourceName)); - if (updateStatement.endsWith("\n")) { - updateStatement = updateStatement.substring(0, updateStatement.length() - 1); - } - } - if (DataConstraintModel.typeList.isAncestorOf(resourceNode.getParent().getResourceStateType())) { - Term selector = new Term(DataConstraintModel.set); - selector.addChild(new Constant(langSpec.getFieldAccessor(fieldOfResourceState))); - selector.addChild(new Variable(update.getParameters().get(update.getParameters().size() - 2).getName())); - selector.addChild(new Constant(newState)); - String[] sideEffects2 = new String[] {""}; - String newList = selector.toImplementation(sideEffects2); - updateStatement += sideEffects2[0]; - } else if (DataConstraintModel.typeMap.isAncestorOf(resourceNode.getParent().getResourceStateType())) { - Term selector = new Term(DataConstraintModel.insert); - selector.addChild(new Constant(langSpec.getFieldAccessor(fieldOfResourceState))); - selector.addChild(new Variable(update.getParameters().get(update.getParameters().size() - 2).getName())); - selector.addChild(new Constant(newState)); - String[] sideEffects2 = new String[] {""}; - String newMap = selector.toImplementation(sideEffects2); - updateStatement += sideEffects2[0]; - } else if (!(updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect())) { - String resourceName = langSpec.toVariableName(getComponentName(outRes, langSpec)); - updateStatement += langSpec.getFieldAccessor(resourceName) + langSpec.getAssignment() + newState + langSpec.getStatementDelimiter(); - } - } - // add an update statement of the state of dst side resource. - if (numOfOutResourcesWithTheSameHierarchy == 1) { - update.addFirstStatement(updateStatement); - } else { - Term conditions = null; - int i = 1; - Map>> resourcePaths = ch.fillOutsideResourcePaths(out, getPushAccessor(platformSpec)); - for (Expression pathParam: out.getResource().getPathParams()) { - if (pathParam instanceof Variable) { - String selfParamName = ((Variable) pathParam).getName(); - Expression arg = null; - for (Selector selector: ch.getAllSelectors()) { - if (selector.getExpression() instanceof Variable) { - Variable selVar = (Variable) selector.getExpression(); - if (selVar.getName().equals(selfParamName)) { - arg = selVar; - break; - } - } - } - if (arg == null) { - ResourcePath filledPath = resourcePaths.get(out).getKey(); - arg = filledPath.getPathParams().get(i - 1); - } - Term condition = new Term(DataConstraintModel.eq, new Expression[] { - new Parameter("self" + (i > 1 ? i : ""), DataConstraintModel.typeString), - arg}); - if (conditions == null) { - conditions = condition; - } else { - conditions = new Term(DataConstraintModel.and, new Expression[] { - conditions, - condition}); - } - } - i++; - } - update.addFirstStatement(langSpec.getIfStatement(conditions, updateStatement)); - } - } - } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork - | InvalidMessage | UnificationFailed | ValueUndefined e1) { - e1.printStackTrace(); - } - } - // Declare the field to cache the state of the source resource in the type of the destination resource. if (inDegree > 1 || (ch.getInputChannelMembers().size() == 1 && ch.getInputChannelMembers().iterator().next().getStateTransition().isRightPartial())) { @@ -1864,9 +1911,9 @@ Expression getter = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)); Term valueGetter = new Term(new Symbol(getterOfResourceState, 1, Symbol.Type.METHOD)); valueGetter.addChild(getter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)).toImplementation(new String[] {}); + parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)).toImplementation(new String[] {""}); } } else { // for REST API @@ -1889,6 +1936,13 @@ String parentResName = langSpec.toVariableName(getComponentName(insideResPath.getResourceHierarchy(), langSpec)); String parentResPath = insideResPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(update, parentResName, parentResPath, parentResType, true, platformSpec, langSpec); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } } } } else if (selExp instanceof Term) { @@ -1923,6 +1977,13 @@ pathParams.add("\" + " + pathExp.toImplementation(sideEffects) + " + \""); } generatePullDataTransfer(update, refVarName, ref.getResourceHierarchy().toResourcePath(pathParams), refResourceType, false, platformSpec, langSpec); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } } else { Expression refGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(ref, srcRes); String refExp = refGetter.toImplementation(sideEffects); @@ -2078,11 +2139,31 @@ update.addStatement(restApiSpec.getHttpMethodParamsConstructionStatement(srcRes2.getResourceName(), params, true)); update.addStatement(langSpec.getVariableDeclaration(DataConstraintModel.typeString.getInterfaceTypeName(), "result") + langSpec.getAssignment() + restApiSpec.getHttpMethodCallStatement(restApiSpec.getBaseURL(), dstPath, resName, httpMethod)); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } + if (!((RestApiSpecific) platformSpec).hasJsonException(update)) { + ((RestApiSpecific) platformSpec).addJsonException(update); + } hasUpdateMethodinvoked = true; } else { // After the second time of call to update methods in this method update.addStatement(restApiSpec.getHttpMethodParamsConstructionStatement(srcRes2.getResourceName(), params, false)); update.addStatement("result" + langSpec.getAssignment() + restApiSpec.getHttpMethodCallStatement(restApiSpec.getBaseURL(), dstPath, resName, httpMethod)); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } + if (!((RestApiSpecific) platformSpec).hasJsonException(update)) { + ((RestApiSpecific) platformSpec).addJsonException(update); + } } } else { // Use the reference field to refer to outside destination resource. @@ -2211,6 +2292,7 @@ if (!platformSpec.isMonolithic()) { resourcePath = getInputMethodResourcePathAndPathParams(out.getResource(), rootInputParams, platformSpec, langSpec); // Path parameters for the input REST API. if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; @@ -2282,7 +2364,8 @@ } } if (platformSpec.isMonolithic() - || (resourceNode.getResourceHierarchy().getParent() != null && resourceNode.getResourceHierarchy().getParent().getParent() != null)) { + || (resourceNode.getResourceHierarchy().getParent() != null && (component != null || resourceNode.getResourceHierarchy().getParent().getParent() != null))) { + // The case that the input accessor is needed. String inputMethodName = ((Term) message).getSymbol().getImplName(); if (((DataTransferChannel) ch).getOutputChannelMembers().size() > 1) { inputMethodName += _for + getComponentName(out.getResource().getResourceHierarchy(), langSpec); @@ -2444,6 +2527,7 @@ ArrayList rootInputParams = new ArrayList<>(); String resourcePath = getGetterResourcePathAndPathParams(out.getResource(), rootInputParams, platformSpec, langSpec); if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; @@ -2480,13 +2564,12 @@ Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(out.getResource(), null); List args = new ArrayList<>(); if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the input method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args.add(((Variable)((Term) resExp).getChild(1)).getName()); } resExp = ((Term) resExp).getChild(0); } - String resourceAccess = resExp.toImplementation(new String[] {""}); // Values of channel parameters. for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { @@ -2516,7 +2599,12 @@ } } } - mainInputAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, input.getName(), args) + langSpec.getStatementDelimiter()); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {""}); + mainInputAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, input.getName(), args) + langSpec.getStatementDelimiter()); + } else { + mainInputAccessor.addStatement(langSpec.getMethodInvocation(input.getName(), args) + langSpec.getStatementDelimiter()); + } } if (input != null) { @@ -2609,6 +2697,13 @@ pathParams.add("\" + " + pathExp.toImplementation(sideEffects) + " + \""); } generatePullDataTransfer(input, refResourceName, ref.getResourceHierarchy().toResourcePath(pathParams), refResourceType, true, platformSpec, langSpec); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } } else { Expression refGetter = getPullAccessor(platformSpec).getDirectStateAccessorFor(ref, dstRes); String refExp = refGetter.toImplementation(sideEffects); @@ -2631,13 +2726,12 @@ Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(outResPath, outResPath.getRoot()); List args = new ArrayList<>(); if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the input method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args.add(((Variable)((Term) resExp).getChild(1)).getName()); } resExp = ((Term) resExp).getChild(0); } - String resourceAccess = resExp.toImplementation(new String[] {""}); // Values of channel parameters. for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { @@ -2651,7 +2745,12 @@ args.add(mesVar.getName()); } } - rootInputAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, input.getName(), args) + langSpec.getStatementDelimiter()); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {""}); + rootInputAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, input.getName(), args) + langSpec.getStatementDelimiter()); + } else { + rootInputAccessor.addStatement(langSpec.getMethodInvocation(input.getName(), args) + langSpec.getStatementDelimiter()); + } if (input != null && input.getThrows() != null && ((RestApiSpecific) platformSpec).hasJsonException(input)) { ((RestApiSpecific) platformSpec).addJsonException(rootInputAccessor); } @@ -2783,9 +2882,9 @@ Expression getter = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)); Term valueGetter = new Term(new Symbol(getterOfResourceState, 1, Symbol.Type.METHOD)); valueGetter.addChild(getter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)).toImplementation(new String[] {}); + parent = getPullAccessor(platformSpec).getDirectStateAccessorFor(insideResPath, resourceNode.getOutSideResource(directDstCh)).toImplementation(new String[] {""}); } } else { // for REST API @@ -2808,6 +2907,13 @@ String parentResName = langSpec.toVariableName(getComponentName(insideResPath.getResourceHierarchy(), langSpec)); String parentResPath = insideResPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(input, parentResName, parentResPath, parentResType, true, platformSpec, langSpec); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } } } } else if (selExp instanceof Term) { @@ -2986,15 +3092,31 @@ input.addStatement(restApiSpec.getHttpMethodParamsConstructionStatement(srcRes.getResourceName(), params, true)); input.addStatement(langSpec.getVariableDeclaration(DataConstraintModel.typeString.getInterfaceTypeName(), "result") + langSpec.getAssignment() + restApiSpec.getHttpMethodCallStatement(restApiSpec.getBaseURL(), dstPath, resName2, httpMethod)); - hasUpdateMethodinvoked = true; if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { // Declare a client field to connect to the destination resource of push transfer. ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); } + if (!((RestApiSpecific) platformSpec).hasJsonException(input)) { + ((RestApiSpecific) platformSpec).addJsonException(input); + } + hasUpdateMethodinvoked = true; } else { // After the second time of call to update methods in this method input.addStatement(restApiSpec.getHttpMethodParamsConstructionStatement(srcRes.getResourceName(), params, false)); input.addStatement("result" + langSpec.getAssignment() + restApiSpec.getHttpMethodCallStatement(restApiSpec.getBaseURL(), dstPath, resName2, httpMethod)); + if (component != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(component)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(component); + } else if (parentComponent != null && !((RestApiSpecific) platformSpec).hasHttpClientFieldDeclaration(parentComponent)) { + // Declare a client field to connect to the destination resource of push transfer. + ((RestApiSpecific) platformSpec).addHttpClientFieldDeclaration(parentComponent); + } + if (!((RestApiSpecific) platformSpec).hasJsonException(input)) { + ((RestApiSpecific) platformSpec).addJsonException(input); + } } } else { // Use the reference field to refer to outside destination resource. @@ -3101,6 +3223,7 @@ List mainGetterParams = new ArrayList<>(); String resourcePath = getGetterResourcePathAndPathParams(resourceNode.getPrimaryResourcePath(), mainGetterParams, platformSpec, langSpec); if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; @@ -3139,6 +3262,12 @@ VariableDeclaration param; parameters = new ArrayList<>(); String resourcePath = getUpdateResourcePathAndPathParams(dstResPath, parameters, true, platformSpec, langSpec); // Path parameters to identify the self resource. + if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path + resourcePath = resourcePath.substring(resourcePath.indexOf('/')); + } else { + resourcePath = ""; + } ResourcePath resPath = new ResourcePath(dstResPath); for (int i = 0; i < parameters.size(); i++) { Parameter pathParam = new Parameter(parameters.get(i).getName()); @@ -3191,17 +3320,21 @@ Expression resExp = getPullAccessor(platformSpec).getDirectStateAccessorFor(resPath, resPath.getRoot()); List args = new ArrayList<>(); if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the update method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args.add(((Variable)((Term) resExp).getChild(1)).getName()); } resExp = ((Term) resExp).getChild(0); } - String resourceAccess = resExp.toImplementation(new String[] {""}); for (VariableDeclaration var: updateAccessor.getParameters()) { args.add(var.getName()); } - updateAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, updateMethodName, args) + langSpec.getStatementDelimiter()); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {""}); + updateAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, updateMethodName, args) + langSpec.getStatementDelimiter()); + } else { + updateAccessor.addStatement(langSpec.getMethodInvocation(updateMethodName, args) + langSpec.getStatementDelimiter()); + } rootComponent.addMethod(updateAccessor); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index f220abd..8d1fca4 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -496,7 +496,7 @@ } insideResPath = insideResPath.getParent(); if (insideResPath != null) { - String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getOutSideResource(directDstCh)).toImplementation(new String[] {}); + String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getOutSideResource(directDstCh)).toImplementation(new String[] {""}); if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for broadcasting. srcUpdate.addFirstStatement("for (int " + forVarName + " = 0; " + forVarName +" < " + parent + ".size(); " + forVarName + "++) {"); @@ -657,7 +657,7 @@ } insideResPath = insideResPath.getParent(); if (insideResPath != null) { - String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getOutSideResource(directDstCh)).toImplementation(new String[] {}); + String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getOutSideResource(directDstCh)).toImplementation(new String[] {""}); if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for broadcasting. srcInput.addFirstStatement("for (int " + varName + " = 0; " + varName +" < " + parent + ".size(); " + varName + "++) {"); @@ -747,7 +747,7 @@ ResourcePath src2 = cm2.getResource(); Type srcResType2 = src2.getResourceStateType(); String srcResName2 = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(src2.getResourceHierarchy())); - String srcGetter = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(src2, dst.getInSideResource(curChannel)).toImplementation(new String[] {}); + String srcGetter = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(src2, dst.getInSideResource(curChannel)).toImplementation(new String[] {""}); getter.addStatement(srcResType2.getInterfaceTypeName() + " " + srcResName2 + " = " + srcGetter + ";"); } else { // a depending channel member. @@ -757,7 +757,7 @@ // generate a pull data transfer from a depending in/ref resource. Type srcResType2 = src2.getResourceStateType(); String srcResName2 = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(src2.getResourceHierarchy())); - String dependingGetter = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(src2, dst.getInSideResource(curChannel)).toImplementation(new String[] {}); + String dependingGetter = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(src2, dst.getInSideResource(curChannel)).toImplementation(new String[] {""}); getter.addStatement(srcResType2.getInterfaceTypeName() + " " + srcResName2 + " = " + dependingGetter + ";"); } } @@ -830,7 +830,7 @@ } insideResPath = insideResPath.getParent(); if (insideResPath != null) { - String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, dst.getInSideResource(ch)).toImplementation(new String[] {}); + String parent = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, dst.getInSideResource(ch)).toImplementation(new String[] {""}); if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for data collecting. getter.addFirstStatement("for (int " + varName + " = 0; " + varName +" < " + parent + ".size(); " + varName + "++) {"); @@ -1224,13 +1224,12 @@ Expression resExp = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(out.getResource(), null); List args = new ArrayList<>(); if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the input method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args.add(((Variable)((Term) resExp).getChild(1)).getName()); } resExp = ((Term) resExp).getChild(0); } - String resourceAccess = resExp.toImplementation(new String[] {null}); // Values of channel parameters. for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { @@ -1268,7 +1267,12 @@ argsStr += delimiter + arg; delimiter = ", "; } - inputAccessor.addStatement(resourceAccess + "." + input.getName() + "(" + argsStr + ");"); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {null}); + inputAccessor.addStatement(resourceAccess + "." + input.getName() + "(" + argsStr + ");"); + } else { + inputAccessor.addStatement(input.getName() + "(" + argsStr + ");"); + } } } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaSpecific.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaSpecific.java index 58357f2..7115e57 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaSpecific.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaSpecific.java @@ -193,7 +193,7 @@ @Override public String getIfStatement(Term condition, String block) { - return "if (" + condition.toImplementation(new String[] {})+ ") {\n" + "\t" + block.replace("\n", "\n\t") + "\n}"; + return "if (" + condition.toImplementation(new String[] {""})+ ") {\n" + "\t" + block.replace("\n", "\n\t") + "\n}"; } @Override diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index b744713..68e4aa9 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -445,6 +445,7 @@ List mainGetterParams = new ArrayList<>(); String resourcePath = getGetterResourcePathAndPathParams(resourceNode.getPrimaryResourcePath(), mainGetterParams); if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; @@ -794,6 +795,12 @@ String updateMethodName = update.getName(); params = new ArrayList<>(); String resourcePath = getUpdateResourcePathAndPathParams(out.getResource(), params, true); // Path parameters to identify the self resource. + if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path + resourcePath = resourcePath.substring(resourcePath.indexOf('/')); + } else { + resourcePath = ""; + } for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { Variable selVar = (Variable) selector.getExpression(); @@ -859,6 +866,7 @@ ArrayList rootInputParams = new ArrayList<>(); String resourcePath = getInputMethodResourcePathAndPathParams(cm.getResource(), rootInputParams); // Path parameters for the input REST API. if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; @@ -904,7 +912,8 @@ } } - if (resourceNode.getResourceHierarchy().getParent() != null && resourceNode.getResourceHierarchy().getParent().getParent() != null) { + if (resourceNode.getResourceHierarchy().getParent() != null && (component != null || resourceNode.getResourceHierarchy().getParent().getParent() != null)) { + // The case that the input accessor is needed. String inputMethodName = ((Term) message).getSymbol().getImplName(); if (((DataTransferChannel) ch).getOutputChannelMembers().size() > 1) { inputMethodName += "For" + getComponentName(cm.getResource().getResourceHierarchy()); @@ -1030,6 +1039,7 @@ ArrayList rootInputParams = new ArrayList<>(); String resourcePath = getGetterResourcePathAndPathParams(cm.getResource(), rootInputParams); if (resourcePath.indexOf('/') > 0) { + // Remove the root resource from the path resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { resourcePath = ""; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index fdfd502..9552937 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -320,14 +320,13 @@ String args = ""; String delimiter = ""; if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the update method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args += delimiter + ((Variable)((Term) resExp).getChild(1)).getName(); delimiter = ", "; } 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()) { @@ -342,7 +341,12 @@ delimiter = ", "; v++; } - update.addStatement(resourceAccess + "." + update2.getName() + "(" + args + ");"); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {""}); + update.addStatement(resourceAccess + "." + update2.getName() + "(" + args + ");"); + } else { + update.addStatement(update2.getName() + "(" + args + ");"); + } } // to convert a json param to a tuple, pair or map object. for (VariableDeclaration param: update.getParameters()) { @@ -406,7 +410,7 @@ paramConverter += "}"; update.addThrow("JsonProcessingException"); } - if (paramConverter.length() > 0 && !update.getBody().getStatements().contains(paramConverter)) { + if (paramConverter.length() > 0 && (update.getBody() == null || !update.getBody().getStatements().contains(paramConverter))) { update.addFirstStatement(paramConverter); } } @@ -542,11 +546,13 @@ // The first call to an update method in this method srcUpdate.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, true)); srcUpdate.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstPath, srcResName, httpMethod)); + srcUpdate.addThrow("JsonProcessingException"); chainedCalls.add(srcUpdate); } else { // After the second time of call to update methods in this method srcUpdate.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, false)); srcUpdate.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstPath, srcResName, httpMethod)); + srcUpdate.addThrow("JsonProcessingException"); } if (descendantDstChannels.contains(chNode)) { // For hierarchical channels (broadcasting push transfer). @@ -590,9 +596,9 @@ Expression getter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()); Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); valueGetter.addChild(getter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {""}); } if (insideResPath != null) { if (selType.equals(DataConstraintModel.typeInt)) { @@ -725,11 +731,13 @@ // First call to an update method in this method srcInput.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, true)); srcInput.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstPath, srcResName, httpMethod)); + srcInput.addThrow("JsonProcessingException"); chainedCalls.add(srcInput); } else { // After the second time of call to update methods in this method srcInput.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, false)); srcInput.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstPath, srcResName, httpMethod)); + srcInput.addThrow("JsonProcessingException"); } if (descendantDstChannels.contains(chNode)) { // For hierarchical channels (broadcasting push transfer). @@ -773,9 +781,9 @@ Expression getter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()); Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); valueGetter.addChild(getter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {""}); } if (insideResPath != null) { if (selType.equals(DataConstraintModel.typeInt)) { @@ -999,9 +1007,9 @@ Expression parentGetter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, dst.getInSideResource(ch)); Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); valueGetter.addChild(parentGetter); - parent = valueGetter.toImplementation(new String[] {}); + parent = valueGetter.toImplementation(new String[] {""}); } else { - parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, dst.getInSideResource(ch)).toImplementation(new String[] {}); + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, dst.getInSideResource(ch)).toImplementation(new String[] {""}); } } else { parent = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(insideResPath.getResourceHierarchy())); @@ -1335,14 +1343,13 @@ String args = ""; String delimiter = ""; if (resExp instanceof Term) { - // to access the parent + // To access the parent resource if the leaf resource is primitive and cannot declare the input method, or to remove getValue(). if (((Term) resExp).getChildren().size() > 1 && ((Term) resExp).getChild(1) instanceof Variable) { args += delimiter + ((Variable)((Term) resExp).getChild(1)).getName(); delimiter = ", "; } resExp = ((Term) resExp).getChild(0); } - String resourceAccess = resExp.toImplementation(new String[] {""}); // Values of channel parameters. for (Selector selector: ch.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { @@ -1358,7 +1365,12 @@ delimiter = ", "; } } - inputAccessor.addStatement(resourceAccess + "." + input.getName() + "(" + args + ");"); + if (resExp != null) { + String resourceAccess = resExp.toImplementation(new String[] {""}); + inputAccessor.addStatement(resourceAccess + "." + input.getName() + "(" + args + ");"); + } else { + inputAccessor.addStatement(input.getName() + "(" + args + ");"); + } if (input != null && input.getThrows() != null && input.getThrows().getExceptions().contains("JsonProcessingException")) { inputAccessor.addThrow("JsonProcessingException"); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java index 9cc7de2..d259620 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java @@ -106,6 +106,7 @@ pos = (Position) pos.clone(); int i = pos.removeHeadOrder(); if (i >= children.size()) return null; + if (children.get(i) == null) return null; return children.get(i).getSubTerm(pos); } @@ -143,7 +144,11 @@ if (children.size() != anotherTerm.children.size()) return null; Term unifiedTerm = new Term(symbol); for (int i = 0; i < children.size(); i++) { - unifiedTerm.addChild(children.get(i).unify(anotherTerm.children.get(i))); + if (children.get(i) != null) { + unifiedTerm.addChild(children.get(i).unify(anotherTerm.children.get(i))); + } else { + unifiedTerm.addChild(anotherTerm.children.get(i)); + } } return unifiedTerm; } else { @@ -385,7 +390,7 @@ if (implParamOrder == null) { String exp = null; String receiver = ""; - if (children.get(0) != null) { + if (children.size() > 0 && children.get(0) != null) { receiver = children.get(0).toImplementation(sideEffects); exp = receiver + "." + symbol.toImplementation() + "("; } else { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 18382a0..04685d9 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -955,7 +955,8 @@ public static final Symbol lookup = new Symbol("lookup", 2, Symbol.Type.PREFIX, "get", Symbol.Type.METHOD, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (args.get(1).getClass() == Constant.class && ((Constant) args.get(1)).getType().equals(typeString)) { + if (args.get(1).getClass() == Constant.class && + ((Constant) args.get(1)).getType() != null && ((Constant) args.get(1)).getType().equals(typeString)) { String key = (String) ((Constant) args.get(1)).getValue(); if (args.get(0) instanceof Term) { Term term = (Term) args.get(0); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java index 9df8290..b56b06d 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java @@ -376,90 +376,6 @@ Entry, // arg types Integer>>>>>>> // lines of code exprectedStructure = new HashMap<>(); - exprectedStructure.put("Groups", Map.entry(Set.of("@Path(\"/groups\")","@Component"), - Map.entry(Map.ofEntries(Map.entry("value", "Map")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getGroup", Map.entry(Set.of(), - Map.entry("Group", - Map.entry(List.of("String"), - 1)))), - Map.entry("getMembersValue", Map.entry(Set.of("@Path(\"/{gid}/members\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("List", - Map.entry(List.of("String"), - 1)))), - Map.entry("getMessagesValue", Map.entry(Set.of("@Path(\"/{gid}/messages\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("List", - Map.entry(List.of("String"), - 1)))), - Map.entry("getGroupValue", Map.entry(Set.of("@Path(\"/{gid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of("String"), - 1)))), - Map.entry("addGroupMember", Map.entry(Set.of("@Path(\"/{gid}/members\")","@POST"), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("postMessage", Map.entry(Set.of("@Path(\"/{gid}/messages\")","@POST"), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("createGroup", Map.entry(Set.of("@POST"), - Map.entry("void", - Map.entry(List.of("String"), - 1)))))))); - exprectedStructure.put("Account", Map.entry(Set.of(), - Map.entry(Map.ofEntries(Map.entry("notifications", "Map")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getNotifications", Map.entry(Set.of(), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("updateNotificationsFromMessages", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String","int","List","String"), - 1)))), - Map.entry("hasRead", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("Account", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("Map"), - 1)))))))); - exprectedStructure.put("Group", Map.entry(Set.of(), - Map.entry(Map.ofEntries(Map.entry("messages", "List"), - Map.entry("client", "Client"), - Map.entry("members", "List")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getMessages", Map.entry(Set.of(), - Map.entry("List", - Map.entry(List.of(), - 1)))), - Map.entry("getMembers", Map.entry(Set.of(), - Map.entry("List", - Map.entry(List.of(), - 1)))), - Map.entry("postMessage", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String"), - 6)))), - Map.entry("addGroupMember", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("Group", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("List","List"), - 2)))))))); exprectedStructure.put("Accounts", Map.entry(Set.of("@Path(\"/accounts\")","@Component"), Map.entry(Map.ofEntries(Map.entry("value", "Map")), Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), @@ -470,7 +386,15 @@ Map.entry("Account", Map.entry(List.of("String"), 1)))), - Map.entry("updateNotificationsFromMessages", Map.entry(Set.of("@Path(\"accounts/{v1}/notifications\")","@POST"), + Map.entry("signUp", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String"), + 1)))), + Map.entry("getAccountValue", Map.entry(Set.of("@Path(\"/{v1}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("updateNotificationsFromMessages", Map.entry(Set.of("@Path(\"/{v1}/notifications\")","@POST"), Map.entry("void", Map.entry(List.of("String","String","int","List","String"), 1)))), @@ -478,18 +402,102 @@ Map.entry("Map", Map.entry(List.of("String"), 1)))), - Map.entry("getAccountValue", Map.entry(Set.of("@Path(\"/{v1}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of("String"), - 1)))), Map.entry("hasRead", Map.entry(Set.of("@Path(\"/{aid}/notifications\")","@DELETE"), Map.entry("void", Map.entry(List.of("String","String"), + 1)))))))); + exprectedStructure.put("Account", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("notifications", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), 1)))), - Map.entry("signUp", Map.entry(Set.of("@POST"), + Map.entry("updateNotificationsFromMessages", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String","int","List","String"), + 1)))), + Map.entry("getNotifications", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("hasRead", Map.entry(Set.of(), Map.entry("void", - Map.entry(List.of("String"), + Map.entry(List.of("String","String"), + 1)))), + Map.entry("Account", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("Map"), 1)))))))); + exprectedStructure.put("Group", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("members", "List"), + Map.entry("client", "Client"), + Map.entry("messages", "List")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getMember", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of("int"), + 1)))), + Map.entry("getMembers", Map.entry(Set.of(), + Map.entry("List", + Map.entry(List.of(), + 1)))), + Map.entry("addGroupMember", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("getMessages", Map.entry(Set.of(), + Map.entry("List", + Map.entry(List.of(), + 1)))), + Map.entry("postMessage", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String"), + 6)))), + Map.entry("Group", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("List","List"), + 2)))))))); + exprectedStructure.put("Groups", Map.entry(Set.of("@Path(\"/groups\")","@Component"), + Map.entry(Map.ofEntries(Map.entry("value", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getGroup", Map.entry(Set.of(), + Map.entry("Group", + Map.entry(List.of("String"), + 1)))), + Map.entry("getMemberValue", Map.entry(Set.of("@Path(\"/{gid}/members/{mno}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getMembersValue", Map.entry(Set.of("@Path(\"/{gid}/members\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("List", + Map.entry(List.of("String"), + 1)))), + Map.entry("addGroupMember", Map.entry(Set.of("@Path(\"/{gid}/members\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("getGroupValue", Map.entry(Set.of("@Path(\"/{gid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("createGroup", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String"), + 1)))), + Map.entry("getMessagesValue", Map.entry(Set.of("@Path(\"/{gid}/messages\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("List", + Map.entry(List.of("String"), + 1)))), + Map.entry("postMessage", Map.entry(Set.of("@Path(\"/{gid}/messages\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))))); checkStructure(generatedCode, exprectedStructure); // generateCheckCode(generatedCode); @@ -731,102 +739,10 @@ Entry, // arg types Integer>>>>>>> // lines of code exprectedStructure = new HashMap<>(); - exprectedStructure.put("Rooms", Map.entry(Set.of("@Path(\"/rooms\")","@Component"), - Map.entry(Map.ofEntries(Map.entry("value", "Map")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getRoom", Map.entry(Set.of(), - Map.entry("Room", - Map.entry(List.of("String"), - 1)))), - Map.entry("getIdValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/id\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("String", - Map.entry(List.of("String","int"), - 1)))), - Map.entry("getBattleValue", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("boolean", - Map.entry(List.of("String"), - 1)))), - Map.entry("getRoomValue", Map.entry(Set.of("@Path(\"/{rid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of("String"), - 1)))), - Map.entry("getMemberValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of("String","int"), - 1)))), - Map.entry("getMembersValue", Map.entry(Set.of("@Path(\"/{rid}/members\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("List", - Map.entry(List.of("String"), - 1)))), - Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("String", - Map.entry(List.of("String","int"), - 1)))), - Map.entry("battle", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@PUT"), - Map.entry("void", - Map.entry(List.of("String","boolean"), - 1)))), - Map.entry("addRoomMember", Map.entry(Set.of("@Path(\"/{rid}/members\")","@POST"), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("createRoom", Map.entry(Set.of("@POST"), - Map.entry("void", - Map.entry(List.of("String"), - 1)))))))); - exprectedStructure.put("Member", Map.entry(Set.of(), - Map.entry(Map.ofEntries(Map.entry("id", "String"), - Map.entry("client", "Client")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getId", Map.entry(Set.of(), - Map.entry("String", - Map.entry(List.of(), - 1)))), - Map.entry("getName", Map.entry(Set.of(), - Map.entry("String", - Map.entry(List.of(), - 2)))), - Map.entry("Member", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String"), - 1)))))))); - exprectedStructure.put("Account", Map.entry(Set.of(), - Map.entry(Map.ofEntries(Map.entry("name", "String"), - Map.entry("point", "int")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getName", Map.entry(Set.of(), - Map.entry("String", - Map.entry(List.of(), - 1)))), - Map.entry("getPoint", Map.entry(Set.of(), - Map.entry("int", - Map.entry(List.of(), - 1)))), - Map.entry("updatePointFromBattle", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String","int","boolean","String"), - 1)))), - Map.entry("changeName", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))), - Map.entry("Account", Map.entry(Set.of(), - Map.entry("void", - Map.entry(List.of("String","int"), - 2)))))))); exprectedStructure.put("Room", Map.entry(Set.of(), Map.entry(Map.ofEntries(Map.entry("members", "Members"), - Map.entry("battle", "boolean"), - Map.entry("client", "Client")), + Map.entry("client", "Client"), + Map.entry("battle", "boolean")), Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), Map.entry("Map", Map.entry(List.of(), @@ -847,40 +763,52 @@ Map.entry("void", Map.entry(List.of("boolean"), 1)))))))); - exprectedStructure.put("Accounts", Map.entry(Set.of("@Path(\"/accounts\")","@Component"), - Map.entry(Map.ofEntries(Map.entry("value", "Map")), - Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of(), - 1)))), - Map.entry("getAccount", Map.entry(Set.of(), - Map.entry("Account", - Map.entry(List.of("String"), - 1)))), - Map.entry("updatePointFromBattle", Map.entry(Set.of("@Path(\"accounts/{mid}/point\")","@POST"), - Map.entry("void", - Map.entry(List.of("String","String","int","boolean","String"), - 1)))), - Map.entry("getAccountValue", Map.entry(Set.of("@Path(\"/{mid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("Map", - Map.entry(List.of("String"), - 1)))), - Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{mid}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("String", - Map.entry(List.of("String"), - 1)))), - Map.entry("getPointValue", Map.entry(Set.of("@Path(\"/{mid}/point\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), - Map.entry("int", - Map.entry(List.of("String"), - 1)))), - Map.entry("signUp", Map.entry(Set.of("@POST"), - Map.entry("void", - Map.entry(List.of("String","String"), + exprectedStructure.put("Account", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("name", "String"), + Map.entry("point", "int")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getName", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), 1)))), - Map.entry("changeName", Map.entry(Set.of("@Path(\"/{aid}/name\")","@PUT"), - Map.entry("void", - Map.entry(List.of("String","String"), - 1)))))))); + Map.entry("changeName", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("updatePointFromBattle", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1)))), + Map.entry("getPoint", Map.entry(Set.of(), + Map.entry("int", + Map.entry(List.of(), + 1)))), + Map.entry("Account", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","int"), + 2)))))))); + exprectedStructure.put("Member", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("id", "String"), + Map.entry("client", "Client")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getId", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), + 1)))), + Map.entry("getName", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), + 2)))), + Map.entry("Member", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String"), + 1)))))))); exprectedStructure.put("Members", Map.entry(Set.of(), Map.entry(Map.ofEntries(Map.entry("value", "List")), Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), @@ -895,8 +823,88 @@ Map.entry("void", Map.entry(List.of("String","String"), 1)))))))); + exprectedStructure.put("Accounts", Map.entry(Set.of("@Path(\"/accounts\")","@Component"), + Map.entry(Map.ofEntries(Map.entry("value", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getAccount", Map.entry(Set.of(), + Map.entry("Account", + Map.entry(List.of("String"), + 1)))), + Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{mid}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String"), + 1)))), + Map.entry("changeName", Map.entry(Set.of("@Path(\"/{aid}/name\")","@PUT"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("getAccountValue", Map.entry(Set.of("@Path(\"/{mid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("updatePointFromBattle", Map.entry(Set.of("@Path(\"/{mid}/point\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1)))), + Map.entry("getPointValue", Map.entry(Set.of("@Path(\"/{mid}/point\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("int", + Map.entry(List.of("String"), + 1)))), + Map.entry("signUp", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))))); + exprectedStructure.put("Rooms", Map.entry(Set.of("@Path(\"/rooms\")","@Component"), + Map.entry(Map.ofEntries(Map.entry("value", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getRoom", Map.entry(Set.of(), + Map.entry("Room", + Map.entry(List.of("String"), + 1)))), + Map.entry("getRoomValue", Map.entry(Set.of("@Path(\"/{rid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("getBattleValue", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("boolean", + Map.entry(List.of("String"), + 1)))), + Map.entry("battle", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@PUT"), + Map.entry("void", + Map.entry(List.of("String","boolean"), + 1)))), + Map.entry("getIdValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/id\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getMemberValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getMembersValue", Map.entry(Set.of("@Path(\"/{rid}/members\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("List", + Map.entry(List.of("String"), + 1)))), + Map.entry("addRoomMember", Map.entry(Set.of("@Path(\"/{rid}/members\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("createRoom", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String"), + 1)))))))); - checkStructure(generatedCode, exprectedStructure); + checkStructure(generatedCode, exprectedStructure); // generateCheckCode(generatedCode); } catch (FileNotFoundException | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword @@ -1276,8 +1284,8 @@ } TypeInference.infer(model); DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); - ArrayList codetree = JerseyMethodBodyGenerator.doGenerate(graph, model, JerseyCodeGenerator.doGenerate(graph, model)); -// ArrayList codetree = new CodeGeneratorFromDataFlowGraph().generateCode(model, graph, new JerseySpecific(), new JavaSpecific()); +// ArrayList codetree = JerseyMethodBodyGenerator.doGenerate(graph, model, JerseyCodeGenerator.doGenerate(graph, model)); + ArrayList codetree = new CodeGeneratorFromDataFlowGraph().generateCode(model, graph, new JerseySpecific(), new JavaSpecific()); return codetree; } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java index b9a5dc0..8128ce4 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java @@ -1438,8 +1438,8 @@ } TypeInference.infer(model); DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); - ArrayList codetree = JavaMethodBodyGenerator.doGenerate(graph, model, JavaCodeGenerator.doGenerate(graph, model)); -// ArrayList codetree = new CodeGeneratorFromDataFlowGraph().generateCode(model, graph, new StandaloneSpecific(), new JavaSpecific()); +// ArrayList codetree = JavaMethodBodyGenerator.doGenerate(graph, model, JavaCodeGenerator.doGenerate(graph, model)); + ArrayList codetree = new CodeGeneratorFromDataFlowGraph().generateCode(model, graph, new StandaloneSpecific(), new JavaSpecific()); return codetree; }