| @ -0,0 +1,22 @@ | |||
| package com.antoniofrische.perifericosAdvisor; | |||
| import com.antoniofrische.perifericosAdvisor.config.AppConfig; | |||
| import org.springframework.context.ApplicationContext; | |||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |||
| public class MovieAdvisorApp { | |||
| public static void main(String[] args) { | |||
| ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class); | |||
| MovieAdvisorRunApp runApp = appContext.getBean(MovieAdvisorRunApp.class); | |||
| runApp.run(args); | |||
| ((AnnotationConfigApplicationContext) appContext).close(); | |||
| } | |||
| } | |||
| @ -0,0 +1,36 @@ | |||
| package com.antoniofrische.perifericosAdvisor; | |||
| import java.io.IOException; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Paths; | |||
| import java.util.stream.Collectors; | |||
| import org.springframework.stereotype.Component; | |||
| import org.springframework.util.ResourceUtils; | |||
| @Component | |||
| public class MovieAdvisorHelp { | |||
| private String help; | |||
| 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 e) { | |||
| System.err.println("Error cargando el texto de ayuda"); | |||
| System.exit(-1); | |||
| } | |||
| } | |||
| public String getHelp() { | |||
| return help; | |||
| } | |||
| } | |||
| @ -0,0 +1,97 @@ | |||
| package com.antoniofrische.perifericosAdvisor; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| import com.antoniofrische.perifericosAdvisor.model.Periferico; | |||
| import com.antoniofrische.perifericosAdvisor.service.PerifericoQueryService; | |||
| import com.antoniofrische.perifericosAdvisor.service.PerifericoService; | |||
| @Component | |||
| public class MovieAdvisorRunApp { | |||
| @Autowired | |||
| PerifericoService perifericoService; | |||
| @Autowired | |||
| PerifericoQueryService perifericoQueryService; | |||
| @Autowired | |||
| MovieAdvisorHelp help; | |||
| public void run(String[] args) { | |||
| if (args.length < 1) { | |||
| System.out.println("Error de sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } else if (args.length == 1) { | |||
| switch (args[0].toLowerCase()) { | |||
| case "-lg": | |||
| perifericoService.findAllTipo().forEach(System.out::println); | |||
| break; | |||
| case "-h": | |||
| System.out.println(help.getHelp()); | |||
| break; | |||
| default: | |||
| System.out.println("Error de sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } | |||
| } else if (args.length % 2 != 0) { | |||
| System.out.println("Error de sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } else if (args.length > 8) { | |||
| System.out.println("Error de sintaxis"); | |||
| 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 "-at": | |||
| perifericoQueryService.anyTipo(argumento[1].split(",")); | |||
| break; | |||
| case "-tt": | |||
| perifericoQueryService.allTipo(argumento[1].split(",")); | |||
| break; | |||
| case "-c": | |||
| perifericoQueryService.color(null); | |||
| break; | |||
| case "-t": | |||
| perifericoQueryService.titleContains(argumento[1]); | |||
| break; | |||
| default: error = true; | |||
| System.out.println("Error de sintaxis"); | |||
| System.out.println(help.getHelp()); | |||
| } | |||
| } | |||
| if (!error) { | |||
| Collection<Periferico> result = perifericoQueryService.exec(); | |||
| System.out.printf("%s\t%-50s\t%s\t%s\n","ID","Título", "Año", "Géneros"); | |||
| if (result != null) { | |||
| result.forEach(f -> System.out.printf("%s\t%-50s\t%s\t%s\n", | |||
| f.getId(), f.getNombre(), f.getColor(), | |||
| f.getTipo().strip().collect(Collectors.joining(", ")))); | |||
| } else { | |||
| System.out.println("No hay películas que cumplan esos criterios. Lo sentimos"); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,7 @@ | |||
| #Generated by Maven Integration for Eclipse | |||
| #Sat Nov 26 12:43:06 CET 2022 | |||
| m2e.projectLocation=C\:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\SpringTool_4\\SpringWorkspace\\perifericosAdvisor | |||
| m2e.projectName=perifericosAdvisor | |||
| groupId=com.antoniofrische | |||
| artifactId=19-MovieAdvisor | |||
| 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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>com.antoniofrische</groupId> | |||
| <artifactId>19-MovieAdvisor</artifactId> | |||
| <version>0.0.1-SNAPSHOT</version> | |||
| <name>19-MovieAdvisor</name> | |||
| <description>Ejemplo que integra todos los conocimientos del curso de Spring.</description> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>org.springframework</groupId> | |||
| <artifactId>spring-context</artifactId> | |||
| <version>5.0.8.RELEASE</version> | |||
| </dependency> | |||
| </dependencies> | |||
| <properties> | |||
| <maven.compiler.source>1.8</maven.compiler.source> | |||
| <maven.compiler.target>1.8</maven.compiler.target> | |||
| </properties> | |||
| </project> | |||
| @ -0,0 +1,7 @@ | |||
| #Generated by Maven Integration for Eclipse | |||
| #Sat Nov 26 12:43:18 CET 2022 | |||
| m2e.projectLocation=C\:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\SpringTool_4\\SpringWorkspace\\perifericosAdvisor | |||
| m2e.projectName=perifericosAdvisor | |||
| groupId=com.antoniofrische | |||
| artifactId=PerifericoAdvisor | |||
| 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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>com.antoniofrische</groupId> | |||
| <artifactId>PerifericoAdvisor</artifactId> | |||
| <version>0.0.1-SNAPSHOT</version> | |||
| <name>19-MovieAdvisor</name> | |||
| <description>Ejemplo que integra todos los conocimientos del curso de Spring.</description> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>org.springframework</groupId> | |||
| <artifactId>spring-context</artifactId> | |||
| <version>5.0.8.RELEASE</version> | |||
| </dependency> | |||
| </dependencies> | |||
| <properties> | |||
| <maven.compiler.source>1.8</maven.compiler.source> | |||
| <maven.compiler.target>1.8</maven.compiler.target> | |||
| </properties> | |||
| </project> | |||