Browse Source

Clases

master
Cristobal Bernal Mayordomo 2 years ago
parent
commit
19d6b4f075
3 changed files with 130 additions and 0 deletions
  1. +32
    -0
      src/main/java/com/cristobalbernal/loladvisor/LolAdvisorHelp.java
  2. +86
    -0
      src/main/java/com/cristobalbernal/loladvisor/LolAdvisorRunApp.java
  3. +12
    -0
      src/main/java/com/cristobalbernal/loladvisor/dao/LolDao.java

+ 32
- 0
src/main/java/com/cristobalbernal/loladvisor/LolAdvisorHelp.java View File

@ -0,0 +1,32 @@
package com.cristobalbernal.loladvisor;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
@Component
public class LolAdvisorHelp {
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;
}
}

+ 86
- 0
src/main/java/com/cristobalbernal/loladvisor/LolAdvisorRunApp.java View File

@ -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");
}
}
}
}
}

+ 12
- 0
src/main/java/com/cristobalbernal/loladvisor/dao/LolDao.java View File

@ -0,0 +1,12 @@
package com.cristobalbernal.loladvisor.dao;
import com.cristobalbernal.loladvisor.model.Lol;
import java.util.Collection;
public interface LolDao {
public Lol findById(long id);
public Collection<Lol> findAll();
public void insert(Lol videogame);
public void edit(Lol videogame);
public void delete(long id);
}

Loading…
Cancel
Save