-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adicionados pacotes e arquivos base do projeto. Conforme issue #31 * Adicionadas dependências base: jsf, junit, etc. * Adicionado META-INF e WEB-INF * Consertado pom (retirada tag plugins) * Alterado POM com plugin corrigindo erro war * Alterado caminho web-inf * Adicionadas dependências restantes. * Alterado jsf pro de verdade * Update pom.xml * a * a * Alteradas linhas a mais. * Adicionadas classes comuns a todos, além de remover alguns txt's desnecessários. * Modificado pom e adicionado favicon 'Sb' à pagina index * Teste de Cliente * Correção Cliente
- Loading branch information
1 parent
ad7e741
commit 8d112b6
Showing
17 changed files
with
667 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/github/viniciussoaresti/controladores/ClienteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*MIT License | ||
Copyright (c) 2018 - SysGraph - Vinícius H., Matheus Dionísio, Pedro Barros e Tiago Eduardo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE.*/ | ||
|
||
package com.github.viniciussoaresti.controladores; | ||
import com.github.viniciussoaresti.infraestrutura.repositorios.comportamentos.RepositorioGenerico; | ||
import com.github.viniciussoaresti.infraestrutura.repositorios.implementacoes.RepositorioClienteImplBD; | ||
import com.github.viniciussoaresti.negocio.Cliente; | ||
import java.util.List; | ||
import javax.faces.application.FacesMessage; | ||
import javax.faces.bean.ManagedBean; | ||
import javax.faces.bean.SessionScoped; | ||
import javax.faces.context.FacesContext; | ||
/** | ||
* | ||
* @author Vinícius Soares | ||
*/ | ||
@ManagedBean | ||
@SessionScoped | ||
public class ClienteController { | ||
|
||
private RepositorioGenerico<Cliente,String> repositorioCliente = null; | ||
private Cliente clienteCadastro; | ||
private Cliente selectedCliente; | ||
|
||
public ClienteController(){ | ||
this.repositorioCliente = new RepositorioClienteImplBD(); | ||
this.clienteCadastro = new Cliente(); | ||
} | ||
|
||
public void inserir(){ | ||
|
||
this.repositorioCliente.inserir(this.clienteCadastro); | ||
this.clienteCadastro = new Cliente(); | ||
|
||
FacesContext.getCurrentInstance().addMessage(null, | ||
new FacesMessage(FacesMessage.SEVERITY_INFO,"Sucesso!","O cliente foi cadastrado com sucesso!")); | ||
} | ||
|
||
public void alterar(Cliente c){ | ||
this.repositorioCliente.alterar(c); | ||
FacesContext.getCurrentInstance().addMessage(null, | ||
new FacesMessage(FacesMessage.SEVERITY_INFO,"Sucesso!","O cliente foi alterado com sucesso!")); | ||
} | ||
|
||
public Cliente recuperarCliente(String CPFCNPJ){ | ||
return this.repositorioCliente.recuperar(CPFCNPJ); | ||
} | ||
|
||
public void deletar(Cliente c){ | ||
this.repositorioCliente.deletar(c); | ||
FacesContext.getCurrentInstance().addMessage(null, | ||
new FacesMessage(FacesMessage.SEVERITY_INFO,"Sucesso!","O cliente foi deletado com sucesso!")); | ||
} | ||
|
||
public List<Cliente> recuperarTodosClientes(){ | ||
return this.repositorioCliente.recuperarTodos(); | ||
} | ||
|
||
public Cliente getClienteCadastro() { | ||
return clienteCadastro; | ||
} | ||
|
||
public void setClienteCadastro(Cliente clienteCadastro) { | ||
this.clienteCadastro = clienteCadastro; | ||
} | ||
|
||
public Cliente getSelectedCliente() { | ||
return selectedCliente; | ||
} | ||
|
||
public void setSelectedCliente(Cliente selectedCliente) { | ||
this.selectedCliente = selectedCliente; | ||
} | ||
|
||
public RepositorioGenerico<Cliente, String> getRepositorioCliente() { | ||
return repositorioCliente; | ||
} | ||
|
||
public void setRepositorioCliente(RepositorioGenerico<Cliente, String> repositorioCliente) { | ||
this.repositorioCliente= repositorioCliente; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/github/viniciussoaresti/conversores/ClienteConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*MIT License | ||
Copyright (c) 2018 - SysGraph - Vinícius H., Matheus Dionísio, Pedro Barros e Tiago Eduardo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE.*/ | ||
|
||
package com.github.viniciussoaresti.conversores; | ||
import com.github.viniciussoaresti.controladores.ClienteController; | ||
import com.github.viniciussoaresti.negocio.Cliente; | ||
import java.lang.annotation.Annotation; | ||
import javax.faces.application.FacesMessage; | ||
import javax.faces.component.UIComponent; | ||
import javax.faces.context.FacesContext; | ||
import javax.faces.convert.Converter; | ||
import javax.faces.convert.ConverterException; | ||
import javax.faces.convert.FacesConverter; | ||
/** | ||
* | ||
* @author Vinícius Soares | ||
*/ | ||
|
||
@FacesConverter("clienteConverter") | ||
public class ClienteConverter { | ||
public Object getAsObject(FacesContext fc, UIComponent uic, String value) { | ||
if(value != null && value.trim().length() > 0) { | ||
try { | ||
ClienteController service = (ClienteController) fc.getExternalContext().getSessionMap().get("clienteController"); | ||
return service.recuperarCliente(value); | ||
} catch(NumberFormatException e) { | ||
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme.")); | ||
} | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
public String getAsString(FacesContext fc, UIComponent uic, Object object) { | ||
if(object != null) { | ||
return String.valueOf(((Cliente) object).getCPFCNPJ()); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,4 +91,4 @@ public void delete(Object o){ | |
em.getTransaction().commit(); | ||
em.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...ithub/viniciussoaresti/infraestrutura/repositorios/implementacoes/RepositorioCliente.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*MIT License | ||
Copyright (c) 2018 - SysGraph - Vinícius H., Matheus Dionísio, Pedro Barros e Tiago Eduardo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE.*/ | ||
|
||
package com.github.viniciussoaresti.infraestrutura.repositorios.implementacoes; | ||
import com.github.viniciussoaresti.negocio.Cliente; | ||
import com.github.viniciussoaresti.infraestrutura.repositorios.comportamentos.RepositorioGenerico; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* | ||
* @author Vinícius Soares | ||
*/ | ||
public class RepositorioCliente implements RepositorioGenerico<Cliente, String> { | ||
private List<Cliente> clientes = null; | ||
|
||
public RepositorioCliente() { | ||
this.clientes = new ArrayList<>(); | ||
} | ||
@Override | ||
public void inserir(Cliente t){ | ||
this.clientes.add(t); | ||
} | ||
|
||
@Override | ||
public void alterar (Cliente t){ | ||
for (Cliente e : this.clientes){ | ||
if (e.getNome().equals( t.getNome())){ | ||
e.setCPFCNPJ(t.getCPFCNPJ()); | ||
e.setEmail(t.getEmail()); | ||
e.setIdade(t.getIdade()); | ||
e.setNome(t.getNome()); | ||
e.setTelefone(t.getTelefone()); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Cliente recuperar(String CPFCNPJ){ | ||
for (Cliente e : this.clientes){ | ||
if(e.getCPFCNPJ().equals(CPFCNPJ) ){ | ||
return e; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void deletar(Cliente t){ | ||
this.clientes.remove(t); | ||
} | ||
|
||
@Override | ||
public List<Cliente> recuperarTodos(){ | ||
return this.clientes; | ||
} | ||
|
||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...viniciussoaresti/infraestrutura/repositorios/implementacoes/RepositorioClienteImplBD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*MIT License | ||
Copyright (c) 2018 - SysGraph - Vinícius H., Matheus Dionísio, Pedro Barros e Tiago Eduardo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE.*/ | ||
package com.github.viniciussoaresti.infraestrutura.repositorios.implementacoes; | ||
import com.github.viniciussoaresti.infraestrutura.dao.PersistenceDao; | ||
import com.github.viniciussoaresti.infraestrutura.repositorios.comportamentos.RepositorioGenerico; | ||
import com.github.viniciussoaresti.negocio.Cliente; | ||
import java.util.List; | ||
import javax.persistence.Persistence; | ||
/** | ||
* | ||
* @author Vinícius Soares | ||
*/ | ||
public class RepositorioClienteImplBD implements RepositorioGenerico<Cliente, String>{ | ||
@Override | ||
public void inserir(Cliente t) { | ||
PersistenceDao.getInstance().persist(t); | ||
} | ||
|
||
@Override | ||
public void alterar(Cliente t) { | ||
PersistenceDao.getInstance().update(t); | ||
} | ||
|
||
@Override | ||
public Cliente recuperar(String CPFCNPJ) { | ||
try{ | ||
return (Cliente)PersistenceDao.getInstance().read("select a from Cliente a where a.CPFCNPJ="+CPFCNPJ).get(0); | ||
}catch(IndexOutOfBoundsException index){ | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void deletar(Cliente t) { | ||
PersistenceDao.getInstance().delete(t); | ||
|
||
} | ||
|
||
@Override | ||
public List<Cliente> recuperarTodos() { | ||
return PersistenceDao.getInstance().read("select a from Cliente a"); | ||
|
||
} | ||
public Cliente recuperaLogin(String CPFCNPJ){ | ||
try{ | ||
return(Cliente)(PersistenceDao.getInstance().read("select a from Cliente a where a.CPFCNPJ='"+CPFCNPJ+"'").get(0)); | ||
}catch(IndexOutOfBoundsException index){ | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.