Commit b13d9202 authored by Maximo's avatar Maximo

Publicar y Comentar Comentario (No funciona la respuesta JSON de lo que se comento pero si comenta bien)
parent 1a8ca5ff
Twotter-ejb/target/
Twotter-ear/target/
Twotter-web/target/
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- This is an unmanaged datasource. It should be used for proofs of concept
or testing only. It uses H2, an in memory database that ships with JBoss
AS. -->
<datasources xmlns="http://www.jboss.org/ironjacamar/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<!-- The datasource is bound into JNDI at this location. We reference
this in META-INF/persistence.xml -->
<datasource jndi-name="java:jboss/datasources/TwotterDS" pool-name="Twotter"
enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:Twotter;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
</datasources>
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>Twotter-ear</display-name>
<module>
<web>
<web-uri>Twotter-web.war</web-uri>
<context-root>/Twotter-web</context-root>
</web>
</module>
<module>
<ejb>Twotter-ejb.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>Twotter-ear</display-name>
<module>
<web>
<web-uri>Twotter-web.war</web-uri>
<context-root>/Twotter-web</context-root>
</web>
</module>
<module>
<ejb>Twotter-ejb.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
\ No newline at end of file
Manifest-Version: 1.0
Built-By: emibo
Build-Jdk: 1.8.0_221
Created-By: Maven Integration for Eclipse
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>Twotter-ear</display-name>
<module>
<web>
<web-uri>Twotter-web.war</web-uri>
<context-root>/Twotter-web</context-root>
</web>
</module>
<module>
<ejb>Twotter-ejb.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
\ No newline at end of file
#Generated by Maven Integration for Eclipse
#Sat Nov 02 17:12:00 UYT 2019
version=0.0.1-SNAPSHOT
groupId=fing.edu.uy
m2e.projectName=Twotter-ear
m2e.projectLocation=C\:\\Users\\emibo\\Documents\\Desarollo\\twotter\\source\\Twotter\\Twotter-ear
artifactId=Twotter-ear
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>Twotter</artifactId>
<groupId>fing.edu.uy</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Twotter-ear</artifactId>
<packaging>ear</packaging>
<name>Twotter: EAR Module</name>
<url>http://wildfly.org</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<dependencies>
<!-- Depend on the ejb module and war so that we can package them -->
<dependency>
<groupId>fing.edu.uy</groupId>
<artifactId>Twotter-web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>fing.edu.uy</groupId>
<artifactId>Twotter-ejb</artifactId>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<!-- Tell Maven we are using Java EE 7 -->
<version>7</version>
<!-- Use Java EE ear libraries as needed. Java EE ear libraries
are in easy way to package any libraries needed in the ear, and automatically
have any modules (EJB-JARs and WARs) use them -->
<defaultLibBundleDir>lib</defaultLibBundleDir>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
<!-- The WildFly plugin deploys your ear to a local WildFly container -->
<!-- Due to Maven's lack of intelligence with EARs we need to configure
the wildfly maven plugin to skip deployment for all modules. We then enable
it specifically in the ear module. -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<filename>${project.artifactId}.ear</filename>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app will need. -->
<!-- By default that is to put the resulting archive into the 'deployments' folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
#Generated by Apache Maven
#Sun Nov 03 00:26:29 UYT 2019
version=0.0.1-SNAPSHOT
groupId=fing.edu.uy
artifactId=Twotter-ear
package DataTypes;
import java.util.List;
public class DataComentarComentario {
private String id;
private String texto;
private String emailUsuario;
private List<DataComentarComentario> comentarios;
private String idPadre;
public DataComentarComentario() {
super();
}
public DataComentarComentario(String id, String texto, String emailUsuario) {
super();
this.id = id;
this.texto = texto;
this.emailUsuario = emailUsuario;
}
public DataComentarComentario(String texto, String emailUsuario) {
super();
this.texto = texto;
this.emailUsuario = emailUsuario;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTexto() {
return texto;
}
public void setTexto(String texto) {
this.texto = texto;
}
public String getEmailUsuario() {
return emailUsuario;
}
public void setEmailUsuario(String emailUsuario) {
this.emailUsuario = emailUsuario;
}
public List<DataComentarComentario> getComentarios() {
return comentarios;
}
public void setComentarios(List<DataComentarComentario> comentarios) {
this.comentarios = comentarios;
}
public String getIdPadre() {
return idPadre;
}
public void setIdPadre(String idPadre) {
this.idPadre = idPadre;
}
}
package dao;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
......@@ -97,6 +99,80 @@ public class FacadeDao implements FacadeDaoLocal {
}
@Override
public DataComentario altaComentario(String id, String texto, String emailUsuario) {
if (id.equals("0")) {
// if (id.isEmpty() || id == null) {
if ( texto != null && emailUsuario != null) {
Comentario c = new Comentario(texto,emailUsuario);
session.store(c);
session.saveChanges();
return new DataComentario(c.getId(),c.getTexto(),c.getEmailUsuario());
}
}else {
if ( id != "0" && texto != null && emailUsuario != null) {
Comentario c = new Comentario(texto,emailUsuario);
session.store(c);
session.saveChanges();
System.out.println("Se guardo el comentario hijo " + c.getId());
//session.advanced()
//.patch("comentarios/"+id, "idComentarios", idComentarios -> idComentarios.add("comentarios/"+c.getId()));
//session.saveChanges();
session.advanced().patch("comentarios/"+id, "idComentarios", idComentarios -> idComentarios.add(c.getId()));
session.saveChanges();
Comentario padre = this.obtenerComentario("comentarios/"+id);
System.out.println("Se intento actualizar el comentario del padre " + padre.getId());
//List<String> idComentarios = new ArrayList<String>();
//padre.setIdComentarios(idComentarios);
DataComentario p = new DataComentario();
p.setId(padre.getId());
p.setTexto(padre.getTexto());
p.setEmailUsuario(padre.getEmailUsuario());
List<DataComentario> lista = new ArrayList<DataComentario>();
Comentario cTemp = new Comentario();
DataComentario dcTemp = new DataComentario();
for (String idC : padre.getIdComentarios()) {
cTemp= this.obtenerComentario("comentarios/"+idC);
dcTemp.setId(cTemp.getId());
dcTemp.setTexto(cTemp.getTexto());
dcTemp.setEmailUsuario(cTemp.getEmailUsuario());
lista.add(dcTemp);
}
p.setComentarios(lista);
return p;
}
}
return null;
}
@Override
public Comentario obtenerComentario(String idComentario) {
DataComentario dc = new DataComentario();
Comentario c = null;
if(idComentario != null) {
//precargo la id de usuario
String preComentario = "comentarios/";
preComentario = preComentario+idComentario;
//consulto comentario por id
c = session.include("comentarios[]").load(Comentario.class, idComentario);
/*if(c != null) {
//cargo datos del comentario
c.setId(c.getId());
c.setEmailUsuario(c.getEmailUsuario());
c.setTexto(c.getTexto());
}*/
}
return c;
}
......
......@@ -2,7 +2,9 @@ package dao;
import javax.ejb.Local;
import DataTypes.DataComentario;
import DataTypes.DataUsuario;
import modelo.Comentario;
import modelo.Usuario;
@Local
public interface FacadeDaoLocal {
......@@ -12,6 +14,10 @@ public interface FacadeDaoLocal {
public DataUsuario obtenerUsuario(String id, String mail);
public Boolean existeEmail(String email);
public DataComentario altaComentario(String id, String texto, String emailUsuario);
public Comentario obtenerComentario(String id);
}
package modelo;
import java.util.ArrayList;
import java.util.List;
public class Comentario {
......@@ -19,6 +20,7 @@ public class Comentario {
super();
this.texto = texto;
this.emailUsuario = emailUsuario;
this.idComentarios = new ArrayList<String>();
}
public String getId() {
return id;
......
......@@ -4,8 +4,10 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import DataTypes.DataComentario;
import DataTypes.DataUsuario;
import dao.FacadeDaoLocal;
import modelo.Comentario;
import modelo.Usuario;
/**
......@@ -32,6 +34,16 @@ public class FacadeNegocio implements FacadeNegocioLocal {
return new DataUsuario(u.getId(),u.getNombre(), u.getEmail());
}
}
public DataComentario altaComentario(String id, String texto, String emailUsuario) throws Exception {
if(dao.existeEmail(emailUsuario)) {
DataComentario c = dao.altaComentario(id, texto, emailUsuario);
return c;//new DataComentario(c.getId(),c.getTexto(), c.getEmailUsuario());
} else {
throw new Exception("El email "+emailUsuario+" no es valido");
}
}
}
package negocio;
import java.util.List;
import javax.ejb.Local;
import DataTypes.DataComentario;
import DataTypes.DataUsuario;
@Local
public interface FacadeNegocioLocal {
public DataUsuario altaUsuario(String nombre, String mail) throws Exception;
public DataComentario altaComentario(String id, String texto, String emailUsuario) throws Exception;
}
Manifest-Version: 1.0
Built-By: emibo
Build-Jdk: 1.8.0_221
Created-By: Maven Integration for Eclipse
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Marker file indicating CDI should be enabled -->
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
</beans>
#Generated by Maven Integration for Eclipse
#Sat Nov 02 22:37:13 UYT 2019
version=0.0.1-SNAPSHOT
groupId=fing.edu.uy
m2e.projectName=Twotter-ejb
m2e.projectLocation=C\:\\Users\\emibo\\Documents\\Desarollo\\twotter\\source\\Twotter\\Twotter-ejb
artifactId=Twotter-ejb
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>Twotter</artifactId>
<groupId>fing.edu.uy</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Twotter-ejb</artifactId>
<packaging>ejb</packaging>
<name>Twotter: EJB Module</name>
<url>http://wildfly.org</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>net.ravendb</groupId>
<artifactId>ravendb</artifactId>
<version>4.1.7</version>
</dependency>
<!-- Declare the APIs we depend on and need for compilation. All of
them are provided by JBoss WildFly -->
<!-- Import the EJB API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as @Email -->
<!-- Hibernate Validator is shipped in JBoss WildFly -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test scope dependencies -->