From 9e1c6d9e59e92d98d90557d83b86989f8a9239ec Mon Sep 17 00:00:00 2001 From: jlcanovas Date: Fri, 11 Jul 2014 13:09:40 +0200 Subject: [PATCH] Implementing backend support for issues #3 and #5 --- .../collaboro/backend/CollaboroBackend.java | 131 ++++- .../servlets/JsonCollaborationSimplified.java | 12 - .../web/servlets/VersionsServlet.java | 514 +++++++++--------- 3 files changed, 360 insertions(+), 297 deletions(-) diff --git a/plugins/fr.inria.atlanmod.collaboro.backend/src/fr/inria/atlanmod/collaboro/backend/CollaboroBackend.java b/plugins/fr.inria.atlanmod.collaboro.backend/src/fr/inria/atlanmod/collaboro/backend/CollaboroBackend.java index a81319e..09bf3f5 100644 --- a/plugins/fr.inria.atlanmod.collaboro.backend/src/fr/inria/atlanmod/collaboro/backend/CollaboroBackend.java +++ b/plugins/fr.inria.atlanmod.collaboro.backend/src/fr/inria/atlanmod/collaboro/backend/CollaboroBackend.java @@ -1,15 +1,22 @@ package fr.inria.atlanmod.collaboro.backend; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EPackage; +import fr.inria.atlanmod.collaboro.history.Collaboration; import fr.inria.atlanmod.collaboro.history.Comment; import fr.inria.atlanmod.collaboro.history.History; +import fr.inria.atlanmod.collaboro.history.HistoryFactory; import fr.inria.atlanmod.collaboro.history.Proposal; import fr.inria.atlanmod.collaboro.history.Solution; import fr.inria.atlanmod.collaboro.history.User; +import fr.inria.atlanmod.collaboro.history.Version; +import fr.inria.atlanmod.collaboro.history.VersionHistory; import fr.inria.atlanmod.collaboro.notation.Definition; /** @@ -22,27 +29,27 @@ public class CollaboroBackend { private static CollaboroBackend instance; public static String PATH_TO_HISTORY = "C:\\Users\\useradm\\git\\collaboro\\plugins\\fr.inria.atlanmod.collaboro.web.servlets\\WebContent\\WEB-INF\\model\\ModiscoWorkflow.ecore"; - + // Variables to control the state of the collaboration private int historyTracked = 0; private int versionTracked = 0; private int lastIndex = 0; - + ModelManagerFactory modelManagerFactory = new ModelManagerFactory(); ModelManager modelManager = modelManagerFactory.createEmptyModelManager(); - + private CollaboroBackend() { File historyFile = new File(PATH_TO_HISTORY); loadHistory(historyFile); } - + public static CollaboroBackend getInstance() { if(instance == null) { instance = new CollaboroBackend(); } return instance; } - + /** * Sets the user logged in the application. * @@ -52,7 +59,7 @@ public static CollaboroBackend getInstance() { public User loginUser(String email, String password, String dsl) { if(email == null || password == null || dsl == null) throw new IllegalArgumentException("Parameters cannot be null"); - + User found = null; if(getHistory() != null) @@ -62,7 +69,7 @@ public User loginUser(String email, String password, String dsl) { return found; } - + /** * Loads a new History model * @@ -75,7 +82,7 @@ public void loadHistory(Object resource) { if(getHistory() != null) versionTracked = getHistory().getHistories().get(historyTracked).getVersions().size() - 1; } - + /** * Testing method to reset the information */ @@ -84,7 +91,7 @@ public void reset() { historyTracked = 0; versionTracked = 0; } - + private void calculateLastIndexProposal() { lastIndex = 0; @@ -115,7 +122,7 @@ private void calculateLastIndexProposal() { } } } - + public History getHistory() { return modelManager.getHistory(); @@ -128,18 +135,114 @@ public EPackage getEcoreModel() { public Definition getNotation() { return modelManager.getNotation(); } - + public ModelManager getModelManager() { return modelManager; } - + public int getHistoryTracked() { return historyTracked; } - + public int getVersionTracked() { return versionTracked; } + + public void createProposalPlain(String userId, String rationale) { + Proposal newProposal = HistoryFactory.eINSTANCE.createProposal(); + + // Locating the user + User userProposing = null; + if(getHistory() != null) + for (User user : getHistory().getUsers()) + if(user.getId() != null && user.getId().equals(userId)) + userProposing = user; + + if(userProposing != null) { + newProposal.setProposedBy(userProposing); + newProposal.setRationale(rationale); + createProposal(newProposal); + } + } + + public void createProposal(Proposal newProposal) { + newProposal.setId("n" + ++lastIndex); + getProposals().add(newProposal); + Version version = getHistory().getHistories().get(getHistoryTracked()).getVersions().get(getVersionTracked()); + version.getProposals().add(newProposal); + modelManager.saveHistory(); + modelManager.saveNotation(); + System.out.println("Se guardo!"); + } + + public List getProposals() { + List result = new ArrayList(); + + if(getHistory() != null && getHistory().getHistories() != null) { + VersionHistory versionHistory = getHistory().getHistories().get(getHistoryTracked()); + if(versionHistory != null && getHistory().getHistories().get(getHistoryTracked()).getVersions() != null) { + Version version = getHistory().getHistories().get(getHistoryTracked()).getVersions().get(getVersionTracked()); + if(version != null) { + result = getHistory().getHistories().get(getHistoryTracked()).getVersions().get(getVersionTracked()).getProposals(); + } + } + } + return result; + } + + private Collaboration initCollaborationPlain(Collaboration collaboration, String userId, String rationale) { + // Locating the user + User userProposing = null; + if(getHistory() != null) + for (User user : getHistory().getUsers()) + if(user.getId() != null && user.getId().equals(userId)) + userProposing = user; + + if(userProposing != null) { + collaboration.setProposedBy(userProposing); + collaboration.setRationale(rationale); + } + return collaboration; + } + + private Collaboration locateCollaborationById(Collaboration collaboration, String id) { + if(collaboration == null ) { + for(Proposal proposal : getProposals()) + return locateCollaborationById(proposal, id); + } else { + if(collaboration.getId().equals(id)) + return collaboration; + else { + if(collaboration instanceof Proposal) + for(Solution solution : ((Proposal) collaboration).getSols()) + return locateCollaborationById(solution, id); + for(Comment comment : collaboration.getComments()) + return locateCollaborationById(comment, id); + } + } + return null; + } + + public void createCommentPlain(String parentCollaboration, String userId, String rationale) { + Comment newComment = HistoryFactory.eINSTANCE.createComment(); + initCollaborationPlain(newComment, userId, rationale); + + Collaboration parent = locateCollaborationById(null, parentCollaboration); + if(parent != null) + createComment(parent, newComment); + } + + public void createComment(Collaboration collaboration, Comment comment) { + Comment newComment = HistoryFactory.eINSTANCE.createComment(); + newComment.setId("n" + ++lastIndex); + collaboration.getComments().add(newComment); + modelManager.saveHistory(); + modelManager.saveNotation(); + } - + + public void saveHistory() { + modelManager.saveHistory(); + } + } diff --git a/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/JsonCollaborationSimplified.java b/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/JsonCollaborationSimplified.java index a5a5759..ec77d02 100644 --- a/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/JsonCollaborationSimplified.java +++ b/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/JsonCollaborationSimplified.java @@ -17,20 +17,11 @@ * */ public class JsonCollaborationSimplified { - private String proposedBy; - private String rationale; - private String type; - private String parent_id; - public JsonCollaborationSimplified() - { - - } - public String getProposedBy() { return proposedBy; } @@ -58,7 +49,4 @@ public String getParent_id() { public void setType(String type) { this.type = type; } - - - } diff --git a/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/VersionsServlet.java b/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/VersionsServlet.java index 79c0011..ed1b280 100644 --- a/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/VersionsServlet.java +++ b/plugins/fr.inria.atlanmod.collaboro.web.servlets/src/fr/inria/atlanmod/collaboro/web/servlets/VersionsServlet.java @@ -31,6 +31,7 @@ import com.google.gson.JsonParser; +import fr.inria.atlanmod.collaboro.backend.CollaboroBackend; import fr.inria.atlanmod.collaboro.backend.Controller; //import fr.inria.atlanmod.collaboro.web.backend.Controller; import fr.inria.atlanmod.collaboro.history.Collaboration; @@ -54,211 +55,211 @@ @WebServlet(description = "Exposes the versions", urlPatterns = { "/version" }) public class VersionsServlet extends HttpServlet { private static final long serialVersionUID = 1L; - + //History history; Controller controller; - - /** - * @see HttpServlet#HttpServlet() - */ - public VersionsServlet() { - super(); - } - - private String createProposalsResponseJson(VersionHistory versionHistory) - { - String proposalsJson="["; - - EList versions=versionHistory.getVersions(); - if(versions!=null && versions.size()>0) - { - //TODO The request should have as a parameter the version that the user wants. - Version firstVersion=versions.get(versions.size()-1); - EList proposals=firstVersion.getProposals(); - if(proposals!=null && proposals.size()>0) - { - for (Proposal proposal : proposals) - { - + + /** + * @see HttpServlet#HttpServlet() + */ + public VersionsServlet() { + super(); + } + + private String createProposalsResponseJson(VersionHistory versionHistory) + { + String proposalsJson="["; + + EList versions=versionHistory.getVersions(); + if(versions!=null && versions.size()>0) + { + //TODO The request should have as a parameter the version that the user wants. + Version firstVersion=versions.get(versions.size()-1); + EList proposals=firstVersion.getProposals(); + if(proposals!=null && proposals.size()>0) + { + for (Proposal proposal : proposals) + { + String proposalJson=createCollaborationJson(proposal); proposalsJson=proposalsJson.concat(proposalJson).concat(","); } - - proposalsJson=proposalsJson.substring(0,proposalsJson.length()-1); - - } - else - { - proposalsJson=proposalsJson.concat("{\"label\": \"No proposals yet\"}"); - } - - } - - proposalsJson=proposalsJson.concat("]"); - - return proposalsJson; - } - - private String createCollaborationJson(Collaboration collaboration) - { - String collaborationJson=""; - if(collaboration instanceof Comment) - { - collaborationJson=createCommentJson((Comment)collaboration); - } - else - { - collaborationJson="{"+getCollaborationLabel(collaboration); - - //Proposals and Solutions have comments - EList collaborationComments=collaboration.getComments(); - boolean collaborationHasComments=collaborationComments!=null && collaborationComments.size()>0; - if(collaborationHasComments) - { - collaborationHasComments=true; - collaborationJson=collaborationJson.concat(", \"children\": ["); - - for (Comment collaborationComment : collaborationComments) - { - collaborationJson=collaborationJson.concat(createCollaborationJson(collaborationComment).concat(",")); + + proposalsJson=proposalsJson.substring(0,proposalsJson.length()-1); + + } + else + { + proposalsJson=proposalsJson.concat("{\"label\": \"No proposals yet\"}"); + } + + } + + proposalsJson=proposalsJson.concat("]"); + + return proposalsJson; + } + + private String createCollaborationJson(Collaboration collaboration) + { + String collaborationJson=""; + if(collaboration instanceof Comment) + { + collaborationJson=createCommentJson((Comment)collaboration); + } + else + { + collaborationJson="{"+getCollaborationLabel(collaboration); + + //Proposals and Solutions have comments + EList collaborationComments=collaboration.getComments(); + boolean collaborationHasComments=collaborationComments!=null && collaborationComments.size()>0; + if(collaborationHasComments) + { + collaborationHasComments=true; + collaborationJson=collaborationJson.concat(", \"children\": ["); + + for (Comment collaborationComment : collaborationComments) + { + collaborationJson=collaborationJson.concat(createCollaborationJson(collaborationComment).concat(",")); } - - collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); - - - if(collaboration instanceof Proposal) - { - Proposal proposal=(Proposal)collaboration; - EList proposalSols=proposal.getSols(); - - //Continue the children of the proposal with the solutions - collaborationJson=collaborationJson.concat(","); - for (Solution collaborationSolution : proposalSols) - { - collaborationJson=collaborationJson.concat(createCollaborationJson(collaborationSolution).concat(",")); + + collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); + + + if(collaboration instanceof Proposal) + { + Proposal proposal=(Proposal)collaboration; + EList proposalSols=proposal.getSols(); + + //Continue the children of the proposal with the solutions + collaborationJson=collaborationJson.concat(","); + for (Solution collaborationSolution : proposalSols) + { + collaborationJson=collaborationJson.concat(createCollaborationJson(collaborationSolution).concat(",")); } - collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); - - } - collaborationJson=collaborationJson.concat("]"); - } - //Test if is a proposal with no comments but with solutions - else if(collaboration instanceof Proposal) - { - - Proposal proposal=(Proposal)collaboration; - EList proposalSols=proposal.getSols(); - if(proposalSols!=null && proposalSols.size()>0) - { - collaborationJson=collaborationJson.concat(", \"children\": ["); - for (Solution proposalSol : proposalSols) - { + collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); + + } + collaborationJson=collaborationJson.concat("]"); + } + //Test if is a proposal with no comments but with solutions + else if(collaboration instanceof Proposal) + { + + Proposal proposal=(Proposal)collaboration; + EList proposalSols=proposal.getSols(); + if(proposalSols!=null && proposalSols.size()>0) + { + collaborationJson=collaborationJson.concat(", \"children\": ["); + for (Solution proposalSol : proposalSols) + { collaborationJson=collaborationJson.concat(createCollaborationJson(proposalSol).concat(",")); } - collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); - collaborationJson=collaborationJson.concat("]"); - } - - } - //If the collaboration had no comments it was only created with it's label - collaborationJson=collaborationJson.concat("}"); - - } - - return collaborationJson; - } - - - private String getCollaborationLabel(Collaboration collaboration) - { - - String collaborationJson=""; - String typeOfCollaboration=collaboration.eClass().getName(); - String collaborationLabel="\"label\": \"" + typeOfCollaboration + " "+collaboration.getId()+" from "+collaboration.getProposedBy().getId()+"\""; - collaborationJson=collaborationJson.concat(collaborationLabel); - if(collaboration.getRationale()!=null && collaboration.getRationale().length()>0) - { - collaborationJson=collaborationJson.concat(","); - String cleanRationale = collaboration.getRationale().replaceAll("(\\r|\\n|\")", " "); - //String collaborationData="\"data\": { \"username\":\""+ collaboration.getProposedBy().getId() +"\",\"description\": \""+cleanRationale+"\""; - String collaborationType=""; - String parentId=""; - if(collaboration instanceof Solution) - { - collaborationType="Solution"; - parentId=((Solution)collaboration).getProposal().getId(); - } - if(collaboration instanceof Comment) - { - collaborationType="Comment"; - parentId=((Comment)collaboration).getCommentedElement().getId(); - } - - else if(collaboration instanceof Proposal) - collaborationType="Proposal"; - String collaborationData="\"data\": { \"username\":\""+ collaboration.getProposedBy().getId() +"\",\"description\": \""+cleanRationale+"\""+",\"type\": \""+collaborationType+"\""+",\"collaboration_id\": \""+collaboration.getId()+"\""; - if(parentId!="") - collaborationData=collaborationData+",\"parent_id\": \""+parentId+"\""; - - collaborationJson=collaborationJson.concat(collaborationData); - - EList votes=collaboration.getVotes(); - String usersAgree=""; - String usersDisagree=""; - - for (Vote vote : votes) - { - boolean voteAgrees=vote.isAgreement(); - User user=vote.getUser(); - - String userName="Vote with no user name"; - if(user!=null) - userName=user.getId(); - - if(voteAgrees) - { - - usersAgree=usersAgree.concat(userName).concat(", "); - } - - else - usersDisagree=usersDisagree.concat(userName).concat(", "); - } - - if(usersAgree.length()>0) - usersAgree=usersAgree.substring(0,usersAgree.length()-2); - else - usersAgree="No users agree"; - if(usersDisagree.length()>0) - usersDisagree=usersDisagree.substring(0,usersDisagree.length()-2); - else - usersDisagree="No users disagree"; - - collaborationJson=collaborationJson.concat(",\"agree\":\""+usersAgree+"\""); - collaborationJson=collaborationJson.concat(",\"disagree\":\""+usersDisagree+"\"}"); - - } - - - - return collaborationJson; - } - - private String createCommentJson(Comment comment) - { - //String commentJson="{\"label\": \"Comment "+comment.getId()+" from "+comment.getProposedBy().getId()+"\"}"; - String commentJson="{"+getCollaborationLabel(comment)+"}"; - - return commentJson; - } - - - + collaborationJson=collaborationJson.substring(0,collaborationJson.length()-1); + collaborationJson=collaborationJson.concat("]"); + } + + } + //If the collaboration had no comments it was only created with it's label + collaborationJson=collaborationJson.concat("}"); + + } + + return collaborationJson; + } + + + private String getCollaborationLabel(Collaboration collaboration) + { + + String collaborationJson=""; + String typeOfCollaboration=collaboration.eClass().getName(); + String collaborationLabel="\"label\": \"" + typeOfCollaboration + " "+collaboration.getId()+" from "+collaboration.getProposedBy().getId()+"\""; + collaborationJson=collaborationJson.concat(collaborationLabel); + if(collaboration.getRationale()!=null && collaboration.getRationale().length()>0) + { + collaborationJson=collaborationJson.concat(","); + String cleanRationale = collaboration.getRationale().replaceAll("(\\r|\\n|\")", " "); + //String collaborationData="\"data\": { \"username\":\""+ collaboration.getProposedBy().getId() +"\",\"description\": \""+cleanRationale+"\""; + String collaborationType=""; + String parentId=""; + if(collaboration instanceof Solution) + { + collaborationType="Solution"; + parentId=((Solution)collaboration).getProposal().getId(); + } + if(collaboration instanceof Comment) + { + collaborationType="Comment"; + parentId=((Comment)collaboration).getCommentedElement().getId(); + } + + else if(collaboration instanceof Proposal) + collaborationType="Proposal"; + String collaborationData="\"data\": { \"username\":\""+ collaboration.getProposedBy().getId() +"\",\"description\": \""+cleanRationale+"\""+",\"type\": \""+collaborationType+"\""+",\"collaboration_id\": \""+collaboration.getId()+"\""; + if(parentId!="") + collaborationData=collaborationData+",\"parent_id\": \""+parentId+"\""; + + collaborationJson=collaborationJson.concat(collaborationData); + + EList votes=collaboration.getVotes(); + String usersAgree=""; + String usersDisagree=""; + + for (Vote vote : votes) + { + boolean voteAgrees=vote.isAgreement(); + User user=vote.getUser(); + + String userName="Vote with no user name"; + if(user!=null) + userName=user.getId(); + + if(voteAgrees) + { + + usersAgree=usersAgree.concat(userName).concat(", "); + } + + else + usersDisagree=usersDisagree.concat(userName).concat(", "); + } + + if(usersAgree.length()>0) + usersAgree=usersAgree.substring(0,usersAgree.length()-2); + else + usersAgree="No users agree"; + if(usersDisagree.length()>0) + usersDisagree=usersDisagree.substring(0,usersDisagree.length()-2); + else + usersDisagree="No users disagree"; + + collaborationJson=collaborationJson.concat(",\"agree\":\""+usersAgree+"\""); + collaborationJson=collaborationJson.concat(",\"disagree\":\""+usersDisagree+"\"}"); + + } + + + + return collaborationJson; + } + + private String createCommentJson(Comment comment) + { + //String commentJson="{\"label\": \"Comment "+comment.getId()+" from "+comment.getProposedBy().getId()+"\"}"; + String commentJson="{"+getCollaborationLabel(comment)+"}"; + + return commentJson; + } + + + /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - + PrintWriter out = response.getWriter(); HttpSession theSession=request.getSession(); System.out.println("Session creation time: "+theSession.getCreationTime()); @@ -269,98 +270,69 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t } response.setHeader("Access-Control-Allow-Origin", "http://localhost:8001"); response.addHeader("Access-Control-Allow-Credentials", "true"); - response.setContentType("application/json"); - - URI uriHistoryModel=URI.createURI(getServletContext().getRealPath("/WEB-INF/model/ModiscoWorkflow.ecore")); - //URI uriHistoryModel=URI.createFileURI(getServletContext().getRealPath("/WEB-INF/model/ModiscoWorkflow.history")); - - controller=new Controller(uriHistoryModel); - // history=controller.getHistory(); - - String proposalsJson=""; - - EList versionHistories=controller.getHistory().getHistories(); - - if(versionHistories!=null && versionHistories.size()>0) - { - VersionHistory versionHistory=versionHistories.get(versionHistories.size()-1); - proposalsJson=createProposalsResponseJson(versionHistory); - } - - System.out.println(proposalsJson); - out.print(proposalsJson); + response.setContentType("application/json"); + + URI uriHistoryModel=URI.createURI(getServletContext().getRealPath("/WEB-INF/model/ModiscoWorkflow.ecore")); + //URI uriHistoryModel=URI.createFileURI(getServletContext().getRealPath("/WEB-INF/model/ModiscoWorkflow.history")); + + controller=new Controller(uriHistoryModel); + // history=controller.getHistory(); + + String proposalsJson=""; + + EList versionHistories=controller.getHistory().getHistories(); + + if(versionHistories!=null && versionHistories.size()>0) + { + VersionHistory versionHistory=versionHistories.get(versionHistories.size()-1); + proposalsJson=createProposalsResponseJson(versionHistory); + } + + System.out.println(proposalsJson); + out.print(proposalsJson); } - + @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException - { - + protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setHeader("Access-Control-Allow-Origin", "http://localhost:8001"); response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS"); response.addHeader("Access-Control-Allow-Credentials", "true"); - - + + // Getting the parameters from the request StringBuffer jb = new StringBuffer(); String line = null; try { - BufferedReader reader = request.getReader(); - while ((line = reader.readLine()) != null) - jb.append(line); - } catch (Exception e) - { - - } - + BufferedReader reader = request.getReader(); + while ((line = reader.readLine()) != null) + jb.append(line); + } catch (Exception e) { + throw new ServletException("There was an error reading the parameters"); + } System.out.println(jb); - Gson gson = new Gson(); + // Parsing the parameters + Gson gson = new Gson(); JsonParser parser = new JsonParser(); - - JsonArray array=(JsonArray)parser.parse(jb.toString()).getAsJsonObject().get("collaborations"); - - for (JsonElement jsonElement : array) - { - - JsonCollaborationSimplified jsonCollaboration = gson.fromJson(jsonElement, JsonCollaborationSimplified.class); - String collaborationType=jsonCollaboration.getType(); - String parent_id=jsonCollaboration.getParent_id(); - System.out.println("El id de la colaboracion padre: "+ parent_id); - System.out.println("El tipo de la colaboracion: "+collaborationType); - if(collaborationType.compareTo("Proposal")==0) - { - Proposal newProposal = HistoryFactory.eINSTANCE.createProposal(); - EList theUsers=controller.getHistory().getUsers(); - for (User user : theUsers) { - if(user.getId().compareToIgnoreCase(jsonCollaboration.getProposedBy())==0) - newProposal.setProposedBy(user); - } - newProposal.setRationale(jsonCollaboration.getRationale()); - controller.createProposal(newProposal); - } - else if(collaborationType.compareTo("Comment")==0) - { - Comment c= HistoryFactory.eINSTANCE.createComment(); - c.setRationale(jsonCollaboration.getRationale()); - - EList theUsers=controller.getHistory().getUsers(); - for (User user : theUsers) { - if(user.getId().compareToIgnoreCase(jsonCollaboration.getProposedBy())==0) - c.setProposedBy(user); - } - - } - + JsonArray array=(JsonArray)parser.parse(jb.toString()).getAsJsonObject().get("collaborations"); + for (JsonElement jsonElement : array) { + JsonCollaborationSimplified jsonCollaboration = gson.fromJson(jsonElement, JsonCollaborationSimplified.class); + + String collaborationType = jsonCollaboration.getType(); + System.out.println("El tipo de la colaboracion: "+collaborationType); + + if(collaborationType.compareTo("Proposal") == 0) { + CollaboroBackend.getInstance().createProposalPlain(jsonCollaboration.getProposedBy(), jsonCollaboration.getRationale()); + } else if(collaborationType.compareTo("Comment") == 0) { + CollaboroBackend.getInstance().createCommentPlain(jsonCollaboration.getParent_id(), jsonCollaboration.getProposedBy(), jsonCollaboration.getRationale()); + } } - - controller.saveHistory(); - + response.setContentType("application/json"); //TODO Change the response to a success or failure alert out.print("{\"user\": { \"firstName\" : \"Juan\", \"lastName\" : \"Villa\", \"admin\" : false}}"); - } - + @Override protected void doOptions(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { @@ -369,14 +341,14 @@ protected void doOptions(HttpServletRequest request, HttpServletResponse respons response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); response.addHeader("Access-Control-Allow-Credentials", "true"); super.doOptions(request, response); - + } - + private void getNotations() { - + } - + }