Commit cea444d9 authored by Mathias Voelcker's avatar Mathias Voelcker
Browse files

Merge branch 'dev' into homo

parents 65e5f88e fcfe28c2
Showing with 127 additions and 120 deletions
+127 -120
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/WebContent/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/WebContent" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/resources" />
<root url="file://$MODULE_DIR$/src" />
</sourceRoots>
</configuration>
</facet>
<facet type="hibernate" name="Hibernate">
<configuration>
<datasource-map>
<unit-entry name="hibernate.cfg.xml" />
<unit-entry name="resources:hibernate.cfg.xml" />
</datasource-map>
<naming-strategy-map />
<deploymentDescriptor name="hibernate.cfg.xml" url="file://$MODULE_DIR$/resources/hibernate.cfg.xml" />
<deploymentDescriptor name="hibernate.cfg.xml" url="file://$MODULE_DIR$/test/resources/hibernate.cfg.xml" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.35" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.26-b03" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.26-b03" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.bundles.repackaged:jersey-guava:2.26-b03" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.26-b03" level="project" />
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.1-m05" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.26-b03" level="project" />
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.5.0-b36" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.5.0-b36" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0-b36" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:javax.inject:2.5.0-b36" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.5.0-b36" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet-core:2.26-b09" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt:0.7.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-email:1.4" level="project" />
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.5.2" level="project" />
<orderEntry type="library" name="Maven: javax.activation:activation:1.1.1" level="project" />
<orderEntry type="library" name="Maven: commons-validator:commons-validator:1.4.0" level="project" />
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.3" level="project" />
<orderEntry type="library" name="Maven: commons-digester:commons-digester:1.8" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-all:2.0.2-beta" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.2.10.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.3.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.0" level="project" />
<orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.0.Final" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.26-b08" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-json-jackson:2.26-b09" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.ext:jersey-entity-filtering:2.26-b09" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.4" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.2.Final" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -6,14 +6,18 @@ import java.util.HashMap;
import java.util.List;
import br.com.gastronomia.dao.AtributoDAO;
import br.com.gastronomia.dao.ReceitaDAO;
import br.com.gastronomia.exception.ValidationException;
import br.com.gastronomia.model.Atributo;
import br.com.gastronomia.model.IngredienteAtributo;
import br.com.gastronomia.model.Receita;
import br.com.gastronomia.model.ReceitaIngrediente;
import br.com.gastronomia.util.Constantes;
import br.com.gastronomia.util.EncryptUtil;
import br.com.gastronomia.util.MensagemContantes;
import br.com.gastronomia.util.Validator;
//branch demo
public class AtributoBO {
public class AtributoBO {
private AtributoDAO atributoDAO;
public AtributoBO() {
......@@ -28,6 +32,7 @@ public class AtributoBO {
if (atributo != null) {
try {
atributo.setStatus(true);
atributoDAO.save(atributo);
return true;
} catch (Exception e) {
......@@ -39,6 +44,19 @@ public class AtributoBO {
}
public long inactiveAtributo(long id) throws ValidationException {
ReceitaDAO receitaDAO = new ReceitaDAO();
List<Receita> receitas = receitaDAO.listAllReceitas();
for (Receita receita : receitas) {
for(ReceitaIngrediente receitaIngrediente : receita.getReceitaIngrediente()) {
for(IngredienteAtributo ingredienteAtributo : receitaIngrediente.getIngrediente().getIngredienteAtributo()) {
if(ingredienteAtributo.getAtributo().getId() == id) {
throw new ValidationException("Atributo vínculado à uma receita.");
}
}
}
}
return atributoDAO.alterStatus(id, false);
}
......@@ -48,6 +66,7 @@ public class AtributoBO {
public long updateAtributo(Atributo atributo) throws ValidationException {
if (atributo != null) {
atributo.setStatus(true);
return atributoDAO.updateAtributo(atributo);
}
throw new ValidationException("invalido");
......@@ -67,12 +86,23 @@ public class AtributoBO {
return listAtributos;
}
public HashMap<String, List<Atributo>> listActivesAtributos() {
ArrayList<Atributo> atributos = null;
HashMap<String, List<Atributo>> listAtributos = new HashMap<String, List<Atributo>>();
atributos = (ArrayList<Atributo>) atributoDAO.findMultipleObjects("status",Atributo.class, true);
listAtributos.put("Atributos", atributos);
return listAtributos;
}
public Atributo getAtributoById(long id) throws ValidationException {
if (id > 0) {
if (id != 0) {
return atributoDAO.findAtributoByID(id);
}
throw new ValidationException("invalido");
}
}
......@@ -6,8 +6,10 @@ import java.util.HashMap;
import java.util.List;
import br.com.gastronomia.dao.GrupoReceitasDAO;
import br.com.gastronomia.dao.ReceitaDAO;
import br.com.gastronomia.exception.ValidationException;
import br.com.gastronomia.model.GrupoReceitas;
import br.com.gastronomia.model.Receita;
import br.com.gastronomia.util.Constantes;
import br.com.gastronomia.util.EncryptUtil;
import br.com.gastronomia.util.MensagemContantes;
......@@ -27,6 +29,7 @@ public class GrupoReceitasBO {
public boolean createGroup(GrupoReceitas grupo) throws ValidationException, NoSuchAlgorithmException {
if (grupo != null) {
try {
grupo.setStatus(true);
grupoReceitasDAO.save(grupo);
return true;
} catch (Exception e) {
......@@ -38,6 +41,16 @@ public class GrupoReceitasBO {
}
public long deactivateGroup(long id) throws ValidationException {
ReceitaDAO receitaDAO = new ReceitaDAO();
List<Receita> receitas = receitaDAO.listAllReceitas();
for (Receita receita : receitas) {
if(receita.getGrupoReceita().getId() == id) {
throw new ValidationException("Grupo vínculado à uma receita.");
}
}
return grupoReceitasDAO.alterStatus(id, false);
}
......@@ -47,6 +60,7 @@ public class GrupoReceitasBO {
public long updateGroup(GrupoReceitas grupoReceitas) throws ValidationException {
if (grupoReceitas != null) {
grupoReceitas.setStatus(true);
return grupoReceitasDAO.updateGroup(grupoReceitas);
}
throw new ValidationException("invalido");
......@@ -65,6 +79,14 @@ public class GrupoReceitasBO {
return listGrupoReceitas;
}
public HashMap<String, List<GrupoReceitas>> listGroupsActived() {
HashMap<String, List<GrupoReceitas>> listGrupoReceitas = new HashMap<String, List<GrupoReceitas>>();
List<GrupoReceitas> grupoReceitas = grupoReceitasDAO.findMultipleObjects("status",GrupoReceitas.class,true);
listGrupoReceitas.put("Grupos", grupoReceitas);
return listGrupoReceitas;
}
public GrupoReceitas getGroupByCod(long id) throws ValidationException {
if (id != 0) {
return grupoReceitasDAO.findGroupByID(id);
......
......@@ -2,6 +2,7 @@ package br.com.gastronomia.bo;
import br.com.gastronomia.dao.AtributoDAO;
import br.com.gastronomia.dao.IngredienteDAO;
import br.com.gastronomia.dao.ReceitaDAO;
import br.com.gastronomia.dao.UsuarioDAO;
import br.com.gastronomia.dto.IngredienteAtributoDto;
import br.com.gastronomia.dto.IngredienteCadastroDTO;
......@@ -19,15 +20,22 @@ public class IngredienteBO {
private IngredienteDAO ingredienteDAO;
private UsuarioDAO usuarioDAO;
private AtributoDAO atributoDAO;
private ReceitaDAO receitaDAO;
public IngredienteBO() {
ingredienteDAO = new IngredienteDAO();
usuarioDAO = new UsuarioDAO();
atributoDAO = new AtributoDAO();
receitaDAO = new ReceitaDAO();
}
public long inactiveIngrediente(long id) throws ValidationException {
if (id > 0){
List<Ingrediente> ingredientes = ingredienteDAO.findReceitaIngredienteByIdIngrediente(id);
if (ingredientes.size() > 0)
throw new ValidationException("Ingrediente não pode ser excluído");
}
return ingredienteDAO.alterStatus(id, false);
}
......@@ -43,16 +51,9 @@ public class IngredienteBO {
}
public boolean createIngrediente(IngredienteCadastroDTO ingredienteDto) throws ValidationException, NoSuchAlgorithmException {
if (ingredienteDto != null) {
public boolean createIngrediente(Ingrediente ingrediente) throws ValidationException, NoSuchAlgorithmException {
if (ingrediente != null) {
try {
Usuario usuario = usuarioDAO.findUserByID(ingredienteDto.getIdCriador());
Ingrediente ingrediente = new Ingrediente();
ingrediente.setIngredienteInfoCadastro(ingredienteDto, usuario);
for (IngredienteAtributoDto ingAtr: ingredienteDto.getAtributos()) {
ingrediente.addIngredienteAtributo(atributoDAO.findAtributoByID(ingAtr.getIdAtributo()), ingAtr.getValor());
}
ingredienteDAO.save(ingrediente);
return true;
} catch (ValidationException | NullPointerException e) {
......
......@@ -48,6 +48,21 @@ public class AtributoController {
}
@GET
@Path("/ativos")
@Produces("application/json; charset=UTF-8")
//@JWTTokenNeeded
public Response listActives() throws PersistenciaException, SQLException {
try {
return Response.ok().entity(atributoBO.listActivesAtributos()).status(Response.Status.ACCEPTED).build();
} catch (Exception e) {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
}
}
@POST
@Path("/")
@Consumes("application/json; charset=UTF-8")
......@@ -68,17 +83,15 @@ public class AtributoController {
@Path("/{id}")
@Produces("application/json; charset=UTF-8")
//@JWTTokenNeeded
public Response remove(@PathParam("id") Long id) throws PersistenciaException, ValidationException {
public Response remove(@PathParam("id") Long id) throws PersistenciaException {
try {
atributoBO.inactiveAtributo(id);
} catch (Exception e) {
} catch (ValidationException e) {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
return Response.ok().entity(new StandardResponseDTO(true, e.getMessage())).status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().entity(new StandardResponseDTO(true, "Atributo desativado com sucesso!")).status(Response.Status.ACCEPTED).build();
return Response.ok().entity(new StandardResponseDTO(true, "Atributo excluído com sucesso!")).status(Response.Status.ACCEPTED).build();
}
@GET
@Path("/{id}")
......
......@@ -46,6 +46,19 @@ public class GrupoController {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
}
}@GET
@Path("/ativos")
@Produces("application/json; charset=UTF-8")
//@JWTTokenNeeded
public Response listActived() throws PersistenciaException, SQLException {
try {
return Response.ok().entity(grupoReceitasBO.listGroupsActived()).status(Response.Status.ACCEPTED).build();
} catch (Exception e) {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
}
}
@POST
......@@ -71,16 +84,16 @@ public class GrupoController {
@Path("/{id}")
@Produces("application/json; charset=UTF-8")
//@JWTTokenNeeded
public Response remove(@PathParam("id") Long id) throws PersistenciaException, ValidationException {
public Response remove(@PathParam("id") Long id) throws PersistenciaException {
try {
grupoReceitasBO.deactivateGroup(id);
} catch (Exception e) {
} catch (ValidationException e) {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
return Response.ok().entity(new StandardResponseDTO(true, e.getMessage())).status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().entity(new StandardResponseDTO(true, "Grupo de Receita desativado com sucesso!")).status(Response.Status.ACCEPTED).build();
return Response.ok().entity(new StandardResponseDTO(true, "Grupo de Receita excluído com sucesso!")).status(Response.Status.ACCEPTED).build();
}
@GET
......
......@@ -44,14 +44,13 @@ public class IngredienteController {
@Consumes("application/json; charset=UTF-8")
@Produces("application/json; charset=UTF-8")
//@JWTTokenNeeded
public Response create(IngredienteCadastroDTO ingredienteDto) throws PersistenciaException, ValidationException {
public Response create(Ingrediente ingrediente) throws PersistenciaException, ValidationException {
try {
System.out.println(ingredienteDto);
ingredienteBO.createIngrediente(ingredienteDto);
ingredienteBO.createIngrediente(ingrediente);
} catch (Exception e) {
return Response.ok().entity(new StandardResponseDTO(true, e.getMessage())).status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().entity(new StandardResponseDTO(true, "Ingrediente "+ingredienteDto.getNome()+", criado com sucesso!")).status(Response.Status.ACCEPTED).build();
return Response.ok().entity(new StandardResponseDTO(true, "Ingrediente "+ingrediente.getNome()+", criado com sucesso!")).status(Response.Status.ACCEPTED).build();
}
@DELETE
......@@ -65,7 +64,7 @@ public class IngredienteController {
} catch (Exception e) {
return Response.ok().status(Response.Status.BAD_REQUEST).build();
return Response.ok(e.getMessage()).status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().entity(new StandardResponseDTO(true, "Ingrediente desativado com sucesso!")).status(Response.Status.ACCEPTED).build();
......
......@@ -17,6 +17,7 @@ public class GrupoReceitasDAO extends GenericHibernateDAO<GrupoReceitas> {
return grupos;
}
public GrupoReceitas findGroupByCod(long codGrupos) {
return (GrupoReceitas) findSingleObject("IdGrupo", GrupoReceitas.class, String.valueOf(codGrupos));
}
......
......@@ -4,9 +4,11 @@ import br.com.gastronomia.db.GenericHibernateDAO;
import br.com.gastronomia.db.HibernateUtil;
import br.com.gastronomia.exception.ValidationException;
import br.com.gastronomia.model.Ingrediente;
import br.com.gastronomia.model.ReceitaIngrediente;
import org.hibernate.Session;
import java.util.List;
import java.util.stream.Collectors;
public class IngredienteDAO extends GenericHibernateDAO<Ingrediente> {
public List<Ingrediente> listForName(Object Ingrediente, String q) {
......@@ -16,7 +18,10 @@ public class IngredienteDAO extends GenericHibernateDAO<Ingrediente> {
}
public List<Ingrediente> listAllIngredientes(){
List<Ingrediente> ingredientes = listAll(Ingrediente.class);
List<Ingrediente> ingredientes = listAll(Ingrediente.class)
.stream()
.filter(ingrediente -> { return ingrediente.getStatus(); })
.collect(Collectors.toList());
return ingredientes;
}
......@@ -28,6 +33,10 @@ public class IngredienteDAO extends GenericHibernateDAO<Ingrediente> {
return (Ingrediente) findSingleObject("id", Ingrediente.class, id);
}
public List<Ingrediente> findReceitaIngredienteByIdIngrediente(Long id) {
return findMultipleObjects("ingrediente", ReceitaIngrediente.class, id);
}
public long updateIngrediente(Ingrediente ingrediente) throws ValidationException {
return merge(ingrediente);
}
......@@ -37,4 +46,6 @@ public class IngredienteDAO extends GenericHibernateDAO<Ingrediente> {
ingrediente.setStatus(statusBool);
return merge(ingrediente);
}
}
......@@ -76,6 +76,7 @@ public class GenericHibernateDAO<T> implements GenericDAO<T> {
return objects;
}
public List<T> listAllOrder(Class<?> T, String field) {
Session session = HibernateUtil.getFactory();
String queryAll = "Select t from " + T.getSimpleName() + " t ORDER BY "+field+" ASC ";
......@@ -145,13 +146,17 @@ public class GenericHibernateDAO<T> implements GenericDAO<T> {
public List<T> findMultipleObjects(String parameter, Class<?> T, Object valueParameter) {
Session session = HibernateUtil.getFactory();
List <T> results;
String hql = "Select T FROM " + T.getSimpleName() + " T where T." + parameter + " = ?" ;
List<T> results = session.createQuery(hql).setString(0, valueParameter.toString()).list(); //Deprecated
if(valueParameter instanceof Boolean)
results = session.createQuery(hql).setBoolean(0, (Boolean) valueParameter).list(); //Deprecated
else
results = session.createQuery(hql).setString(0, valueParameter.toString()).list(); //Deprecated
session.close();
return results;
}
@Override
public long merge(Object T) throws ValidationException {
Session session = HibernateUtil.getFactory();
......
......@@ -123,4 +123,5 @@ public class Atributo implements Serializable {
+ " multiplicador: " + multiplicador + " obrigatório:"
+ obrigatorio + " status:" + status;
}
}
\ No newline at end of file
......@@ -54,6 +54,8 @@ public class GrupoReceitas implements Serializable {
*
**/
public GrupoReceitas() {
//this.status = true;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment