Skip to content

Commit c2f5bf3

Browse files
committed
Primeiro commit
0 parents  commit c2f5bf3

39 files changed

Lines changed: 1480 additions & 0 deletions

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.class
2+
.DS_Store
3+
Servers/*
4+
.metadata
5+
.settings
6+
.classpath
7+
.project
8+
target/

pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.algaworks</groupId>
4+
<artifactId>Financeiro</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
</properties>
11+
12+
<dependencies>
13+
<!-- OmniFaces (utilitarios para JSF) -->
14+
<dependency>
15+
<groupId>org.omnifaces</groupId>
16+
<artifactId>omnifaces</artifactId>
17+
<version>1.6</version>
18+
<scope>compile</scope>
19+
</dependency>
20+
21+
<!-- PrimeFaces (biblioteca de componentes) -->
22+
<dependency>
23+
<groupId>org.primefaces</groupId>
24+
<artifactId>primefaces</artifactId>
25+
<version>4.0</version>
26+
<scope>compile</scope>
27+
</dependency>
28+
29+
<!-- Weld (implementação do CDI) -->
30+
<dependency>
31+
<groupId>org.jboss.weld.servlet</groupId>
32+
<artifactId>weld-servlet</artifactId>
33+
<version>2.0.4.Final</version>
34+
<scope>compile</scope>
35+
</dependency>
36+
37+
<!-- Implementacao do Bean Validation -->
38+
<dependency>
39+
<groupId>org.hibernate</groupId>
40+
<artifactId>hibernate-validator</artifactId>
41+
<version>5.0.1.Final</version>
42+
<scope>compile</scope>
43+
</dependency>
44+
45+
<!-- Núcleo do Hibernate -->
46+
<dependency>
47+
<groupId>org.hibernate</groupId>
48+
<artifactId>hibernate-core</artifactId>
49+
<version>4.2.6.Final</version>
50+
<scope>compile</scope>
51+
</dependency>
52+
53+
<!-- Implementação de EntityManager da JPA -->
54+
<dependency>
55+
<groupId>org.hibernate</groupId>
56+
<artifactId>hibernate-entitymanager</artifactId>
57+
<version>4.2.6.Final</version>
58+
<scope>compile</scope>
59+
</dependency>
60+
61+
<!-- Driver JDBC do MySQL -->
62+
<dependency>
63+
<groupId>mysql</groupId>
64+
<artifactId>mysql-connector-java</artifactId>
65+
<version>5.1.26</version>
66+
<scope>compile</scope>
67+
</dependency>
68+
69+
<!-- Mojarra (implementacao do JSF) -->
70+
<dependency>
71+
<groupId>org.glassfish</groupId>
72+
<artifactId>javax.faces</artifactId>
73+
<version>2.2.2</version>
74+
<scope>compile</scope>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>javax.servlet</groupId>
79+
<artifactId>javax.servlet-api</artifactId>
80+
<version>3.0.1</version>
81+
<scope>provided</scope>
82+
</dependency>
83+
</dependencies>
84+
85+
<build>
86+
<plugins>
87+
<plugin>
88+
<artifactId>maven-compiler-plugin</artifactId>
89+
<version>3.0</version>
90+
<configuration>
91+
<source>1.7</source>
92+
<target>1.7</target>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
98+
</project>

src/main/java/CriaLancamentos.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import java.math.BigDecimal;
2+
import java.util.Calendar;
3+
4+
import javax.persistence.EntityManager;
5+
import javax.persistence.EntityTransaction;
6+
7+
import com.algaworks.financeiro.model.Lancamento;
8+
import com.algaworks.financeiro.model.Pessoa;
9+
import com.algaworks.financeiro.model.TipoLancamento;
10+
import com.algaworks.financeiro.util.JpaUtil;
11+
12+
public class CriaLancamentos {
13+
14+
public static void main(String[] args) {
15+
EntityManager manager = JpaUtil.getEntityManager();
16+
EntityTransaction trx = manager.getTransaction();
17+
trx.begin();
18+
19+
Calendar dataVencimento1 = Calendar.getInstance();
20+
dataVencimento1.set(2013, 10, 1, 0, 0, 0);
21+
22+
Calendar dataVencimento2 = Calendar.getInstance();
23+
dataVencimento2.set(2013, 12, 10, 0, 0, 0);
24+
25+
Pessoa cliente = new Pessoa();
26+
cliente.setNome("WWW Indústria de Alimentos");
27+
28+
Pessoa fornecedor = new Pessoa();
29+
fornecedor.setNome("SoftBRAX Treinamentos");
30+
31+
Lancamento lancamento1 = new Lancamento();
32+
lancamento1.setDescricao("Venda de licença de software");
33+
lancamento1.setPessoa(cliente);
34+
lancamento1.setDataVencimento(dataVencimento1.getTime());
35+
lancamento1.setDataPagamento(dataVencimento1.getTime());
36+
lancamento1.setValor(new BigDecimal(103_000));
37+
lancamento1.setTipo(TipoLancamento.RECEITA);
38+
39+
Lancamento lancamento2 = new Lancamento();
40+
lancamento2.setDescricao("Venda de suporte anual");
41+
lancamento2.setPessoa(cliente);
42+
lancamento2.setDataVencimento(dataVencimento1.getTime());
43+
lancamento2.setDataPagamento(dataVencimento1.getTime());
44+
lancamento2.setValor(new BigDecimal(15_000));
45+
lancamento2.setTipo(TipoLancamento.RECEITA);
46+
47+
Lancamento lancamento3 = new Lancamento();
48+
lancamento3.setDescricao("Treinamento da equipe");
49+
lancamento3.setPessoa(fornecedor);
50+
lancamento3.setDataVencimento(dataVencimento2.getTime());
51+
lancamento3.setValor(new BigDecimal(68_000));
52+
lancamento3.setTipo(TipoLancamento.DESPESA);
53+
54+
manager.persist(cliente);
55+
manager.persist(fornecedor);
56+
manager.persist(lancamento1);
57+
manager.persist(lancamento2);
58+
manager.persist(lancamento3);
59+
60+
trx.commit();
61+
manager.close();
62+
}
63+
64+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<persistence version="2.0"
3+
xmlns="http://java.sun.com/xml/ns/persistence"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
6+
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
7+
8+
<persistence-unit name="FinanceiroPU">
9+
<provider>org.hibernate.ejb.HibernatePersistence</provider>
10+
11+
<properties>
12+
<property name="javax.persistence.jdbc.url"
13+
value="jdbc:mysql://localhost/ebookjsf" />
14+
<property name="javax.persistence.jdbc.user" value="root" />
15+
<property name="javax.persistence.jdbc.password" value="algaworks" />
16+
<property name="javax.persistence.jdbc.driver"
17+
value="com.mysql.jdbc.Driver" />
18+
19+
<property name="hibernate.dialect"
20+
value="org.hibernate.dialect.MySQL5Dialect" />
21+
<property name="hibernate.show_sql" value="true" />
22+
<property name="hibernate.format_sql" value="true" />
23+
<property name="hibernate.hbm2ddl.auto" value="update" />
24+
</properties>
25+
</persistence-unit>
26+
27+
</persistence>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.algaworks.financeiro.controller;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
import javax.faces.application.FacesMessage;
7+
import javax.faces.context.FacesContext;
8+
import javax.faces.event.AjaxBehaviorEvent;
9+
import javax.inject.Inject;
10+
import javax.inject.Named;
11+
12+
import com.algaworks.financeiro.model.Lancamento;
13+
import com.algaworks.financeiro.model.Pessoa;
14+
import com.algaworks.financeiro.model.TipoLancamento;
15+
import com.algaworks.financeiro.repository.Lancamentos;
16+
import com.algaworks.financeiro.repository.Pessoas;
17+
import com.algaworks.financeiro.service.CadastroLancamentos;
18+
import com.algaworks.financeiro.service.NegocioException;
19+
20+
@Named
21+
@javax.faces.view.ViewScoped
22+
public class CadastroLancamentoBean implements Serializable {
23+
24+
private static final long serialVersionUID = 1L;
25+
26+
@Inject
27+
private CadastroLancamentos cadastro;
28+
29+
@Inject
30+
private Pessoas pessoas;
31+
32+
@Inject
33+
private Lancamentos lancamentos;
34+
35+
private Lancamento lancamento;
36+
private List<Pessoa> todasPessoas;
37+
38+
public void prepararCadastro() {
39+
this.todasPessoas = this.pessoas.todas();
40+
41+
if (this.lancamento == null) {
42+
this.lancamento = new Lancamento();
43+
}
44+
}
45+
46+
public List<String> pesquisarDescricoes(String descricao) {
47+
return this.lancamentos.descricoesQueContem(descricao);
48+
}
49+
50+
public void dataVencimentoAlterada(AjaxBehaviorEvent event) {
51+
if (this.lancamento.getDataPagamento() == null) {
52+
this.lancamento.setDataPagamento(this.lancamento.getDataVencimento());
53+
}
54+
}
55+
56+
public void salvar() {
57+
FacesContext context = FacesContext.getCurrentInstance();
58+
59+
try {
60+
this.cadastro.salvar(this.lancamento);
61+
62+
this.lancamento = new Lancamento();
63+
context.addMessage(null, new FacesMessage("Lançamento salvo com sucesso!"));
64+
} catch (NegocioException e) {
65+
66+
FacesMessage mensagem = new FacesMessage(e.getMessage());
67+
mensagem.setSeverity(FacesMessage.SEVERITY_ERROR);
68+
context.addMessage(null, mensagem);
69+
}
70+
}
71+
72+
public List<Pessoa> getTodasPessoas() {
73+
return this.todasPessoas;
74+
}
75+
76+
public TipoLancamento[] getTiposLancamentos() {
77+
return TipoLancamento.values();
78+
}
79+
80+
public Lancamento getLancamento() {
81+
return lancamento;
82+
}
83+
84+
public void setLancamento(Lancamento lancamento) {
85+
this.lancamento = lancamento;
86+
}
87+
88+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.algaworks.financeiro.controller;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
import javax.faces.application.FacesMessage;
7+
import javax.faces.context.FacesContext;
8+
import javax.faces.view.ViewScoped;
9+
import javax.inject.Inject;
10+
import javax.inject.Named;
11+
12+
import com.algaworks.financeiro.model.Lancamento;
13+
import com.algaworks.financeiro.repository.Lancamentos;
14+
import com.algaworks.financeiro.service.CadastroLancamentos;
15+
import com.algaworks.financeiro.service.NegocioException;
16+
17+
@Named
18+
@ViewScoped
19+
public class ConsultaLancamentosBean implements Serializable {
20+
21+
private static final long serialVersionUID = 1L;
22+
23+
@Inject
24+
private Lancamentos lancamentosRepository;
25+
26+
@Inject
27+
private CadastroLancamentos cadastro;
28+
29+
private List<Lancamento> lancamentos;
30+
31+
private Lancamento lancamentoSelecionado;
32+
33+
public void excluir() {
34+
FacesContext context = FacesContext.getCurrentInstance();
35+
36+
try {
37+
this.cadastro.excluir(this.lancamentoSelecionado);
38+
this.consultar();
39+
40+
context.addMessage(null, new FacesMessage("Lançamento excluído com sucesso!"));
41+
} catch (NegocioException e) {
42+
43+
FacesMessage mensagem = new FacesMessage(e.getMessage());
44+
mensagem.setSeverity(FacesMessage.SEVERITY_ERROR);
45+
context.addMessage(null, mensagem);
46+
}
47+
}
48+
49+
public void consultar() {
50+
this.lancamentos = lancamentosRepository.todos();
51+
}
52+
53+
public List<Lancamento> getLancamentos() {
54+
return lancamentos;
55+
}
56+
57+
public Lancamento getLancamentoSelecionado() {
58+
return lancamentoSelecionado;
59+
}
60+
61+
public void setLancamentoSelecionado(Lancamento lancamentoSelecionado) {
62+
this.lancamentoSelecionado = lancamentoSelecionado;
63+
}
64+
65+
}

0 commit comments

Comments
 (0)