diff --git a/build.gradle b/build.gradle index 1d53e0b..0779dda 100644 --- a/build.gradle +++ b/build.gradle @@ -6,10 +6,13 @@ * User Manual available at https://docs.gradle.org/6.6.1/userguide/tutorial_java_projects.html */ + plugins { // Apply the java plugin to add support for Java id 'java' + id 'java-library' + // Apply the application plugin to add support for building a CLI application. id 'application' @@ -17,6 +20,13 @@ plugins { id 'io.spring.dependency-management' version '1.0.10.RELEASE' } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +version = '1.2.1' + configurations { all*.exclude module : 'spring-boot-starter-logging' //all*.exclude module : 'logback-classic' @@ -56,3 +66,14 @@ application { // Define the main class for the application. mainClassName = 'sacip.Launcher' } + +//create a single Jar with all dependencies +task fatJar(type: Jar) { + manifest { + attributes 'Implementation-Title': 'SACIP', + 'Main-Class': 'sacip.Launcher' + } + baseName = project.name + '-all' + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} diff --git a/src/main/java/sacip/rest/RestTracking.java b/src/main/java/sacip/rest/RestTracking.java index d3faedc..5143d7d 100644 --- a/src/main/java/sacip/rest/RestTracking.java +++ b/src/main/java/sacip/rest/RestTracking.java @@ -21,8 +21,6 @@ public class RestTracking { @PostMapping("/dadosUso") public String armazenaDadosUso(@RequestBody JsonNode dados){ - // String names[] = {"Componente Clicado", "Modulo", "Timestamp", "Usuario", "IP"}; - // String modulos[] = {"Exercicio", "ConteudoNE", "Exemplos", "OGPor", "Ajuda"}; // String informacoesInteressantes[] = {"Modulos mais utilizados", "Tags de Conteudo mais utilizadas", "Tópicos mais utilizados", "Frequencia de entrada no sistema", "Tempo gasto por tópico", // "Tempo gasto por tag", "Tempo gasto por Modulo", "Exercicios que foi bem?"}; try @@ -34,21 +32,43 @@ public String armazenaDadosUso(@RequestBody JsonNode dados){ } catch (Exception e) { - LOG.error("Ocorreu erro ao enviar ao agente Tracking", e); + LOG.error("Ocorreu erro ao enviar dados de uso ao agente Tracking", e); return e.getLocalizedMessage(); } } @PostMapping("/exercicioResolvido") - public String armazenaExercicioResolvido() + public String armazenaExercicioResolvido(@RequestBody JsonNode dados) { - return ""; + try + { + ServiceWrapper wrapper = AgentServer.require("SACIP", "storeSolvedExercise"); + wrapper.addParameter("dados", dados); + List out = wrapper.run(); + return (String) out.get(0); + } + catch (Exception e) + { + LOG.error("Ocorreu erro ao enviar exercicio resolvido ao agente Tracking", e); + return e.getLocalizedMessage(); + } } @PostMapping("/novoConteudoTrilha") - public String armazenaNovoConteudoTrilha() + public String armazenaNovoConteudoTrilha(@RequestBody JsonNode dados) { - return ""; + try + { + ServiceWrapper wrapper = AgentServer.require("SACIP", "storeContentOnPath"); + wrapper.addParameter("dados", dados); + List out = wrapper.run(); + return (String) out.get(0); + } + catch (Exception e) + { + LOG.error("Ocorreu erro ao enviar exercicio resolvido ao agente Tracking", e); + return e.getLocalizedMessage(); + } } } diff --git a/src/main/java/sacip/sti/agents/TrackingAgent.java b/src/main/java/sacip/sti/agents/TrackingAgent.java index 567ca1e..f98b759 100644 --- a/src/main/java/sacip/sti/agents/TrackingAgent.java +++ b/src/main/java/sacip/sti/agents/TrackingAgent.java @@ -40,49 +40,64 @@ public void provide(String service, Map in, List out) throws ServiceException { List dadosO = new ArrayList<>(); List dadosA = new ArrayList<>(); List dadosE = new ArrayList<>(); - System.out.println(jsonobject.get("cliques").getClass()); - if(jsonobject.get("cliques").isArray()) + if(jsonobject.has("cliques")) { - ArrayNode cliqueArray = (ArrayNode) jsonobject.get("cliques"); - for (JsonNode jsonNode : cliqueArray) { - String modulo = jsonNode.get("modulo").asText(); - switch(modulo) - { - case "Exemplo": - dadosE.add(jsonNode.toString()); - break; - - case "Conteudo": - dadosC.add(jsonNode.toString()); - break; - - case "Ajuda": - dadosA.add(jsonNode.toString()); - break; - - case "OGPor": - dadosO.add(jsonNode.toString()); - break; + if(jsonobject.get("cliques").isArray()) + { + ArrayNode cliqueArray = (ArrayNode) jsonobject.get("cliques"); + for (JsonNode jsonNode : cliqueArray) { + String modulo = jsonNode.get("modulo").asText(); + switch(modulo) + { + case "Exemplo": + dadosE.add(jsonNode.toString()); + break; + + case "Conteudo": + dadosC.add(jsonNode.toString()); + break; + + case "Ajuda": + dadosA.add(jsonNode.toString()); + break; + + case "OGPor": + dadosO.add(jsonNode.toString()); + break; + } } } + + Map dadoss = Map.of("Conteudo", dadosC, "OGPor", dadosO, "Ajuda", dadosA, "Exemplos", dadosE); + + try { + ServiceWrapper wrapper = require("SACIP", "storeStudentUseData"); + wrapper.addParameter("name", nome); + wrapper.addParameter("data", dadoss); + out.add(wrapper.run().get(0)); + } catch (Exception e) { + out.add(e.getLocalizedMessage()); + LOG.error("ERRO NO TRACKING AGENT AO ENVIAR DADOS", e); + e.printStackTrace(); + } } - - - Map dadoss = Map.of("Conteudo", dadosC, "OGPor", dadosO, "Ajuda", dadosA, "Exemplos", dadosE); - - try { - ServiceWrapper wrapper = require("SACIP", "storeStudentUseData"); - wrapper.addParameter("name", nome); - wrapper.addParameter("data", dadoss); - out.add(wrapper.run().get(0)); - } catch (Exception e) { - // TODO Auto-generated catch block - out.add(e.getLocalizedMessage()); - LOG.error("ERRO NO TRACKING AGENT AO ENVIAR DADOS", e); - e.printStackTrace(); - } + if(jsonobject.has("conteudo")) + { + try { + ServiceWrapper wrapper = require("SACIP", "storeStudentContentUse"); + wrapper.addParameter("name", nome); + wrapper.addParameter("content", jsonobject.get("conteudo")); + out.add(wrapper.run().get(0)); + } catch (Exception e) { + out.add(e.getLocalizedMessage()); + LOG.error("ERRO NO TRACKING AGENT AO ENVIAR DADOS", e); + e.printStackTrace(); + } + } } + + } } diff --git a/src/main/java/sacip/sti/components/DBConnection.java b/src/main/java/sacip/sti/components/DBConnection.java index 121011c..5b14ea9 100644 --- a/src/main/java/sacip/sti/components/DBConnection.java +++ b/src/main/java/sacip/sti/components/DBConnection.java @@ -56,6 +56,9 @@ public void provide(String service, Map in, List out) throws ServiceException { case "storeStudentUseData": out.add(addClickInformation((String)in.get("name"), (Map)in.get("data"))); break; + case "storeStudentContentUse": + out.add(addContentUseInformation((String)in.get("name"), (JsonNode)in.get("content"))); + break; case "createContent": out.add(createContent((Content)in.get("conta"))); break; @@ -143,6 +146,20 @@ public String createUser(Student student) { } } + private Object addContentUseInformation(String name, JsonNode contentdata) + { + try { + String query = "MATCH (n:USER { name : $name})"+ + "MERGE (n)-[:USES]-(k:CONTENTUSE {name:$name})"+ + "SET k.log = coalesce(k.log, []) + $klog"; + var result = cypher.writequery(query, Map.of("name", name, "klog", contentdata.toString())); + return result.toString(); + } catch (Exception e) { + LOG.error("FALHOU AO ADICIONAR DADOS DE CONTEUDO USADO", e); + return "FALHOU AO ADICIONAR DADOS DE CONTEUDO USADO"+ e; + } + } + private Object addClickInformation(String name, Map cliqueReg){ try { @@ -154,24 +171,22 @@ private Object addClickInformation(String name, Map cliqueReg){ switch(entry.getKey()) { case "Conteudo": - query.append("\nMERGE (n)-[:CLICKS]-(c:CONTENT{name: $name})"); + query.append("\nMERGE (n)-[:CLICKS]-(c:CONTENTLOG{name: $name})"); break; case "Exemplos": - query.append("\nMERGE (n)-[:CLICKS]-(e:EXEMPLO{name: $name})"); + query.append("\nMERGE (n)-[:CLICKS]-(e:EXEMPLOLOG{name: $name})"); break; case "OGPor": - query.append("\nMERGE (n)-[:CLICKS]-(o:OGPOR{name: $name})"); + query.append("\nMERGE (n)-[:CLICKS]-(o:OGPORLOG{name: $name})"); break; case "Ajuda": - query.append("\nMERGE (n)-[:CLICKS]-(a:AJUDA{name: $name})"); + query.append("\nMERGE (n)-[:CLICKS]-(a:AJUDALOG{name: $name})"); break; } } - //query.deleteCharAt(query.length()-1); - //query.append("\nSET"); for (Map.Entry entry : cliqueReg.entrySet()) { switch(entry.getKey()) { @@ -197,7 +212,6 @@ private Object addClickInformation(String name, Map cliqueReg){ } } query.append("\nRETURN n"); - System.out.println(query.toString()); //realisa o set var result = cypher.writequery(query.toString(), updates); if(result.isEmpty()) @@ -205,7 +219,7 @@ private Object addClickInformation(String name, Map cliqueReg){ return "SUCESSO"; } - return "SUCESSO"; + return result.toString(); } catch (Exception e) { diff --git a/structure.xml b/structure.xml index da2c490..5f7fd49 100644 --- a/structure.xml +++ b/structure.xml @@ -4,8 +4,8 @@ 7101 7100 - 127.0.0.1 - + + 35.192.97.232