diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c502dd6f606e02a946780891e9c1626a49cf59d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ + +*.iml +*.idea +*.log +*/.checkstyle +*.log* +*.deployed +*.MF +*.undeployed +*.failed +*/target/* +*/*/target/* +*.ear +#.gitignore diff --git a/central-db/pom.xml b/central-db/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a13032a8f08fecb7463e14fff5cef2321d322a20 --- /dev/null +++ b/central-db/pom.xml @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>central</artifactId> + <groupId>uy.edu.fing.tse</groupId> + <version>1.0.TSE-SNAPSHOT</version> + </parent> + + <artifactId>central-db</artifactId> + <packaging>ejb</packaging> + + <name>central: DB Module</name> + + <dependencies> + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-dto</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.jboss.spec.javax.ejb</groupId> + <artifactId>jboss-ejb-api_3.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.1-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Test scope dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <!-- Arquillian allows you to test enterprise code such as EJBs and + Transactional(JTA) JPA from JUnit/TestNG --> + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + </dependency> + </dependencies> + + <build> + <finalName>${project.artifactId}</finalName> + <plugins> + <plugin> + <artifactId>maven-ejb-plugin</artifactId> + <configuration> + <ejbVersion>3.1</ejbVersion> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>default</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${version.surefire.plugin}</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccess.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccess.java new file mode 100644 index 0000000000000000000000000000000000000000..e8e617a846918f28e34b08faff8a3b9b13ed8b0d --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccess.java @@ -0,0 +1,21 @@ +package uy.edu.fing.tse.practico.db; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.dto.PublicacionDTO; + +import java.util.List; + +public interface DataAccess { + + NoticiaDTO alta(final NoticiaDTO noticia); + + PublicacionDTO alta(final PublicacionDTO publicacion); + + NoticiaDTO find(long idNoticia); + + List<NoticiaDTO> getNoticias(); + + List<PublicacionDTO> getPublicaciones(); + + public NoticiaDTO addPublicacionToNoticia(final PublicacionDTO pub, final long idNoticia); +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessBean.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessBean.java new file mode 100644 index 0000000000000000000000000000000000000000..193b81e6acb08c9ba135d9366bbefe9ba50e7504 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessBean.java @@ -0,0 +1,86 @@ +package uy.edu.fing.tse.practico.db; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.dto.PublicacionDTO; +import uy.edu.fing.tse.practico.db.entity.Noticia; +import uy.edu.fing.tse.practico.db.entity.Publicacion; +import uy.edu.fing.tse.practico.db.mapper.Mapper; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.ejb.LocalBean; +import javax.ejb.Remote; +import javax.ejb.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import java.util.List; +import java.util.stream.Collectors; + +@Singleton +@Local({DataAccessLocal.class}) +@Remote({DataAccessRemote.class}) +@LocalBean +public class DataAccessBean implements DataAccessLocal, DataAccessRemote { + + @PersistenceContext(unitName = "practico") + private EntityManager em; + + @PostConstruct + void init() { + //Despues del constructor hace esto + } + + @Override + public NoticiaDTO alta(NoticiaDTO noticia) { + final Noticia newN = em.merge(Mapper.mapper(noticia)); + em.flush(); + return Mapper.mapper(newN); + } + + @Override + public PublicacionDTO alta(PublicacionDTO publicacion) { + final Publicacion newP = em.merge(Mapper.mapper(publicacion)); + em.flush(); + return Mapper.mapper(newP); + } + + @Override + public NoticiaDTO find(long idNoticia) { + final TypedQuery<Noticia> query = em.createNamedQuery("Noticia.findById", Noticia.class); + query.setParameter("id", idNoticia); + final Noticia result = query.getSingleResult(); + return Mapper.mapper(result); + } + + @Override + public List<NoticiaDTO> getNoticias() { + final TypedQuery<Noticia> query = em.createNamedQuery("Noticia.findAll", Noticia.class); + return query.getResultList().stream().map(Mapper::mapper).collect(Collectors.toList()); + } + + @Override + public List<PublicacionDTO> getPublicaciones() { + final TypedQuery<Publicacion> query = em.createNamedQuery("Publicacion.findAll", Publicacion.class); + return query.getResultList().stream().map(Mapper::mapper).collect(Collectors.toList()); + } + + @Override + public NoticiaDTO addPublicacionToNoticia(final PublicacionDTO pub, final long idNoticia) { + Noticia noticiaManaged = em.find(Noticia.class, idNoticia); + + if (noticiaManaged == null) { + throw new RuntimeException("No existe Noticia"); + } + + Publicacion publicacion = Mapper.mapper(pub); + publicacion = em.merge(publicacion); + em.flush(); + + noticiaManaged.addPublicacion(publicacion); + noticiaManaged = em.merge(noticiaManaged); + em.flush(); + + return Mapper.mapper(noticiaManaged); + } +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessLocal.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..8af9685aabd4393aca233fef779b2e8ff0acb549 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessLocal.java @@ -0,0 +1,8 @@ +package uy.edu.fing.tse.practico.db; + +import javax.ejb.Local; + +@Local +public interface DataAccessLocal extends DataAccess { + +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessRemote.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..ede5aaab97ca5641c2417f80d7e6c7e981c00eb2 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/DataAccessRemote.java @@ -0,0 +1,8 @@ +package uy.edu.fing.tse.practico.db; + +import javax.ejb.Remote; + +@Remote +public interface DataAccessRemote extends DataAccess { + +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Noticia.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Noticia.java new file mode 100644 index 0000000000000000000000000000000000000000..3720d68e222d256bdd45dffe1a4dcdabac1ed8b6 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Noticia.java @@ -0,0 +1,66 @@ +package uy.edu.fing.tse.practico.db.entity; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +@NamedQueries({ + @NamedQuery(name = "Noticia.findAll", query = "select n from Noticia n"), + @NamedQuery(name = "Noticia.findById", query = "select n from Noticia n where n.id = :id") +}) +public class Noticia { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String titulo; + + private String descripcion; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "noticia", orphanRemoval = true) + private List<Publicacion> publicaciones = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitulo() { + return titulo; + } + + public void setTitulo(String titulo) { + this.titulo = titulo; + } + + public String getDescripcion() { + return descripcion; + } + + public void setDescripcion(String descripcion) { + this.descripcion = descripcion; + } + + public List<Publicacion> getPublicaciones() { + return publicaciones; + } + + public void addPublicacion(Publicacion p) { + p.setNoticia(this); + this.publicaciones.add(p); + } + + public void setPublicaciones(List<Publicacion> publicaciones) { + publicaciones.forEach(p -> { + if (p.getNoticia() == null) { + p.setNoticia(this); + } + }); + this.publicaciones = publicaciones; + } +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Publicacion.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Publicacion.java new file mode 100644 index 0000000000000000000000000000000000000000..09a6e1e587e3184ccaae93b15f749cb6ea9b76a8 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/entity/Publicacion.java @@ -0,0 +1,56 @@ +package uy.edu.fing.tse.practico.db.entity; + +import javax.persistence.*; + +@Entity +@NamedQueries({ + @NamedQuery(name = "Publicacion.findAll", query = "select p from Publicacion p"), + @NamedQuery(name = "Publicacion.findByNoticiaId", query = "select p from Publicacion p where p.noticia.id = :idN"), + @NamedQuery(name = "Publicacion.findById", query = "select p from Publicacion p where p.id = :id")} +) +public class Publicacion { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + //TODO: potencial ENUM + private String tipo; + + private String url; + + @ManyToOne + private Noticia noticia; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTipo() { + return tipo; + } + + public void setTipo(String tipo) { + this.tipo = tipo; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Noticia getNoticia() { + return noticia; + } + + public void setNoticia(Noticia noticia) { + this.noticia = noticia; + } +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/mapper/Mapper.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/mapper/Mapper.java new file mode 100644 index 0000000000000000000000000000000000000000..72e68014fcfce3ed2ef836403891aa069871b483 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/mapper/Mapper.java @@ -0,0 +1,53 @@ +package uy.edu.fing.tse.practico.db.mapper; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.dto.PublicacionDTO; +import uy.edu.fing.tse.practico.db.entity.Noticia; +import uy.edu.fing.tse.practico.db.entity.Publicacion; + +import java.util.stream.Collectors; + +public final class Mapper { + private Mapper() { + } + + public static Publicacion mapper(final PublicacionDTO p) { + Publicacion ret = new Publicacion(); + ret.setId(p.getId()); + ret.setTipo(p.getTipo()); + ret.setUrl(p.getUrl()); + return ret; + } + + public static PublicacionDTO mapper(final Publicacion p) { + return new PublicacionDTO(p.getId(), p.getTipo(), p.getUrl()); + } + + public static Noticia mapper(final NoticiaDTO n) { + Noticia ret = new Noticia(); + ret.setTitulo(n.getTitulo()); + ret.setDescripcion(n.getDescripcion()); + n.getPublicaciones().stream().map(Mapper::mapper).forEach(ret::addPublicacion); + return ret; + } + + public static NoticiaDTO mapper(final Noticia n) { + final NoticiaDTO dao = new NoticiaDTO(n.getId(), n.getTitulo(), n.getDescripcion()); + dao.setPublicaciones(n.getPublicaciones() + .stream().map(Mapper::mapper) + .collect(Collectors.toList())); + return dao; + } + + public static void update(final PublicacionDTO p, Publicacion dbP) { + dbP.setTipo(p.getTipo()); + dbP.setUrl(p.getUrl()); + } + + public static void update(final NoticiaDTO n, Noticia dbN) { + dbN.setTitulo(n.getTitulo()); + dbN.setDescripcion(n.getDescripcion()); + //FIXME puede dar inconsistencia + n.getPublicaciones().stream().map(Mapper::mapper).forEach(dbN::addPublicacion); + } +} diff --git a/central-db/src/main/java/uy/edu/fing/tse/practico/db/startup/Config.java b/central-db/src/main/java/uy/edu/fing/tse/practico/db/startup/Config.java new file mode 100644 index 0000000000000000000000000000000000000000..bb260a0fa4647eb23ef0b4753a26b4103940e407 --- /dev/null +++ b/central-db/src/main/java/uy/edu/fing/tse/practico/db/startup/Config.java @@ -0,0 +1,31 @@ +package uy.edu.fing.tse.practico.db.startup; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.practico.db.DataAccessBean; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.EJB; +import javax.ejb.Singleton; +import javax.ejb.Startup; + +@Singleton +@Startup +public class Config { + + @EJB + private DataAccessBean dataAccess; + + @PostConstruct + public void start() { + dataAccess.alta(new NoticiaDTO(null, "Primera Noticia", "Esta descripcion es de la noticia")); + dataAccess.alta(new NoticiaDTO(null, "Segunda Noticia", "Se esta escribiendo aun")); + dataAccess.alta(new NoticiaDTO(null, "Extra Extra Noticia", "El coyote se comio al correcaminos, al parecer cambio de proveedor de productos")); + } + + @PreDestroy + public void stop() { + } + + +} diff --git a/central-db/src/main/resources/META-INF/beans.xml b/central-db/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000000000000000000000000000000000..76426bcac566205e6c414979c639bf1cd7f29d2d --- /dev/null +++ b/central-db/src/main/resources/META-INF/beans.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- 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> diff --git a/central-db/src/main/resources/META-INF/persistence.xml b/central-db/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..cc9680c277f6fe2f84f3f1e06026f52f36d2f099 --- /dev/null +++ b/central-db/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<persistence version="2.1" + xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://xmlns.jcp.org/xml/ns/persistence + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="practico"> + <!--OpenShift--> + <!--<jta-data-source>java:jboss/datasources/practicoDS</jta-data-source>--> + <!--Local--> + <jta-data-source>java:jboss/datasources/herokuDS</jta-data-source> + <properties> + <!-- Properties for Hibernate --> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="hibernate.show_sql" value="false"/> + </properties> + </persistence-unit> +</persistence> diff --git a/central-db/src/test/java/.keep b/central-db/src/test/java/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/central-db/src/test/resources/META-INF/test-persistence.xml b/central-db/src/test/resources/META-INF/test-persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..269e67bf4d1f110eb78f4530b31aefd187ee17ad --- /dev/null +++ b/central-db/src/test/resources/META-INF/test-persistence.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" + xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://xmlns.jcp.org/xml/ns/persistence + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="primary"> + <!-- We use a different datasource for tests, so as to not overwrite + production data. This is an unmanaged data source, backed by H2, an in memory + database. Production applications should use a managed datasource. --> + <!-- The datasource is deployed as WEB-INF/test-ds.xml, + you can find it in the source at src/test/resources/test-ds.xml --> + <jta-data-source>java:jboss/datasources/practicoTestDS</jta-data-source> + <properties> + <!-- Properties for Hibernate --> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="hibernate.show_sql" value="false"/> + </properties> + </persistence-unit> +</persistence> diff --git a/central-db/src/test/resources/arquillian.xml b/central-db/src/test/resources/arquillian.xml new file mode 100644 index 0000000000000000000000000000000000000000..312ee7a5436d2948b7142c8aeecb640fe74c58ec --- /dev/null +++ b/central-db/src/test/resources/arquillian.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<arquillian xmlns="http://jboss.org/schema/arquillian" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://jboss.org/schema/arquillian + http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + + <!-- Uncomment to have test archives exported to the file system for inspection --> + <!-- <engine> --> + <!-- <property name="deploymentExportPath">target/</property> --> + <!-- </engine> --> + + <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature --> + <defaultProtocol type="Servlet 3.0"/> + + <!-- Example configuration for a remote WildFly instance --> + <container qualifier="jboss" default="true"> + <!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. --> + <!--<configuration> --> + <!--<property name="jbossHome">/path/to/wildfly</property> --> + <!--</configuration> --> + </container> + +</arquillian> diff --git a/central-db/src/test/resources/test-ds.xml b/central-db/src/test/resources/test-ds.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e633a31123e9f9d30550cda6368f73769b93ef1 --- /dev/null +++ b/central-db/src/test/resources/test-ds.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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/test-persistence.xml --> + <datasource jndi-name="java:jboss/datasources/practicoTestDS" + pool-name="practico-test" enabled="true" + use-java-context="true"> + <connection-url>jdbc:h2:mem:practico-test;DB_CLOSE_DELAY=-1</connection-url> + <driver>h2</driver> + <security> + <user-name>sa</user-name> + <password>sa</password> + </security> + </datasource> +</datasources> + diff --git a/central-dto/pom.xml b/central-dto/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..f24ca7917ea56581575eeec3397d5d7cdaf67666 --- /dev/null +++ b/central-dto/pom.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>central</artifactId> + <groupId>uy.edu.fing.tse</groupId> + <version>1.0.TSE-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>central-dto</artifactId> + + <name>central-dto</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> + <plugins> + <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <version>3.1.0</version> + </plugin> + <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.1</version> + </plugin> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <version>2.5.2</version> + </plugin> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.2</version> + </plugin> + <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <version>3.7.1</version> + </plugin> + <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>3.0.0</version> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/central-dto/src/main/java/uy/edu/fing/tse/dto/NoticiaDTO.java b/central-dto/src/main/java/uy/edu/fing/tse/dto/NoticiaDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..8629078fc5f6a355ffb51e2eea283e76ba6827ba --- /dev/null +++ b/central-dto/src/main/java/uy/edu/fing/tse/dto/NoticiaDTO.java @@ -0,0 +1,58 @@ +package uy.edu.fing.tse.dto; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public final class NoticiaDTO implements Serializable { + + + private static final long serialVersionUID = 4516690446335921631L; + + private final Long id; + + private final String titulo; + + private final String descripcion; + + private final List<PublicacionDTO> publicaciones = new ArrayList<>(); + + public NoticiaDTO(Long id, String titulo, String descripcion) { + this.id = id; + this.titulo = titulo; + this.descripcion = descripcion; + } + + public Long getId() { + return id; + } + + + public String getTitulo() { + return titulo; + } + + + public String getDescripcion() { + return descripcion; + } + + public List<PublicacionDTO> getPublicaciones() { + return publicaciones; + } + + public void setPublicaciones(List<PublicacionDTO> publicaciones) { + this.publicaciones.clear(); + this.publicaciones.addAll(publicaciones); + } + + @Override + public String toString() { + return "NoticiaDTO{" + + "id=" + id + + ", titulo='" + titulo + '\'' + + ", descripcion='" + descripcion + '\'' + + ", publicaciones=" + publicaciones + + '}'; + } +} diff --git a/central-dto/src/main/java/uy/edu/fing/tse/dto/PublicacionDTO.java b/central-dto/src/main/java/uy/edu/fing/tse/dto/PublicacionDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..e9804f0633ef0cf89f52c47136e0161aae0d3220 --- /dev/null +++ b/central-dto/src/main/java/uy/edu/fing/tse/dto/PublicacionDTO.java @@ -0,0 +1,43 @@ +package uy.edu.fing.tse.dto; + +import java.io.Serializable; + +public final class PublicacionDTO implements Serializable { + + private static final long serialVersionUID = -6800083961746968433L; + private final Long id; + + //TODO: potencial ENUM + private final String tipo; + + private final String url; + + public PublicacionDTO(Long id, String tipo, String url) { + this.id = id; + this.tipo = tipo; + this.url = url; + } + + public Long getId() { + return id; + } + + + public String getTipo() { + return tipo; + } + + + public String getUrl() { + return url; + } + + @Override + public String toString() { + return "PublicacionDTO{" + + "id=" + id + + ", tipo='" + tipo + '\'' + + ", url='" + url + '\'' + + '}'; + } +} diff --git a/central-ear/pom.xml b/central-ear/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b650d6c95814029de86c45ab039310050449467f --- /dev/null +++ b/central-ear/pom.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>central</artifactId> + <groupId>uy.edu.fing.tse</groupId> + <version>1.0.TSE-SNAPSHOT</version> + </parent> + + <artifactId>central-ear</artifactId> + <packaging>ear</packaging> + + <name>central: EAR Module</name> + + <dependencies> + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-dto</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-db</artifactId> + <type>ejb</type> + </dependency> + + <dependency> + <artifactId>central-ejb</artifactId> + <groupId>uy.edu.fing.tse</groupId> + <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> + <version>8</version> + <applicationName>${project.artifactId}</applicationName> + <generateApplicationXml>true</generateApplicationXml> + <defaultLibBundleDir>lib</defaultLibBundleDir> + <modules> + <ejbModule> + <groupId>${project.groupId}</groupId> + <artifactId>central-ejb</artifactId> + <bundleFileName>central-ejb.jar</bundleFileName> + </ejbModule> + </modules> + </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> diff --git a/central-ear/src/main/application/META-INF/altaNoticia-jms.xml b/central-ear/src/main/application/META-INF/altaNoticia-jms.xml new file mode 100644 index 0000000000000000000000000000000000000000..85d0173faa5f206d98769d6b467b8a7c0a6c367e --- /dev/null +++ b/central-ear/src/main/application/META-INF/altaNoticia-jms.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<messaging-deployment xmlns="urn:jboss:messaging-activemq-deployment:1.0"> + <server name="default"> + <jms-destinations> + <!--<jms-topic name="topic/response">--> + <!--<entry name="java:/jms/topic/response"/>--> + <!--<entry name="java:jboss/exported/jms/topic/response"/>--> + <!--</jms-topic>--> + <jms-queue name="queue/queue_alta_noticia"> + <entry name="java:/jms/queue/queue_alta_noticia"/> + <entry name="java:jboss/exported/jms/queue/queue_alta_noticia"/> + </jms-queue> + </jms-destinations> + </server> +</messaging-deployment> \ No newline at end of file diff --git a/central-ear/src/main/application/META-INF/jboss-deployment-descriptor.xml b/central-ear/src/main/application/META-INF/jboss-deployment-descriptor.xml new file mode 100644 index 0000000000000000000000000000000000000000..5a0fce3aed14a0c003819a674b6c6ca00bf27c44 --- /dev/null +++ b/central-ear/src/main/application/META-INF/jboss-deployment-descriptor.xml @@ -0,0 +1,11 @@ +<jboss> + <enterprise-beans> + <service> + <ejb-class>uy.edu.fing.tse.practico.business.BusinessBean</ejb-class> + <local>uy.edu.fing.tse.practico.business.BusinessLocal</local> + <remote>uy.edu.fing.tse.practico.business.BusinessRemote</remote> + <jndi-name>practico/remote</jndi-name> + <local-jndi-name>practico/local</local-jndi-name> + </service> + </enterprise-beans> +</jboss> \ No newline at end of file diff --git a/central-ear/src/main/application/META-INF/practico-ds.xml b/central-ear/src/main/application/META-INF/practico-ds.xml new file mode 100644 index 0000000000000000000000000000000000000000..4dc62abe2cc89b5decb03d89bb3eb48ca66e7c18 --- /dev/null +++ b/central-ear/src/main/application/META-INF/practico-ds.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<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/practicoDS" pool-name="practico" + enabled="true" use-java-context="true"> + <connection-url>jdbc:h2:mem:practico;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> + <!--https://data.heroku.com/datastores/30b15fdc-4667-493f-b244-cdfea47f071f#administration--> + <datasource jndi-name="java:jboss/datasources/herokuDS" pool-name="heroku" enabled="true" use-java-context="true"> + <connection-url>jdbc:postgresql://ec2-23-23-92-204.compute-1.amazonaws.com:5432/dd1clqkconunk4</connection-url> + <driver>postgresql</driver> + <security> + <user-name>hqxefooowavbtm</user-name> + <password>fd34e142d8d9ae681fb227b74745c498c87f22a65da9681c9653b01af1375557</password> + </security> + </datasource> +</datasources> + diff --git a/central-ejb/pom.xml b/central-ejb/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..9063b50dd547ad82ad75e591d3ef7eade83954ae --- /dev/null +++ b/central-ejb/pom.xml @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>central</artifactId> + <groupId>uy.edu.fing.tse</groupId> + <version>1.0.TSE-SNAPSHOT</version> + </parent> + + <artifactId>central-ejb</artifactId> + <packaging>ejb</packaging> + + <name>central: 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>uy.edu.fing.tse</groupId> + <artifactId>central-dto</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-db</artifactId> + <type>ejb</type> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.jboss.spec.javax.ejb</groupId> + <artifactId>jboss-ejb-api_3.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + </dependency> + + <!-- Test scope dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <!-- Optional, but highly recommended --> + <!-- Arquillian allows you to test enterprise code such as EJBs and + Transactional(JTA) JPA from JUnit/TestNG --> + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.wildfly</groupId> + <artifactId>wildfly-jms-client-bom</artifactId> + <version>15.0.0.Final</version> + <type>pom</type> + </dependency> + + </dependencies> + + <build> + <finalName>${project.artifactId}</finalName> + <plugins> + <plugin> + <artifactId>maven-ejb-plugin</artifactId> + <configuration> + <jarName>${project.artifactId}</jarName> + <ejbVersion>3.1</ejbVersion> + <!-- this is false by default --> + <generateClient>true</generateClient> + <clientIncludes> + <clientInclude>uy/edu/fing/tse/central/business/BusinessRemote*</clientInclude> + <clientInclude>uy/edu/fing/tse/dto/*</clientInclude> + </clientIncludes> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>default</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${version.surefire.plugin}</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/central-ejb/src/main/java/.keep b/central-ejb/src/main/java/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/Business.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/Business.java new file mode 100644 index 0000000000000000000000000000000000000000..8481131195d564c9ca631dc7f32103b937ab624f --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/Business.java @@ -0,0 +1,28 @@ +package uy.edu.fing.tse.practico.business; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.dto.PublicacionDTO; + +import java.util.List; + +/** + * La Capa de Negocio deberá proveer funcionalidades para Agregar una Publicación a + * una Noticia, Obtener Noticias, Obtener Publicaciones y Obtener las Publicaciones de + * una Noticia. + */ +public interface Business { + + void add(NoticiaDTO noticia); + + void add(PublicacionDTO publicacion, NoticiaDTO noticia); + + NoticiaDTO findNoticia(long idNoticia); + + List<NoticiaDTO> getNoticias(); + + List<PublicacionDTO> getPublicaciones(); + + List<PublicacionDTO> getPublicaciones(final long idNoticia); + + NoticiaDTO addPublicacionANoticia(final PublicacionDTO pub, final long idNoticia); +} diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessBean.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessBean.java new file mode 100644 index 0000000000000000000000000000000000000000..fde79c48f597acd31ad99023d51466216c2bc5ab --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessBean.java @@ -0,0 +1,73 @@ +package uy.edu.fing.tse.practico.business; + + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.dto.PublicacionDTO; +import uy.edu.fing.tse.practico.db.DataAccessBean; + +import javax.annotation.PostConstruct; +import javax.ejb.*; +import java.util.List; + +/** + * Se debe controlar que una noticia no tenga más de diez publicaciones. Esta + * capa deberá implementarse con Stateless Session Beans que provean interfaces + * remotas y locales + */ +@Stateless +@Local({BusinessLocal.class}) +@Remote({BusinessRemote.class}) +@LocalBean +public class BusinessBean implements BusinessLocal, BusinessRemote { + + @EJB + private DataAccessBean dataAccess; + + @PostConstruct + void init() { + //Despues Hace esto + } + + @Override + public void add(NoticiaDTO noticia) { + dataAccess.alta(noticia); + } + + @Override + public void add(PublicacionDTO publicacion, NoticiaDTO noticia) { + noticia.getPublicaciones().add(publicacion); + dataAccess.alta(noticia); + } + + @Override + public NoticiaDTO findNoticia(final long idNoticia) { + return dataAccess.find(idNoticia); + } + + @Override + public List<NoticiaDTO> getNoticias() { + return dataAccess.getNoticias(); + } + + @Override + public List<PublicacionDTO> getPublicaciones() { + return dataAccess.getPublicaciones(); + } + + @Override + public List<PublicacionDTO> getPublicaciones(final long idNoticia) { + return dataAccess.find(idNoticia).getPublicaciones(); + } + + @Override + public NoticiaDTO addPublicacionANoticia(final PublicacionDTO pub, final long idNoticia) { + NoticiaDTO noticiaDTO = dataAccess.find(idNoticia); + + if (noticiaDTO.getPublicaciones().size() >= 10) { + throw new RuntimeException("La noticia tiene demasiadas publicaciones ya."); + } + + noticiaDTO = dataAccess.addPublicacionToNoticia(pub, idNoticia); + return noticiaDTO; + } +} diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessLocal.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessLocal.java new file mode 100644 index 0000000000000000000000000000000000000000..af4e40371cb8c068dd02f052acc1ff53a5061922 --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessLocal.java @@ -0,0 +1,7 @@ +package uy.edu.fing.tse.practico.business; + +import javax.ejb.Local; + +@Local +public interface BusinessLocal extends Business { +} diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessRemote.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessRemote.java new file mode 100644 index 0000000000000000000000000000000000000000..735cb9db435f154d90c8c88ddbc260d80a6443c2 --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/BusinessRemote.java @@ -0,0 +1,7 @@ +package uy.edu.fing.tse.practico.business; + +import javax.ejb.Remote; + +@Remote +public interface BusinessRemote extends Business { +} diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/AltaNoticiaMDB.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/AltaNoticiaMDB.java new file mode 100644 index 0000000000000000000000000000000000000000..b16d696cb29c7dd476151d23630914e72cce497e --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/AltaNoticiaMDB.java @@ -0,0 +1,38 @@ +package uy.edu.fing.tse.practico.business.jms; + +import uy.edu.fing.tse.dto.NoticiaDTO; +import uy.edu.fing.tse.practico.business.BusinessBean; + +import javax.ejb.ActivationConfigProperty; +import javax.ejb.EJB; +import javax.ejb.MessageDriven; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; + +//FIXME comentarlo para el despliegue en OpenShift +@MessageDriven(name = "AltaNoticia", activationConfig = { + @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/queue_alta_noticia"), + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), + @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "50") +}) +public class AltaNoticiaMDB implements MessageListener { + + @EJB + private BusinessBean negocio; + + @Override + public void onMessage(Message message) { + try { + final String body = message.getBody(String.class); + final String[] split = body.trim().split("\\|"); + + final NoticiaDTO noticia = new NoticiaDTO(null, split[0], split[1]); + negocio.add(noticia); + + } catch (JMSException e) { + e.printStackTrace(); + } + } +} diff --git a/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/JMSProducer.java b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/JMSProducer.java new file mode 100644 index 0000000000000000000000000000000000000000..b364f6df82121ee97953bd4487ab855550627846 --- /dev/null +++ b/central-ejb/src/main/java/uy/edu/fing/tse/practico/business/jms/JMSProducer.java @@ -0,0 +1,40 @@ +package uy.edu.fing.tse.practico.business.jms; + +import uy.edu.fing.tse.dto.NoticiaDTO; + +import javax.annotation.Resource; +import javax.ejb.Stateless; +import javax.jms.*; + +@Stateless +public class JMSProducer { + + @Resource(lookup = "java:/ConnectionFactory") + private ConnectionFactory connectionFactory; + + @Resource(lookup = "java:/jms/queue/queue_alta_noticia") + private Queue sendQueue; + + public void altaNoticia(final NoticiaDTO noticia) { + try { + sendMsj(noticia.getTitulo() + "|" + noticia.getDescripcion()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void sendMsj(final String messageStr) { + // Create the JMS connection, session, producer, and consumer + try (Connection connection = connectionFactory.createConnection()) { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(sendQueue); + + connection.start(); + + final Message message = session.createTextMessage(messageStr); + producer.send(message); + } catch (JMSException _e) { + //ignore + } + } +} diff --git a/central-ejb/src/main/resources/META-INF/beans.xml b/central-ejb/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef4b32814c5fa06214ffa8feb5f00f18c2c408df --- /dev/null +++ b/central-ejb/src/main/resources/META-INF/beans.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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> diff --git a/central-ejb/src/test/java/.keep b/central-ejb/src/test/java/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/central-ejb/src/test/resources/META-INF/test-persistence.xml b/central-ejb/src/test/resources/META-INF/test-persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..269e67bf4d1f110eb78f4530b31aefd187ee17ad --- /dev/null +++ b/central-ejb/src/test/resources/META-INF/test-persistence.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" + xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://xmlns.jcp.org/xml/ns/persistence + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="primary"> + <!-- We use a different datasource for tests, so as to not overwrite + production data. This is an unmanaged data source, backed by H2, an in memory + database. Production applications should use a managed datasource. --> + <!-- The datasource is deployed as WEB-INF/test-ds.xml, + you can find it in the source at src/test/resources/test-ds.xml --> + <jta-data-source>java:jboss/datasources/practicoTestDS</jta-data-source> + <properties> + <!-- Properties for Hibernate --> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="hibernate.show_sql" value="false"/> + </properties> + </persistence-unit> +</persistence> diff --git a/central-ejb/src/test/resources/arquillian.xml b/central-ejb/src/test/resources/arquillian.xml new file mode 100644 index 0000000000000000000000000000000000000000..d431b57b10ebcef7cdcd9b4ee94210b574c136b7 --- /dev/null +++ b/central-ejb/src/test/resources/arquillian.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<arquillian xmlns="http://jboss.org/schema/arquillian" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://jboss.org/schema/arquillian + http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + + <!-- Uncomment to have test archives exported to the file system for inspection --> + <!-- <engine> --> + <!-- <property name="deploymentExportPath">target/</property> --> + <!-- </engine> --> + + <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature --> + <defaultProtocol type="Servlet 3.0"/> + + <!-- Example configuration for a remote WildFly instance --> + <container qualifier="jboss" default="true"> + <!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. --> + <!--<configuration> --> + <!--<property name="jbossHome">/path/to/wildfly</property> --> + <!--</configuration> --> + </container> + +</arquillian> diff --git a/central-ejb/src/test/resources/test-ds.xml b/central-ejb/src/test/resources/test-ds.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e633a31123e9f9d30550cda6368f73769b93ef1 --- /dev/null +++ b/central-ejb/src/test/resources/test-ds.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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/test-persistence.xml --> + <datasource jndi-name="java:jboss/datasources/practicoTestDS" + pool-name="practico-test" enabled="true" + use-java-context="true"> + <connection-url>jdbc:h2:mem:practico-test;DB_CLOSE_DELAY=-1</connection-url> + <driver>h2</driver> + <security> + <user-name>sa</user-name> + <password>sa</password> + </security> + </datasource> +</datasources> + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..06594d0c7ad0be1dfaa4d6b18f403fa1931961f1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,295 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + + <name>central</name> + <modelVersion>4.0.0</modelVersion> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central</artifactId> + <version>1.0.TSE-SNAPSHOT</version> + <packaging>pom</packaging> + + + <modules> + <module>central-dto</module> + <module>central-db</module> + <module>central-ejb</module> + <module>central-ear</module> + </modules> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <version.wildfly.maven.plugin>2.0.1.Final</version.wildfly.maven.plugin> + <version.jboss.bom>8.2.1.Final</version.jboss.bom> + <version.wildfly>15.0.0.Final</version.wildfly> + + <!-- other plugin versions --> + <version.compiler.plugin>3.1</version.compiler.plugin> + <version.ear.plugin>3.0.1</version.ear.plugin> + <version.ejb.plugin>3.0.1</version.ejb.plugin> + <version.surefire.plugin>2.22.1</version.surefire.plugin> + <version.war.plugin>3.2.2</version.war.plugin> + + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-dto</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-ejb</artifactId> + <version>${project.version}</version> + <type>ejb</type> + </dependency> + + <dependency> + <groupId>uy.edu.fing.tse</groupId> + <artifactId>central-db</artifactId> + <version>${project.version}</version> + <type>ejb</type> + </dependency> + + <dependency> + <groupId>org.wildfly.bom</groupId> + <artifactId>wildfly-javaee8-with-tools</artifactId> + <version>${version.wildfly}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + + <dependency> + <groupId>org.jboss.spec</groupId> + <artifactId>jboss-javaee-8.0</artifactId> + <version>1.0.3.Final</version> + <type>pom</type> + <scope>import</scope> + </dependency> + + <!-- Hibernate ORM sub-modules --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>${version.org.hibernate}</version> + <!-- this already part of JDK6 --> + <exclusions> + <exclusion> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>${version.org.hibernate}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-envers</artifactId> + <version>${version.org.hibernate}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-infinispan</artifactId> + <version>${version.org.hibernate}</version> + <!-- we use org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec from hibernate-core here --> + <exclusions> + <exclusion> + <groupId>org.jboss.javaee</groupId> + <artifactId>jboss-transaction-api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-c3p0</artifactId> + <version>${version.org.hibernate}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-ehcache</artifactId> + <version>${version.org.hibernate}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-proxool</artifactId> + <version>${version.org.hibernate}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <version>6.0.16.Final</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search</artifactId> + <version>${version.org.hibernate.search}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search-analyzers</artifactId> + <version>${version.org.hibernate.search}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search-engine</artifactId> + <version>${version.org.hibernate.search}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search-infinispan</artifactId> + <version>${version.org.hibernate.search}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search-orm</artifactId> + <version>${version.org.hibernate.search}</version> + </dependency> + + <!-- Tools --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator-annotation-processor</artifactId> + <version>${version.org.hibernate.validator}</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + <version>${version.org.hibernate-jpamodelgen}</version> + </dependency> + + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.1-api</artifactId> + <version>1.0.2.Final</version> + </dependency> + + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>jaxrs-api</artifactId> + <version>3.0.12.Final</version> + </dependency> + + <dependency> + <groupId>org.jboss.spec.javax.faces</groupId> + <artifactId>jboss-jsf-api_2.2_spec</artifactId> + <version>2.2.14</version> + </dependency> + + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>1.2</version> + </dependency> + </dependencies> + </dependencyManagement> + + <build> + <pluginManagement> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clean-plugin</artifactId> + <version>2.2</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.4</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <version>2.2</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>2.2</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <version>2.2</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <release>11</release> + </configuration> + </plugin> + + <plugin> + <groupId>org.wildfly.plugins</groupId> + <artifactId>wildfly-maven-plugin</artifactId> + <version>${version.wildfly.maven.plugin}</version> + <inherited>true</inherited> + <configuration> + <skip>true</skip> + </configuration> + <executions> + <execution> + <phase>install</phase> + <goals> + <goal>deploy</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-ejb-plugin</artifactId> + <version>${version.ejb.plugin}</version> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>versions-maven-plugin</artifactId> + <version>2.5</version> + <configuration> + <generateBackupPoms>false</generateBackupPoms> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${version.surefire.plugin}</version> + <configuration> + <argLine> + --illegal-access=permit + </argLine> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project>