| @ -0,0 +1,55 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <classpath> | |||
| <classpathentry kind="src" output="target/classes" path="src/main/java"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| <attribute name="test" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| <attribute name="test" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" path="target/generated-sources/annotations"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| <attribute name="ignore_optional_problems" value="true"/> | |||
| <attribute name="m2e-apt" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| <attribute name="ignore_optional_problems" value="true"/> | |||
| <attribute name="m2e-apt" value="true"/> | |||
| <attribute name="test" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="output" path="target/classes"/> | |||
| </classpath> | |||
| @ -0,0 +1,23 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <projectDescription> | |||
| <name>AnimalAdvisor</name> | |||
| <comment></comment> | |||
| <projects> | |||
| </projects> | |||
| <buildSpec> | |||
| <buildCommand> | |||
| <name>org.eclipse.jdt.core.javabuilder</name> | |||
| <arguments> | |||
| </arguments> | |||
| </buildCommand> | |||
| <buildCommand> | |||
| <name>org.eclipse.m2e.core.maven2Builder</name> | |||
| <arguments> | |||
| </arguments> | |||
| </buildCommand> | |||
| </buildSpec> | |||
| <natures> | |||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||
| <nature>org.eclipse.m2e.core.maven2Nature</nature> | |||
| </natures> | |||
| </projectDescription> | |||
| @ -0,0 +1,2 @@ | |||
| eclipse.preferences.version=1 | |||
| org.eclipse.jdt.apt.aptEnabled=false | |||
| @ -0,0 +1,16 @@ | |||
| eclipse.preferences.version=1 | |||
| org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | |||
| org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||
| org.eclipse.jdt.core.compiler.compliance=1.8 | |||
| org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||
| org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||
| org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |||
| org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | |||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |||
| org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | |||
| org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | |||
| org.eclipse.jdt.core.compiler.processAnnotations=disabled | |||
| org.eclipse.jdt.core.compiler.release=disabled | |||
| org.eclipse.jdt.core.compiler.source=1.8 | |||
| @ -0,0 +1,4 @@ | |||
| activeProfiles= | |||
| eclipse.preferences.version=1 | |||
| resolveWorkspaceProjects=true | |||
| version=1 | |||
| @ -0,0 +1,30 @@ | |||
| Al iniciar el programa deberia mostrar un mensaje que no se ha espedificado el parametro | |||
| Los metodos que he implementado | |||
| "-bg" buscarcolor | |||
| Busca y lista aquellos animales que tenga ese color | |||
| "-ba" buscarPromedioVida | |||
| Busca y lista aquellos animales que tenga ese Promedio de Vida | |||
| "-bas" buscarDomesticos | |||
| Busca y lista aquellos animales que sen domesticos | |||
| "-n" buscarHabitat | |||
| Busca y lista aquellos animales que tenga ese habitat | |||
| "-d" buscarNombre | |||
| Busca y lista aquellos animales que tenga ese Nombre | |||
| "-bp" buscarTipo | |||
| Busca y lista aquellos animales que tenga ese Tipo | |||
| Todos los datos que he utilizado de animales es esta actividad son creados por mi. | |||
| No son realistas todos los datos aportados en la actividad | |||
| Diagrama: | |||
|  | |||
| @ -0,0 +1,22 @@ | |||
| <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>com.kevinsignes</groupId> | |||
| <artifactId>AnimalAdvisor</artifactId> | |||
| <version>0.0.1-SNAPSHOT</version> | |||
| <name>AnimalAdvisor</name> | |||
| <description>Actividad Juanjito Springcore</description> | |||
| <dependencies> | |||
| <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> | |||
| <dependency> | |||
| <groupId>org.springframework</groupId> | |||
| <artifactId>spring-context</artifactId> | |||
| <version>6.0.0</version> | |||
| </dependency> | |||
| <!--https://www.baeldung.com/spring-postconstruct-predestroy --> | |||
| <dependency> | |||
| <groupId>javax.annotation</groupId> | |||
| <artifactId>javax.annotation-api</artifactId> | |||
| <version>1.3.2</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @ -0,0 +1,19 @@ | |||
| package com.kevinsignes.animal.advisor; | |||
| import org.springframework.context.ApplicationContext; | |||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |||
| import com.kevinsignes.animaladvisor.config.*; | |||
| public class AnimalAdvisorApp { | |||
| public static void main(String[] args) { | |||
| ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class); | |||
| AnimalAdvisorRunApp runApp = appContext.getBean(AnimalAdvisorRunApp.class); | |||
| runApp.run(args); | |||
| ((AnnotationConfigApplicationContext) appContext).close(); | |||
| } | |||
| } | |||
| @ -0,0 +1,33 @@ | |||
| package com.kevinsignes.animal.advisor; | |||
| import java.io.IOException; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Paths; | |||
| import java.util.stream.Collectors; | |||
| import javax.annotation.PostConstruct; | |||
| import org.springframework.stereotype.Component; | |||
| import org.springframework.util.ResourceUtils; | |||
| @Component | |||
| public class AnimalAdvisorHelp { | |||
| private String help; | |||
| @PostConstruct | |||
| public void init() { | |||
| try { | |||
| //@formatter:off | |||
| help = Files | |||
| .lines(Paths.get(ResourceUtils.getFile("classpath:ayuda.txt").toURI())) | |||
| .collect(Collectors.joining("\n")); | |||
| //@formatter:on | |||
| } catch (IOException ioe) { | |||
| ioe.printStackTrace(); | |||
| } | |||
| } | |||
| public String getHelp() { | |||
| return help; | |||
| } | |||
| } | |||
| @ -0,0 +1,94 @@ | |||
| package com.kevinsignes.animal.advisor; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| import com.kevinsignes.animaladvisor.modelos.*; | |||
| import com.kevinsignes.animaladvisor.service.*; | |||
| @Component | |||
| public class AnimalAdvisorRunApp { | |||
| @Autowired | |||
| private AnimalService animalService; | |||
| @Autowired | |||
| private AnimalQueryService animalQueryService; | |||
| @Autowired | |||
| private AnimalAdvisorHelp help; | |||
| public void run(String[] args) { | |||
| // TODO Auto-generated method stub | |||
| if(args.length < -1) { | |||
| System.out.println("Error en la sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } else if (args.length == 1){ | |||
| switch(args[0].toLowerCase()) { | |||
| case "-l": | |||
| animalService.mostrarTodos().forEach(System.out::println); | |||
| break; | |||
| default: | |||
| System.out.println("Error en la sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } | |||
| } else if (args.length % 2 != 0) { | |||
| System.out.println("Error en la sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } else if (args.length == 0) { | |||
| System.out.println("No se ha pasado ningún parámetro"); | |||
| System.out.println(help.getHelp()); | |||
| } else { | |||
| List<String[]> argumentos = new ArrayList<>(); | |||
| for(int i = 0; i < args.length; i += 2) { | |||
| argumentos.add(new String[] {args[i], args[i + 1]}); | |||
| } | |||
| boolean error = false; | |||
| for(String[] argumento : argumentos) { | |||
| switch (argumento[0].toLowerCase()) { | |||
| case "-bg": | |||
| animalQueryService.buscarcolor(argumento[1]); | |||
| break; | |||
| case "-ba": | |||
| animalQueryService.buscarPromedioVida(argumento[1]); | |||
| break; | |||
| case "-bas": | |||
| animalQueryService.buscarDomesticos(argumento[1]); | |||
| break; | |||
| case "-n": | |||
| animalQueryService.buscarHabitat(argumento[1]); | |||
| break; | |||
| case "-d": | |||
| animalQueryService.buscarNombre(argumento[1]); | |||
| break; | |||
| case "-bp": | |||
| animalQueryService.buscarTipo(argumento[1]); | |||
| break; | |||
| default: | |||
| error = true; | |||
| System.out.println("Error en la sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } | |||
| } | |||
| if (!error) { | |||
| Collection<Animal> result = animalQueryService.ejecutar(); | |||
| System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n","ID","Nombre", "Tipo", "Habitat", "Promedio de vida", "Color", " Domestico"); | |||
| if (result != null) { | |||
| result.forEach(vg -> System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n", | |||
| vg.getId(), vg.getNombre(), vg.getTipo(), | |||
| vg.getHabitat(), vg.getPromediaVida(), vg.getColor(), vg.getDomestico())); | |||
| } else { | |||
| System.out.println("No hay animales que cumplan esos criterios. Lo sentimos mucho"); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,32 @@ | |||
| package com.kevinsignes.animaladvisor.config; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.context.annotation.ComponentScan; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.context.annotation.PropertySource; | |||
| @Configuration | |||
| @ComponentScan(basePackages="com.kevinsignes.animaladvisor") | |||
| @PropertySource("classpath:/animaladvisor.properties") | |||
| public class AppConfig { | |||
| @Value("${file.path}") | |||
| public String file; | |||
| @Value("${file.csv.separator}") | |||
| public String separator; | |||
| @Value("${file.csv.list_separator}") | |||
| public String listSeparator; | |||
| public String getFile() { | |||
| return file; | |||
| } | |||
| public String getSeparator() { | |||
| return separator; | |||
| } | |||
| public String getListSeparator() { | |||
| return listSeparator; | |||
| } | |||
| } | |||
| @ -0,0 +1,13 @@ | |||
| package com.kevinsignes.animaladvisor.dao; | |||
| import java.util.Collection; | |||
| import com.kevinsignes.animaladvisor.modelos.Animal; | |||
| public interface AnimalDao { | |||
| public Animal buscarPorId(long id); | |||
| public Collection<Animal> mostrarTodos(); | |||
| public void nuevoAnimal(Animal animal); | |||
| public void editarAnimal(Animal animal); | |||
| public void borrarAnimal(long id); | |||
| } | |||
| @ -0,0 +1,72 @@ | |||
| package com.kevinsignes.animaladvisor.dao; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import javax.annotation.PostConstruct; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Repository; | |||
| import com.kevinsignes.animaladvisor.modelos.Animal; | |||
| import com.kevinsignes.animaladvisor.config.AppConfig; | |||
| @Repository | |||
| public class AnimalDaoImplMemory implements AnimalDao { | |||
| public List<Animal> animales = new ArrayList<Animal>(); | |||
| @Autowired | |||
| private AppConfig appConfig; | |||
| @PostConstruct | |||
| public void iniciar() { | |||
| animales = UtilAnimalFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator()); | |||
| } | |||
| public Animal buscarPorId(long id) { | |||
| Optional<Animal> animalPorId = animales.stream().filter(ani -> ani.getId() == id).findFirst(); | |||
| return animalPorId.orElse(null); | |||
| } | |||
| public Collection<Animal> mostrarTodos() { | |||
| return animales; | |||
| } | |||
| public void nuevoAnimal(Animal animal) { | |||
| animales.add(animal); | |||
| } | |||
| public void editarAnimal(Animal animal) { | |||
| int i = obtenerId(animal.getId()); | |||
| if(i != -1) { | |||
| animales.set(i, animal); | |||
| } | |||
| } | |||
| public void borrarAnimal(long id) { | |||
| int i = obtenerId(id); | |||
| if(i != -1) { | |||
| animales.remove(i); | |||
| } | |||
| } | |||
| private int obtenerId(long id) { | |||
| boolean encontrado = false; | |||
| int i = 0; | |||
| while(!encontrado && i < animales.size()) { | |||
| if(animales.get(i).getId() == id) { | |||
| encontrado = true; | |||
| } else { | |||
| i++; | |||
| } | |||
| } | |||
| return (encontrado) ? i : -1; | |||
| } | |||
| } | |||
| @ -0,0 +1,36 @@ | |||
| package com.kevinsignes.animaladvisor.dao; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Paths; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| import org.springframework.util.ResourceUtils; | |||
| import com.kevinsignes.animaladvisor.modelos.Animal; | |||
| public class UtilAnimalFileReader { | |||
| public static List<Animal> readFile(final String path, final String separator, final String listSeparator) { | |||
| List<Animal> result = new ArrayList<Animal>(); | |||
| try { | |||
| // @formatter:off | |||
| result = Files | |||
| .lines(Paths.get(ResourceUtils.getFile(path).toURI())) | |||
| .skip(1) | |||
| .map(line -> { | |||
| String[] values = line.split(separator); | |||
| return new Animal(Long.parseLong(values[0]), values[1], values[2], | |||
| values[3],values[4], values[5],values[6] ) ; | |||
| }).collect(Collectors.toList()); | |||
| // @formatter:on | |||
| } catch (Exception e) { | |||
| System.err.println("Error de lectura del fichero de datos: animal.csv"); | |||
| System.exit(-1); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @ -0,0 +1,100 @@ | |||
| package com.kevinsignes.animaladvisor.modelos; | |||
| import java.util.Objects; | |||
| public class Animal { | |||
| private long id; | |||
| private String nombre; | |||
| private String tipo; | |||
| private String habitat; | |||
| private String promediaVida; | |||
| private String color; | |||
| private String domestico; | |||
| public Animal(long id, String nombre, String tipo, String habitat, String promediaVida, String color, | |||
| String domestico) { | |||
| super(); | |||
| this.id = id; | |||
| this.nombre = nombre; | |||
| this.tipo = tipo; | |||
| this.habitat = habitat; | |||
| this.promediaVida = promediaVida; | |||
| this.color = color; | |||
| this.domestico = domestico; | |||
| } | |||
| public long getId() { | |||
| return id; | |||
| } | |||
| public void setId(long id) { | |||
| this.id = id; | |||
| } | |||
| public String getNombre() { | |||
| return nombre; | |||
| } | |||
| public void setNombre(String nombre) { | |||
| this.nombre = nombre; | |||
| } | |||
| public String getTipo() { | |||
| return tipo; | |||
| } | |||
| public void setTipo(String tipo) { | |||
| this.tipo = tipo; | |||
| } | |||
| public String getHabitat() { | |||
| return habitat; | |||
| } | |||
| public void setHabitat(String habitat) { | |||
| this.habitat = habitat; | |||
| } | |||
| public String getPromediaVida() { | |||
| return promediaVida; | |||
| } | |||
| public void setPromediaVida(String promediaVida) { | |||
| this.promediaVida = promediaVida; | |||
| } | |||
| public String getColor() { | |||
| return color; | |||
| } | |||
| public void setColor(String color) { | |||
| this.color = color; | |||
| } | |||
| public String getDomestico() { | |||
| return domestico; | |||
| } | |||
| public void setDomestico(String domestico) { | |||
| this.domestico = domestico; | |||
| } | |||
| @Override | |||
| public int hashCode() { | |||
| return Objects.hash(color, domestico, habitat, id, nombre, promediaVida, tipo); | |||
| } | |||
| @Override | |||
| public boolean equals(Object obj) { | |||
| if (this == obj) | |||
| return true; | |||
| if (obj == null) | |||
| return false; | |||
| if (getClass() != obj.getClass()) | |||
| return false; | |||
| Animal other = (Animal) obj; | |||
| return Objects.equals(color, other.color) && Objects.equals(domestico, other.domestico) | |||
| && Objects.equals(habitat, other.habitat) && id == other.id && Objects.equals(nombre, other.nombre) | |||
| && Objects.equals(promediaVida, other.promediaVida) && Objects.equals(tipo, other.tipo); | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return "Animal [id=" + id + ", nombre=" + nombre + ", tipo=" + tipo + ", habitat=" + habitat + ", promediaVida=" | |||
| + promediaVida + ", color=" + color + ", domestico=" + domestico + "]"; | |||
| } | |||
| } | |||
| @ -0,0 +1,15 @@ | |||
| package com.kevinsignes.animaladvisor.service; | |||
| import java.util.Collection; | |||
| import com.kevinsignes.animaladvisor.modelos.Animal; | |||
| public interface AnimalQueryService { | |||
| public Collection<Animal> ejecutar(); | |||
| public AnimalQueryService buscarTipo(String tipo); | |||
| public AnimalQueryService buscarHabitat(String habitat); | |||
| public AnimalQueryService buscarPromedioVida(String promedioVida); | |||
| public AnimalQueryService buscarNombre(String nombre); | |||
| public AnimalQueryService buscarcolor(String color); | |||
| public AnimalQueryService buscarDomesticos(String domesticos); | |||
| } | |||
| @ -0,0 +1,82 @@ | |||
| package com.kevinsignes.animaladvisor.service; | |||
| import java.util.Collection; | |||
| import java.util.function.Predicate; | |||
| import java.util.stream.Collectors; | |||
| import javax.annotation.PostConstruct; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.kevinsignes.animaladvisor.dao.*; | |||
| import com.kevinsignes.animaladvisor.modelos.*; | |||
| @Service | |||
| public class AnimalQueryServiceImpl implements AnimalQueryService { | |||
| @Autowired | |||
| private AnimalDao dao; | |||
| private Predicate<Animal> predicate; | |||
| @PostConstruct | |||
| public void iniciar() { | |||
| predicate = null; | |||
| } | |||
| @Override | |||
| public Collection<Animal> ejecutar() { | |||
| //@formatter:off | |||
| return dao.mostrarTodos() | |||
| .stream() | |||
| .filter(predicate) | |||
| .collect(Collectors.toList()); | |||
| //@formatter:on | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarTipo(String tipo) { | |||
| Predicate<Animal> pBuscarTipo = (ani -> ani.getTipo().substring(ani.getTipo().length()-4, ani.getTipo().length()-1).equalsIgnoreCase(tipo)); | |||
| predicate = (predicate == null) ? pBuscarTipo : predicate.and(pBuscarTipo); | |||
| return this; | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarHabitat(String habitat) { | |||
| Predicate<Animal> pAnyo = (ani -> ani.getHabitat().substring(ani.getTipo().length()-4, ani.getTipo().length()-1).equalsIgnoreCase(habitat)); | |||
| predicate = (predicate == null) ? pAnyo : predicate.and(pAnyo); | |||
| return this; | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarNombre(String nombre) { | |||
| Predicate<Animal> pNombre = (ani -> ani.getNombre().substring(ani.getNombre().length()-4, ani.getNombre().length()-1).equalsIgnoreCase(nombre)); | |||
| predicate = (predicate == null) ? pNombre : predicate.and(pNombre); | |||
| return this; | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarPromedioVida(String promedioVida) { | |||
| Predicate<Animal> pPromedioVida = (ani -> ani.getPromediaVida().substring(ani.getPromediaVida().length()-4, ani.getPromediaVida().length()-1).equalsIgnoreCase(promedioVida)); | |||
| predicate = (predicate == null) ? pPromedioVida : predicate.and(pPromedioVida); | |||
| return this; | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarcolor(String color) { | |||
| Predicate<Animal> pBuscarcolor = (ani -> ani.getColor().substring(ani.getColor().length()-4, ani.getColor().length()-1).equalsIgnoreCase(color)); | |||
| predicate = (predicate == null) ? pBuscarcolor : predicate.and(pBuscarcolor); | |||
| return this; | |||
| } | |||
| @Override | |||
| public AnimalQueryService buscarDomesticos(String domesticos) { | |||
| Predicate<Animal> pDomesticos = (ani -> ani.getDomestico().substring(ani.getDomestico().length()-4, ani.getDomestico().length()-1).equalsIgnoreCase(domesticos)); | |||
| predicate = (predicate == null) ? pDomesticos : predicate.and(pDomesticos); | |||
| return this; | |||
| } | |||
| } | |||
| @ -0,0 +1,44 @@ | |||
| package com.kevinsignes.animaladvisor.service; | |||
| import java.util.Collection; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.kevinsignes.animaladvisor.dao.AnimalDao; | |||
| import com.kevinsignes.animaladvisor.modelos.Animal; | |||
| @Service | |||
| public class AnimalService { | |||
| @Autowired | |||
| AnimalDao animalDao; | |||
| @Autowired | |||
| AnimalQueryService queryService; | |||
| public Collection<Animal> buscarTipo(String tipo) { | |||
| return queryService.buscarTipo(tipo).ejecutar(); | |||
| } | |||
| public Collection<Animal> buscarPromedioVida(String anyo) { | |||
| return queryService.buscarPromedioVida(anyo).ejecutar(); | |||
| } | |||
| public Collection<Animal> buscarNombre(String nombre) { | |||
| return queryService.buscarNombre(nombre).ejecutar(); | |||
| } | |||
| public Collection<Animal> mostrarTodos() { | |||
| return animalDao.mostrarTodos(); | |||
| } | |||
| public Collection<Animal> buscarcolor(String color) { | |||
| return queryService.buscarcolor(color).ejecutar(); | |||
| } | |||
| public Collection<Animal> mostrarDomesticos(String domesticos) { | |||
| return queryService.buscarDomesticos(domesticos).ejecutar(); | |||
| } | |||
| } | |||
| @ -0,0 +1,6 @@ | |||
| ID;NOMBRE;TIPO;HABITAT;PROMEDIO VIDA;COLOR;DOMESTICO | |||
| 1;Elefante;Herbívoro;Sabana / Selva tropical ;33;Gris claro / Gris oscuro;Si | |||
| 2;Girafa;Herbívoro;Sabana ;20;Esmoquin;No | |||
| 3;Pingüino;Carnívoros;Glaciares;15;;Si | |||
| 4;Dragon de comodo;Carnívoros;Sabanas / Bosques Tropicales;50;Verde / Negro;No | |||
| 5;Gaviota;Carnívoros;Mar / Costas;12;Blanco / Grisas;Si | |||
| @ -0,0 +1,5 @@ | |||
| Manifest-Version: 1.0 | |||
| Built-By: Dani | |||
| Build-Jdk: 17.0.4 | |||
| Created-By: Maven Integration for Eclipse | |||
| @ -0,0 +1,7 @@ | |||
| #Generated by Maven Integration for Eclipse | |||
| #Sun Nov 27 23:01:03 CET 2022 | |||
| m2e.projectLocation=C\:\\Users\\Dani\\Downloads\\AnimalAdvisor\\AnimalAdvisor | |||
| m2e.projectName=AnimalAdvisor | |||
| groupId=com.kevinsignes | |||
| artifactId=AnimalAdvisor | |||
| version=0.0.1-SNAPSHOT | |||
| @ -0,0 +1,22 @@ | |||
| <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>com.kevinsignes</groupId> | |||
| <artifactId>AnimalAdvisor</artifactId> | |||
| <version>0.0.1-SNAPSHOT</version> | |||
| <name>AnimalAdvisor</name> | |||
| <description>Actividad Juanjito Springcore</description> | |||
| <dependencies> | |||
| <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> | |||
| <dependency> | |||
| <groupId>org.springframework</groupId> | |||
| <artifactId>spring-context</artifactId> | |||
| <version>6.0.0</version> | |||
| </dependency> | |||
| <!--https://www.baeldung.com/spring-postconstruct-predestroy --> | |||
| <dependency> | |||
| <groupId>javax.annotation</groupId> | |||
| <artifactId>javax.annotation-api</artifactId> | |||
| <version>1.3.2</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @ -0,0 +1,6 @@ | |||
| ID;NOMBRE;TIPO;HABITAT;PROMEDIO VIDA;COLOR;DOMESTICO | |||
| 1;Elefante;Herbívoro;Sabana / Selva tropical ;33;Gris claro / Gris oscuro;Si | |||
| 2;Girafa;Herbívoro;Sabana ;20;Esmoquin;No | |||
| 3;Pingüino;Carnívoros;Glaciares;15;;Si | |||
| 4;Dragon de comodo;Carnívoros;Sabanas / Bosques Tropicales;50;Verde / Negro;No | |||
| 5;Gaviota;Carnívoros;Mar / Costas;12;Blanco / Grisas;Si | |||