diff --git a/build.gradle b/build.gradle
index 3bd6612..1d53e0b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -38,9 +38,10 @@ dependencies {
implementation 'br.com.smartechnology.midas:agent-server:1.2.0'
// https://mvnrepository.com/artifact/org.json/json
- implementation 'org.json:json:20200518'
+ // implementation 'org.json:json:20200518'
-
+ // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
+ implementation 'com.fasterxml.jackson.core:jackson-core:2.11.3'
// https://mvnrepository.com/artifact/org.neo4j.driver/neo4j-java-driver
implementation 'org.neo4j.driver:neo4j-java-driver:4.1.1'
diff --git a/services.xml b/services.xml
index ff2d004..40e7420 100644
--- a/services.xml
+++ b/services.xml
@@ -64,11 +64,6 @@
InterfaceAgent
mas
SACIP
-
-
- novaContaorg.json.JSONObject
-
-
diff --git a/src/main/java/sacip/rest/RestInterface.java b/src/main/java/sacip/rest/RestInterface.java
index d2c0401..fc846c8 100644
--- a/src/main/java/sacip/rest/RestInterface.java
+++ b/src/main/java/sacip/rest/RestInterface.java
@@ -3,16 +3,27 @@
import java.util.List;
import java.util.Map;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import org.midas.as.AgentServer;
import org.midas.as.manager.execution.ServiceWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
+import sacip.sti.dataentities.Student;
+
@RestController
@RequestMapping("/interface")
public class RestInterface {
private String test = "HELLO WORLD";
+ private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
+
+ public RestInterface() {
+ super();
+ }
@GetMapping("/contas")
public String fazLogin() {
@@ -21,22 +32,17 @@ public String fazLogin() {
@PostMapping("/contas")
@ResponseBody
- public String criaNovaConta(@RequestBody Map conta) {
+ public String criaNovaConta(@RequestBody Student conta) {
try {
- //TODO Tentar fazer pegar JSON
-
- System.out.println("REQUEST JSON" + conta.toString());
ServiceWrapper wrapper = AgentServer.require("SACIP", "createAccount");
- wrapper.addParameter("novaConta", new JSONObject(conta));
+ wrapper.addParameter("novaConta", conta);
List run = wrapper.run();
return run.toString();
-
} catch (Exception e) {
- e.printStackTrace();
- return "Falhou criar conta: \n"+e;
+ LOG.error("Falhou criar conta em REST Interface", e);
+ return "Falhou criar conta: \n"+e.getLocalizedMessage();
}
-
}
@PutMapping("/contas")
diff --git a/src/main/java/sacip/sti/agents/InterfaceAgent.java b/src/main/java/sacip/sti/agents/InterfaceAgent.java
index b17c042..f969222 100644
--- a/src/main/java/sacip/sti/agents/InterfaceAgent.java
+++ b/src/main/java/sacip/sti/agents/InterfaceAgent.java
@@ -3,16 +3,20 @@
import java.util.List;
import java.util.Map;
-import org.json.JSONObject;
+import org.midas.as.AgentServer;
import org.midas.as.agent.board.Message;
import org.midas.as.agent.board.MessageListener;
import org.midas.as.agent.templates.Agent;
import org.midas.as.agent.templates.LifeCycleException;
import org.midas.as.agent.templates.ServiceException;
import org.midas.as.manager.execution.ServiceWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class InterfaceAgent extends Agent implements MessageListener{
+ private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
+
@Override
public void boardChanged(Message msg) {
// TODO Auto-generated method stub
@@ -24,25 +28,14 @@ public void provide(String service, Map in, List out) throws ServiceException {
if(service.equals("createAccount"))
{
- try {
- System.out.println("CRIANDO CONTA");
- JSONObject conta = (JSONObject) in.get("novaConta");
- System.out.println("GERANDO JSON" + conta.toString());
+ try {
ServiceWrapper wrapper = require("SACIP", "createStudent");
- // wrapper.setParameters(in);
- wrapper.addParameter("name", conta.get("name"));
- wrapper.addParameter("password", conta.get("password"));
- wrapper.addParameter("avatar", conta.get("avatar"));
- wrapper.addParameter("genero", conta.get("genero"));
- wrapper.addParameter("idade", conta.get("idade"));
- wrapper.addParameter("nivelEdu", conta.get("nivelEdu"));
- wrapper.addParameter("preferencias", conta.get("preferencias"));
- System.out.println("GERANDO PARAMETROS");
- out = wrapper.run();
+ wrapper.addParameter("conta", in.get("novaConta"));
+ List response = wrapper.run();
+ out.add(response.get(0));
} catch (Exception e) {
- e.printStackTrace();
- System.out.println("FALHOU INTERFACE AGENT"+e);
+ LOG.error("Falhou criar conta", e);
out.add("FALHOU INTERFACE AGENT"+e);
}
}
diff --git a/src/main/java/sacip/sti/components/DBConnection.java b/src/main/java/sacip/sti/components/DBConnection.java
index 1a98311..c643bea 100644
--- a/src/main/java/sacip/sti/components/DBConnection.java
+++ b/src/main/java/sacip/sti/components/DBConnection.java
@@ -1,27 +1,28 @@
package sacip.sti.components;
-import java.lang.reflect.Array;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.json.JSONArray;
+import org.midas.as.AgentServer;
import org.midas.as.agent.templates.Component;
import org.midas.as.agent.templates.ServiceException;
-import org.neo4j.driver.Result;
import sacip.sti.dataentities.Content;
import sacip.sti.dataentities.Student;
import sacip.sti.utils.BoltCypherExecutor;
import sacip.sti.utils.CypherExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
@SuppressWarnings("unchecked")
public class DBConnection extends Component {
private final CypherExecutor cypher;
+ private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
public DBConnection() {
super();
@@ -34,7 +35,7 @@ public void provide(String service, Map in, List out) throws ServiceException {
switch (service)
{
case "createStudent":
- out.add(createUser(instanceStudent(in)));
+ out.add(createUser((Student)in.get("conta")));
break;
case "findStudents":
@@ -70,9 +71,7 @@ public void provide(String service, Map in, List out) throws ServiceException {
private Student instanceStudent(Map in)
{
- System.out.println("INSTANCIA ESTUDANTE " + in.get("preferencias"));
- ObjectMapper mapper = new ObjectMapper();
-
+ ObjectMapper mapper = new ObjectMapper();
try {
return new Student((String)in.get("name"),
(String)in.get("password"),
@@ -80,12 +79,10 @@ private Student instanceStudent(Map in)
(String)in.get("genero"),
(Integer)in.get("idade"),
(String)in.get("nivelEdu"),
- mapper.readValue(((JSONArray) in.get("preferencias")).toString(), List.class));
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println(e.getLocalizedMessage() +"\n "+Arrays.asList(e.getStackTrace()));
- //TODO REMOVER ISSOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
- return new Student();
+ (List) in.get("preferencias"));
+ } catch (Exception e) {
+ LOG.error("Não foi possível instanciar o estudante", e);
+ return null;
}
}
@@ -101,8 +98,8 @@ private Content instanceContent(Map in)
(List) in.get("tags"),
(String)in.get("link"));
} catch (Exception e) {
- e.printStackTrace();
- return new Content();
+ LOG.error("Não foi possível instanciar o conteúdo", e);
+ return null;
}
}
@@ -116,8 +113,7 @@ private Content instanceContent(Map in)
public String createUser(Student student) {
try
{
- System.out.println("INICIOU QUERY " + student.toString());
- List