diff --git a/UserAgentsServices.xml b/UserAgentsServices.xml
index 917d13b..138b3dd 100644
--- a/UserAgentsServices.xml
+++ b/UserAgentsServices.xml
@@ -31,6 +31,13 @@
mas
SACIP
+
+ registerStudent
+ faz o login do estudante no sistema
+ PedagogicalAgent
+ mas
+ SACIP
+
diff --git a/board.bkp b/board.bkp
index f0ffc30..4917a58 100644
Binary files a/board.bkp and b/board.bkp differ
diff --git a/src/main/java/sacip/Launcher.java b/src/main/java/sacip/Launcher.java
index f36db8a..5c16090 100644
--- a/src/main/java/sacip/Launcher.java
+++ b/src/main/java/sacip/Launcher.java
@@ -38,7 +38,7 @@ public static void main(String[] args) {
// for (String beanName : beanNames) {
// System.out.println(beanName);
// }
- Manager.getInstance().disconnect(true);
+ //Manager.getInstance().disconnect(true);
} catch (IOException e) {
e.printStackTrace();
diff --git a/src/main/java/sacip/sti/agents/InterfaceAgent.java b/src/main/java/sacip/sti/agents/InterfaceAgent.java
index 128d15d..a124a89 100644
--- a/src/main/java/sacip/sti/agents/InterfaceAgent.java
+++ b/src/main/java/sacip/sti/agents/InterfaceAgent.java
@@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -31,7 +32,7 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
-import sacip.sti.components.DBConnection;
+
import sacip.sti.dataentities.Content;
import sacip.sti.dataentities.Student;
@@ -41,15 +42,13 @@
public class InterfaceAgent extends Agent implements MessageListener{
private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
- public int localport;
+ public int localport = 7102;
public final String serverport = "7100";
public final String serverAddress = "127.0.0.1";
private static Map usuariosConectados;
public InterfaceAgent() {
- super();
- this.localport = Integer.parseInt(super.recoverMetaInformation().getContainerPort());
- this.localport++;
+ super();
usuariosConectados = new HashMap<>();
}
@@ -85,10 +84,22 @@ public String criaNovaConta(@RequestBody Student conta) {
}
}
+ @PostMapping("/logout/{agentPort}")
+ @ResponseBody
+ public String deslogar(@PathVariable String agentPort) {
+
+ try {
+ Manager.getInstance().disconnect(agentPort, true);
+ return "SUCESSO";
+ } catch (Exception e) {
+ LOG.error("Falhou criar conta em REST Interface", e);
+ return "Falhou criar conta: \n"+e.getLocalizedMessage();
+ }
+ }
+
@PostMapping("/login")
@ResponseBody
public String fazLogin(@RequestBody JsonNode credenciais) {
-
try {
String usuario = credenciais.get("usuario").asText();
String senha = credenciais.get("senha").asText();
@@ -117,14 +128,17 @@ public String fazLogin(@RequestBody JsonNode credenciais) {
do {
try
{
- super.recoverMetaInformation().getOrganizationByName("SACIP"+setLocal).getEntityByName("PedagogicalAgent"+setLocal);
+ Catalog.getEntityByName(setLocal+"", "SACIP"+setLocal, "PedagogicalAgent"+setLocal);
break;
}
catch (Exception e) {
+ LOG.error("Entidade não encontrada", e);
Thread.sleep(1000);
}
} while (true);
-
+
+ require("SACIP"+setLocal, "registerStudent"+setLocal).run();
+
return setLocal+"";
} catch (Exception e) {
@@ -175,7 +189,7 @@ public void iniciandoAgentesUsuario(String instancia) throws IOException
//Inicializando Agentes do Usuário
String UserAgentsStructureXML = readFile("UserAgentsStructure.xml");
String UserAgentsServicesXML = readFile("UserAgentsServices.xml");
- UserAgentsStructureXML = UserAgentsStructureXML.replace("$localport", localport+"").replace("$serverport", serverport).replace("$serverAddress", serverAddress).replace("", instancia+"");
+ UserAgentsStructureXML = UserAgentsStructureXML.replace("$localport", instancia+"").replace("$serverport", serverport).replace("$serverAddress", serverAddress).replace("", instancia+"");
UserAgentsServicesXML = UserAgentsServicesXML.replace("", instancia+"").replace("", instancia+"").replace("", instancia+"");
AgentServer.initialize(true, true, UserAgentsStructureXML, UserAgentsServicesXML);
}
diff --git a/src/main/java/sacip/sti/agents/PedagogicalAgent.java b/src/main/java/sacip/sti/agents/PedagogicalAgent.java
index 28118f5..150edc3 100644
--- a/src/main/java/sacip/sti/agents/PedagogicalAgent.java
+++ b/src/main/java/sacip/sti/agents/PedagogicalAgent.java
@@ -24,24 +24,19 @@
public class PedagogicalAgent extends Agent implements MessageListener {
- private final String port;
private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
private Student student;
List trilha = new ArrayList<>();
public PedagogicalAgent() {
super();
- this.port = super.recoverMetaInformation().getContainerPort();
- registrarAluno();
- //montarAlunoExemplo();
- registrarConteudosDaTrilhaDoAluno();
}
private void registrarAluno()
{
try {
Map usuariosConectados = (Map) Board.getContextAttribute("conectedUsers");
- this.student = usuariosConectados.get(this.port);
+ this.student = usuariosConectados.get(super.getPort());
} catch (Exception e) {
LOG.error("Problema no registro do usuario", e);
}
@@ -89,7 +84,7 @@ private void registrarConteudosDaTrilhaDoAluno() {
@Override
public void provide(String service, Map in, List out) throws ServiceException {
- switch (service.replace(this.port, "")) {
+ switch (service.replace(super.getPort(), "")) {
case "getAluno":
out.add(getAluno());
break;
@@ -98,6 +93,12 @@ public void provide(String service, Map in, List out) throws ServiceException {
out.add(suggestContent());
break;
+ case "registerStudent":
+ registrarAluno();
+ //montarAlunoExemplo();
+ registrarConteudosDaTrilhaDoAluno();
+ break;
+
default:
throw new ServiceException("Serviço " + service + " não foi implementado no agente pedagógico.");
}
@@ -105,7 +106,18 @@ public void provide(String service, Map in, List out) throws ServiceException {
@Override
protected void lifeCycle() throws LifeCycleException, InterruptedException {
-
+ // while(alive)
+ // {
+ // try {
+ // if(super.getPort()!=null && this.student == null)
+ // {
+
+ // break;
+ // }
+ // } catch (Exception e) {
+ // //TODO: handle exception
+ // }
+ // }
}
@Override
diff --git a/src/main/java/sacip/sti/agents/RecommenderAgent.java b/src/main/java/sacip/sti/agents/RecommenderAgent.java
index 3c36386..a3b6aa7 100644
--- a/src/main/java/sacip/sti/agents/RecommenderAgent.java
+++ b/src/main/java/sacip/sti/agents/RecommenderAgent.java
@@ -32,7 +32,7 @@ public class RecommenderAgent extends Agent {
private static final int ANALISAR = 3;
private static final int AVALIAR = 4;
private static final int CRIAR = 5;
-
+
@Override
public void provide(String service, Map in, List out) throws ServiceException {
switch (service)
diff --git a/src/main/java/sacip/sti/agents/TrackingAgent.java b/src/main/java/sacip/sti/agents/TrackingAgent.java
index 91d8791..725bf69 100644
--- a/src/main/java/sacip/sti/agents/TrackingAgent.java
+++ b/src/main/java/sacip/sti/agents/TrackingAgent.java
@@ -32,12 +32,7 @@
public class TrackingAgent extends Agent implements MessageListener {
private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
- private final String port;
-
- public TrackingAgent() {
- super();
- this.port = super.recoverMetaInformation().getContainerPort();
- }
+ private String port;
@Override
public void provide(String service, Map in, List out) throws ServiceException {
@@ -45,7 +40,7 @@ public void provide(String service, Map in, List out) throws ServiceException {
JsonNode dados = (JsonNode) in.get("dados");
String nome = dados.get("nome").asText();
- switch (service.replace(this.port, ""))
+ switch (service.replace(super.getPort(), ""))
{
case "storeData":
if (dados.has("cliques")) {