Skip to content

Commit 7070670

Browse files
committed
commit core application
1 parent 0599e88 commit 7070670

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1863
-0
lines changed

EVAM04_EMISIONVOTO_CORE/pom.xml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<artifactId>EVAM04_EMISIONVOTO</artifactId>
7+
<groupId>edu.cibertec.votoelectronico.application</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<groupId>edu.cibertec.votoelectronico.core</groupId>
13+
<artifactId>EVAM04_EMISIONVOTO_CORE</artifactId>
14+
<name>EVAM04_EMISIONVOTO_CORE</name>
15+
<url>http://www.cibertec.edu.pe</url>
16+
<description>Hiberate OGM and MongoDB</description>
17+
<packaging>jar</packaging>
18+
19+
<properties>
20+
<project.build.finalName>EVAM04_EMISIONVOTO_CORE</project.build.finalName>
21+
<version.exec.plugin>1.6.0</version.exec.plugin>
22+
<spring.version>4.3.7.RELEASE</spring.version>
23+
<hibernate.ogm.version>5.4.1.Final</hibernate.ogm.version>
24+
<version.jboss-transaction-api>1.0.1.Final</version.jboss-transaction-api>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.hibernate.ogm</groupId>
30+
<artifactId>hibernate-ogm-mongodb</artifactId>
31+
<version>${hibernate.ogm.version}</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.jboss.spec.javax.transaction</groupId>
36+
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
37+
<version>${version.jboss-transaction-api}</version>
38+
</dependency>
39+
40+
<!-- Add the Narayana Transactions Manager an implementation would be provided
41+
in a Java EE container, but this works nicely in Java SE as well -->
42+
<dependency>
43+
<groupId>org.jboss.narayana.jta</groupId>
44+
<artifactId>narayana-jta</artifactId>
45+
<version>5.9.2.Final</version>
46+
</dependency>
47+
<!-- <version>5.9.2.Final</version> -->
48+
49+
<!-- JBOSS JTA Standalone to work in Java SE -->
50+
51+
<!-- <dependency> -->
52+
<!-- <groupId>org.jboss.jbossts</groupId> -->
53+
<!-- <artifactId>jbossjta</artifactId> -->
54+
<!-- <version>4.16.4.Final</version> -->
55+
<!-- </dependency> -->
56+
57+
<!-- <dependency> -->
58+
<!-- <groupId>org.jboss</groupId> -->
59+
<!-- <artifactId>jboss-transaction-spi</artifactId> -->
60+
<!-- </dependency> -->
61+
62+
<dependency>
63+
<groupId>org.hibernate.validator</groupId>
64+
<artifactId>hibernate-validator</artifactId>
65+
<version>6.0.2.Final</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.hibernate.validator</groupId>
69+
<artifactId>hibernate-validator-annotation-processor</artifactId>
70+
<version>6.0.2.Final</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.glassfish</groupId>
74+
<artifactId>javax.el</artifactId>
75+
<version>3.0.1-b09</version>
76+
</dependency>
77+
<!-- <dependency> -->
78+
<!-- <groupId>org.glassfish.web</groupId> -->
79+
<!-- <artifactId>javax.el</artifactId> -->
80+
<!-- <version>2.2.6</version> -->
81+
<!-- </dependency> -->
82+
83+
<dependency>
84+
<groupId>org.mindrot</groupId>
85+
<artifactId>jbcrypt</artifactId>
86+
<version>0.3m</version>
87+
</dependency>
88+
89+
</dependencies>
90+
91+
<build>
92+
<plugins>
93+
<plugin>
94+
<artifactId>maven-jar-plugin</artifactId>
95+
<version>${version.jar.plugin}</version>
96+
<configuration>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-compiler-plugin</artifactId>
102+
<version>${version.compiler.plugin}</version>
103+
<configuration>
104+
<source>${maven.compiler.source}</source>
105+
<target>${maven.compiler.target}</target>
106+
</configuration>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package edu.cibertec.votoelectronico.application;
2+
3+
import org.hibernate.SessionFactory;
4+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
5+
import org.hibernate.cfg.Environment;
6+
import org.hibernate.ogm.cfg.OgmConfiguration;
7+
import org.hibernate.service.ServiceRegistry;
8+
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
import edu.cibertec.votoelectronico.domain.GrupoPolitico;
13+
import edu.cibertec.votoelectronico.domain.Voto;
14+
15+
/**
16+
* HibernateUtil class (no need of hibernate.cfg.xml)
17+
*
18+
*/
19+
public class HibernateConfig {
20+
21+
private static final Logger LOG = LoggerFactory.getLogger(HibernateConfig.class);
22+
private static final SessionFactory sessionFactory;
23+
private static final ServiceRegistry serviceRegistry;
24+
25+
static {
26+
try {
27+
// create a new instance of OmgConfiguration
28+
OgmConfiguration cfgogm = new OgmConfiguration();
29+
30+
// enable transaction strategy
31+
// enable JTA strategy
32+
cfgogm.setProperty(Environment.TRANSACTION_COORDINATOR_STRATEGY, "jta");
33+
cfgogm.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");
34+
35+
// specify JTA platform
36+
cfgogm.setProperty(Environment.JTA_PLATFORM, "JBossTS");
37+
// cfgogm.setProperty(Environment.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform");
38+
39+
// in order to select the local JBoss JTA implementation it is necessary to
40+
// specify
41+
// cfgogm.setProperty("com.arjuna.ats.jta.jtaTMImplementation",
42+
// "com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple");
43+
// cfgogm.setProperty("com.arjuna.ats.jta.jtaUTImplementation",
44+
// "com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple");
45+
46+
// configure MongoDB connection
47+
cfgogm.setProperty("hibernate.ogm.datastore.provider", "mongodb");
48+
// cfgogm.setProperty("hibernate.ogm.datastore.grid_dialect",
49+
// "org.hibernate.ogm.dialect.mongodb.MongoDBDialect");
50+
cfgogm.setProperty("hibernate.ogm.datastore.create_database", "true");
51+
cfgogm.setProperty("hibernate.ogm.datastore.database", "votoelectronico_db");
52+
cfgogm.setProperty("hibernate.ogm.datastore.username", "votoelectronico_admin");
53+
cfgogm.setProperty("hibernate.ogm.datastore.password", "$votoelectronico_admin123.a");
54+
cfgogm.setProperty("hibernate.ogm.mongodb.authentication_database", "votoelectronico_db");
55+
cfgogm.setProperty("hibernate.ogm.datastore.host", "127.0.0.1");
56+
cfgogm.setProperty("hibernate.ogm.datastore.port", "27017");
57+
58+
// add our annotated class
59+
cfgogm.addAnnotatedClass(GrupoPolitico.class);
60+
cfgogm.addAnnotatedClass(Voto.class);
61+
62+
// create the SessionFactory
63+
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfgogm.getProperties()).build();
64+
sessionFactory = cfgogm.buildSessionFactory(serviceRegistry);
65+
66+
} catch (Exception ex) {
67+
LOG.info("Initial SessionFactory creation failed !", ex);
68+
throw new ExceptionInInitializerError(ex);
69+
}
70+
}
71+
72+
public static SessionFactory getSessionFactory() {
73+
return sessionFactory;
74+
}
75+
76+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package edu.cibertec.votoelectronico.application;
2+
3+
import javax.persistence.EntityManager;
4+
import javax.persistence.EntityManagerFactory;
5+
import javax.persistence.Persistence;
6+
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
11+
12+
@Configuration
13+
@ComponentScan("edu.cibertec.votoelectronico")
14+
@PropertySource("classpath:database.properties")
15+
public class PersistenceConfig {
16+
17+
@Bean
18+
public EntityManagerFactory createEntityManagerFactory() {
19+
return Persistence.createEntityManagerFactory("ogm-mongodb");
20+
}
21+
22+
@Bean
23+
public EntityManager createEntityManager(EntityManagerFactory emf) {
24+
return emf.createEntityManager();
25+
}
26+
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package edu.cibertec.votoelectronico.application.event;
2+
3+
import org.springframework.context.ApplicationEvent;
4+
5+
import edu.cibertec.votoelectronico.domain.Voto;
6+
7+
public class EmitirVotoEvent extends ApplicationEvent implements PayloadEvent<Voto> {
8+
9+
/**
10+
*
11+
*/
12+
private static final long serialVersionUID = 1L;
13+
14+
private Voto payload;
15+
16+
public EmitirVotoEvent(Object source) {
17+
super(source);
18+
}
19+
20+
public EmitirVotoEvent(Object source, Voto payload) {
21+
super(source);
22+
this.payload = payload;
23+
}
24+
25+
@Override
26+
public Voto getPayload() {
27+
return this.payload;
28+
}
29+
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package edu.cibertec.votoelectronico.application.event;
2+
3+
public interface PayloadEvent<T> {
4+
5+
public T getPayload();
6+
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package edu.cibertec.votoelectronico.application.publisher;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.ApplicationEventPublisher;
5+
6+
public abstract class BaseEventPublisher {
7+
8+
@Autowired
9+
protected ApplicationEventPublisher applicationEventPublisher;
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package edu.cibertec.votoelectronico.application.publisher;
2+
3+
import edu.cibertec.votoelectronico.application.event.EmitirVotoEvent;
4+
import edu.cibertec.votoelectronico.domain.Voto;
5+
6+
public interface EmitirVotoEventPublisher extends GenericEventPublisher<Voto, EmitirVotoEvent> {
7+
8+
@Override
9+
default EmitirVotoEvent createEvent(Voto payload) {
10+
return new EmitirVotoEvent(this, payload);
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package edu.cibertec.votoelectronico.application.publisher;
2+
3+
import org.springframework.context.ApplicationEvent;
4+
5+
public interface GenericEventPublisher<P, E extends ApplicationEvent> {
6+
7+
public E createEvent(P payload);
8+
9+
public void publish(P payload);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package edu.cibertec.votoelectronico.application.publisher;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.stereotype.Component;
6+
7+
import edu.cibertec.votoelectronico.domain.Voto;
8+
9+
@Component
10+
public class SimpleEmitirVotoEventPublisher extends BaseEventPublisher implements EmitirVotoEventPublisher {
11+
12+
private final Logger LOG = LoggerFactory.getLogger(SimpleEmitirVotoEventPublisher.class);
13+
14+
@Override
15+
public void publish(Voto payload) {
16+
LOG.info("EmitirVoto Event will be published...");
17+
this.applicationEventPublisher.publishEvent(this.createEvent(payload));
18+
LOG.info("EmitirVoto Event was published...");
19+
}
20+
21+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package edu.cibertec.votoelectronico.domain;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import javax.persistence.CascadeType;
7+
import javax.persistence.Entity;
8+
import javax.persistence.FetchType;
9+
import javax.persistence.GeneratedValue;
10+
import javax.persistence.GenerationType;
11+
import javax.persistence.Id;
12+
import javax.persistence.NamedNativeQueries;
13+
import javax.persistence.NamedNativeQuery;
14+
import javax.persistence.OneToMany;
15+
import javax.persistence.Table;
16+
17+
import org.hibernate.annotations.Type;
18+
19+
@Entity
20+
@Table(name = "grupoPoliticos")
21+
@NamedNativeQueries({
22+
@NamedNativeQuery(name = "QN_GRUPO_POLITICO_DELETE_ALL", query = "db.grupoPoliticos.drop()", resultClass = GrupoPolitico.class) })
23+
public class GrupoPolitico {
24+
25+
@Id
26+
@GeneratedValue(strategy = GenerationType.IDENTITY)
27+
@Type(type = "objectid")
28+
private String grupoPoliticoId;
29+
30+
private String nombre;
31+
private String descripcion;
32+
33+
@OneToMany(mappedBy = "grupoPolitico", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
34+
private Set<Voto> votos = new HashSet<>();
35+
36+
public GrupoPolitico() {
37+
super();
38+
}
39+
40+
public String getGrupoPoliticoId() {
41+
return grupoPoliticoId;
42+
}
43+
44+
public void setGrupoPoliticoId(String grupoPoliticoId) {
45+
this.grupoPoliticoId = grupoPoliticoId;
46+
}
47+
48+
public String getNombre() {
49+
return nombre;
50+
}
51+
52+
public void setNombre(String nombre) {
53+
this.nombre = nombre;
54+
}
55+
56+
public String getDescripcion() {
57+
return descripcion;
58+
}
59+
60+
public void setDescripcion(String descripcion) {
61+
this.descripcion = descripcion;
62+
}
63+
64+
public Set<Voto> getVotos() {
65+
return votos;
66+
}
67+
68+
public void setVotos(Set<Voto> votos) {
69+
this.votos = votos;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return "GrupoPolitico [grupoPoliticoId=" + grupoPoliticoId + ", nombre=" + nombre + ", descripcion="
75+
+ descripcion + ", votos=" + votos + "]";
76+
}
77+
78+
}

0 commit comments

Comments
 (0)