Browse Source

implment de servicios

master
AntonioFrische 2 years ago
parent
commit
0b6855ad8a
10 changed files with 142 additions and 3 deletions
  1. +19
    -0
      src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoQueryService.java
  2. +62
    -0
      src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoQueryServiceImpl.java
  3. +60
    -0
      src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoService.java
  4. +1
    -1
      src/main/java/com/antoniofrische/perifericosAdvisor/config/AppConfig.java
  5. +0
    -2
      src/main/java/com/antoniofrische/perifericosAdvisor/dao/PerifericoDaoImplMemory.java
  6. BIN
      target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoQueryService.class
  7. BIN
      target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoQueryServiceImpl.class
  8. BIN
      target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoService.class
  9. BIN
      target/classes/com/antoniofrische/perifericosAdvisor/config/AppConfig.class
  10. BIN
      target/classes/com/antoniofrische/perifericosAdvisor/dao/PerifericoDaoImplMemory.class

+ 19
- 0
src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoQueryService.java View File

@ -0,0 +1,19 @@
package com.antoniofrische.perifericoadvisor.service;
import java.util.Collection;
import com.antoniofrische.perifericosAdvisor.model.Periferico;
public interface PerifericoQueryService {
public Collection<Periferico> exec();
public PerifericoQueryService anyTipo(String... tipo);
public PerifericoQueryService allTipo(String... tipo);
public PerifericoQueryService color(String color);
public PerifericoQueryService titleContains(String nombre);
}

+ 62
- 0
src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoQueryServiceImpl.java View File

@ -0,0 +1,62 @@
package com.antoniofrische.perifericoadvisor.service;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.antoniofrische.perifericosAdvisor.dao.PerifericoDao;
import com.antoniofrische.perifericosAdvisor.model.Periferico;
@Service
public class PerifericoQueryServiceImpl implements PerifericoQueryService{
@Autowired
PerifericoDao dao;
private Predicate<Periferico> predicate;
public void init() {
predicate = null;
}
public Collection<Periferico> exec() {
// @formatter:off
return dao.findAll()
.stream()
.filter(predicate)
.collect(Collectors.toList());
// @formatter:on
}
public PerifericoQueryServiceImpl anyTipo(String... tipo) {
Predicate<Periferico> pAnyTipo = (periferico -> Arrays.stream(tipo).anyMatch(periferico.getTipo()::contains));
predicate = (predicate == null) ? pAnyTipo : predicate.and(pAnyTipo);
return this;
}
public PerifericoQueryServiceImpl allTipo(String... genres) {
Predicate<Periferico> pAllGenres = (periferico -> Arrays.stream(genres).allMatch(periferico.getTipo()::contains));
predicate = (predicate == null) ? pAllGenres : predicate.and(pAllGenres);
return this;
}
public PerifericoQueryServiceImpl color(String color) {
Predicate<Periferico> pYear = (periferico -> periferico.getColor().equalsIgnoreCase(color));
predicate = (predicate == null) ? pYear : predicate.and(pYear);
return this;
}
public PerifericoQueryServiceImpl titleContains(String nombre) {
Predicate<Periferico> pTitleContains = (periferico -> periferico.getNombre().toLowerCase().contains(nombre.toLowerCase()));
predicate = (predicate == null) ? pTitleContains : predicate.and(pTitleContains);
return this;
}
}

+ 60
- 0
src/main/java/com/antoniofrische/perifericoadvisor/service/PerifericoService.java View File

@ -0,0 +1,60 @@
package com.antoniofrische.perifericoadvisor.service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.antoniofrische.perifericosAdvisor.dao.PerifericoDao;
import com.antoniofrische.perifericosAdvisor.model.Periferico;
@Service
public class PerifericoService {
@Autowired
PerifericoDao perifericoDao;
@Autowired
PerifericoQueryService queryService;
public Collection<String> findAllTipo() {
List<String> result = null;
// @formatter:off
result = (List<String>) perifericoDao.findAll()
.stream()
.map(p -> p.getTipo())
.flatMap(lista -> lista.stream()
.distinct()
.sorted()
.collect(Collectors.toList()));
// @formatter:on
return result;
}
public Collection<Periferico> findByAnyGenre(String... tipo) {
return queryService.anyTipo(tipo).exec();
}
public Collection<Periferico> findByAllGenres(String... tipo) {
return queryService.allTipo(tipo).exec();
}
public Collection<Periferico> findByColor(String color) {
return queryService.color(color).exec();
}
public Collection<Periferico> findByTitleContains(String nombre) {
return queryService.titleContains(nombre).exec();
}
public Collection<Periferico> findAll() {
return perifericoDao.findAll();
}
}

+ 1
- 1
src/main/java/com/antoniofrische/perifericosAdvisor/config/AppConfig.java View File

@ -9,7 +9,7 @@ import org.springframework.context.annotation.PropertySource;
@Configuration @Configuration
@ComponentScan(basePackages="com.antoniofrische.perifericosAdvisor") @ComponentScan(basePackages="com.antoniofrische.perifericosAdvisor")
@PropertySource("classpath:/movieadvisor.properties")
@PropertySource("classpath:/perifericoadvisor.properties")
public class AppConfig { public class AppConfig {
@Value("${file.path}") @Value("${file.path}")


+ 0
- 2
src/main/java/com/antoniofrische/perifericosAdvisor/dao/PerifericoDaoImplMemory.java View File

@ -5,7 +5,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -21,7 +20,6 @@ public class PerifericoDaoImplMemory implements PerifericoDao {
@Autowired @Autowired
private AppConfig appConfig; private AppConfig appConfig;
@PostConstruct
public void init() { public void init() {
perifericos = UtilPerifericoFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator()); perifericos = UtilPerifericoFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator());
} }


BIN
target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoQueryService.class View File


BIN
target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoQueryServiceImpl.class View File


BIN
target/classes/com/antoniofrische/perifericoadvisor/service/PerifericoService.class View File


BIN
target/classes/com/antoniofrische/perifericosAdvisor/config/AppConfig.class View File


BIN
target/classes/com/antoniofrische/perifericosAdvisor/dao/PerifericoDaoImplMemory.class View File


Loading…
Cancel
Save