Skip to content

Commit

Permalink
Advancing in issue #1. Now the login action queries the backedn to va…
Browse files Browse the repository at this point in the history
…lidate the user
  • Loading branch information
jlcanovas committed Jul 11, 2014
1 parent 4bfa0ca commit 2455df6
Show file tree
Hide file tree
Showing 11 changed files with 1,033 additions and 354 deletions.
13 changes: 13 additions & 0 deletions plugins/fr.inria.atlanmod.collaboro.backend/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Collaboro builder" default="default">
<description>
Build JAR
</description>

<!-- =================================
target: default
================================= -->
<target name="default" description="JAR">
<jar destfile="fr.inria.atlanmod.collaboro.backend.jar" basedir="bin"/>
</target>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package fr.inria.atlanmod.collaboro.backend;

import java.io.File;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;

import fr.inria.atlanmod.collaboro.history.Comment;
import fr.inria.atlanmod.collaboro.history.History;
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.notation.Definition;

/**
* This class is the main entry point to play with Collaboro.
* For the moment, we are moving thing from Controller class here.
*
* @author Javier Canovas ([email protected])
*
*/
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.
*
* @param userName
* @return The user found, null if not
*/
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)
for (User user : getHistory().getUsers())
if(user.getEmail() != null && user.getEmail().equals(email))
return user;

return found;
}

/**
* Loads a new History model
*
* @param resource to be tracked
*/
public void loadHistory(Object resource) {
reset();
modelManager = modelManagerFactory.createModelManager(resource);
calculateLastIndexProposal();
if(getHistory() != null)
versionTracked = getHistory().getHistories().get(historyTracked).getVersions().size() - 1;
}

/**
* Testing method to reset the information
*/
public void reset() {
lastIndex = 0;
historyTracked = 0;
versionTracked = 0;
}

private void calculateLastIndexProposal() {
lastIndex = 0;

if(getHistory() != null) {
for(Proposal proposal : getHistory().getHistories().get(getHistoryTracked()).getVersions().get(getVersionTracked()).getProposals()) {
String idProposal = proposal.getId();
int valueProposal = Integer.valueOf(idProposal.substring(1, idProposal.length()));
if(valueProposal > lastIndex)
lastIndex = valueProposal;
for(Comment comment : proposal.getComments()) {
String idComment = comment.getId();
int valueComment = Integer.valueOf(idComment.substring(1, idComment.length()));
if(valueComment > lastIndex)
lastIndex = valueComment;
}
for(Solution solution : proposal.getSols()) {
String idSolution = solution.getId();
int valueSolution = Integer.valueOf(idSolution.substring(1, idSolution.length()));
if(valueSolution > lastIndex)
lastIndex = valueSolution;
for(Comment comment : solution.getComments()) {
String idCommentSol = comment.getId();
int valueCommentSol = Integer.valueOf(idCommentSol.substring(1, idCommentSol.length()));
if(valueCommentSol > lastIndex)
lastIndex = valueCommentSol;
}
}
}
}
}


public History getHistory() {
return modelManager.getHistory();
}

public EPackage getEcoreModel() {
return modelManager.getEcoreModel();
}

public Definition getNotation() {
return modelManager.getNotation();
}

public ModelManager getModelManager() {
return modelManager;
}

public int getHistoryTracked() {
return historyTracked;
}

public int getVersionTracked() {
return versionTracked;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,8 @@
import fr.inria.atlanmod.collaboro.history.VersionHistory;
import fr.inria.atlanmod.collaboro.notation.Definition;
import fr.inria.atlanmod.collaboro.notation.NotationElement;
//import fr.inria.atlanmod.collaboro.ui.LocalModelManager;
//import fr.inria.atlanmod.collaboro.ui.ModelManager;
//import fr.inria.atlanmod.collaboro.ui.ModelManagerFactory;

/**
*
* @author Juan David Villa Calle
*
*/
public class Controller
{
public class Controller {

// Variables to control the state of the plugin
private User loggedUser = null;
Expand All @@ -47,11 +38,9 @@ public class Controller
ModelManagerFactory modelManagerFactory = new ModelManagerFactory();
ModelManager modelManager = modelManagerFactory.createEmptyModelManager();

public Controller(URI modelBeingTracked)
{
if(modelManager instanceof LocalModelManager)
{
boolean initialized=((LocalModelManager) modelManager).initialize(new File(modelBeingTracked.toString()));
public Controller(URI modelBeingTracked) {
if(modelManager instanceof LocalModelManager) {
boolean initialized = ((LocalModelManager) modelManager).initialize(new File(modelBeingTracked.toString()));
System.out.println("Inicializo al modelManager? "+initialized);
}
}
Expand All @@ -65,15 +54,8 @@ public void reset() {
historyTracked = 0;
versionTracked = 0;
}

//public Controller(URI uriHistoryModel)
//{
//modelManager = new LocalModelManager();
//modelManager.initialize(uriHistoryModel);
//}

public User getLoggedUser()
{

public User getLoggedUser() {
return loggedUser;
}

Expand All @@ -89,8 +71,7 @@ public Definition getNotation() {
return modelManager.getNotation();
}

public ModelManager getModelManager()
{
public ModelManager getModelManager() {
return modelManager;
}

Expand Down
13 changes: 13 additions & 0 deletions plugins/fr.inria.atlanmod.collaboro.history/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Collaboro builder" default="default">
<description>
Build JAR
</description>

<!-- =================================
target: default
================================= -->
<target name="default" description="JAR">
<jar destfile="fr.inria.atlanmod.collaboro.history.jar" basedir="bin"/>
</target>
</project>
13 changes: 13 additions & 0 deletions plugins/fr.inria.atlanmod.collaboro.notation/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Collaboro builder" default="default">
<description>
Build JAR
</description>

<!-- =================================
target: default
================================= -->
<target name="default" description="JAR">
<jar destfile="fr.inria.atlanmod.collaboro.notation.jar" basedir="bin"/>
</target>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 2455df6

Please sign in to comment.