|
|
@ -0,0 +1,86 @@ |
|
|
|
package com.cristobalbernal.loladvisor; |
|
|
|
import com.cristobalbernal.loladvisor.model.Lol; |
|
|
|
import com.cristobalbernal.loladvisor.service.LolQueryService; |
|
|
|
import com.cristobalbernal.loladvisor.service.LolService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Component |
|
|
|
public class LolAdvisorRunApp { |
|
|
|
@Autowired |
|
|
|
private LolService videogameService; |
|
|
|
@Autowired |
|
|
|
private LolQueryService lolQueryService; |
|
|
|
@Autowired |
|
|
|
private LolAdvisorHelp 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": |
|
|
|
videogameService.findAllRol().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 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 "-ag": |
|
|
|
lolQueryService.anyName(argumento[1].split(",")); |
|
|
|
break; |
|
|
|
case "-tg": |
|
|
|
lolQueryService.allName(argumento[1].split(",")); |
|
|
|
break; |
|
|
|
case "-t": |
|
|
|
lolQueryService.titleContains(argumento[1]); |
|
|
|
break; |
|
|
|
default: error = true; |
|
|
|
System.out.println("Error de sintaxis"); |
|
|
|
System.out.println(help.getHelp()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!error) { |
|
|
|
Collection<Lol> result = lolQueryService.exec(); |
|
|
|
System.out.printf("%s\t%-50s\t%s\t%s\n","ID","Nombre", "Rol", "Géneros"); |
|
|
|
if (result != null) { |
|
|
|
result.forEach(vg -> System.out.printf("%s\t%-50s\t%s\t%s\n", |
|
|
|
vg.getId(), vg.getNombre(), |
|
|
|
String.join(", ", vg.getRol()), |
|
|
|
vg.getGenero())); |
|
|
|
} else { |
|
|
|
System.out.println("No hay personajes que cumplan esos criterios. Lo sentimos"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |