Skip to content

Commit

Permalink
chore: Set default value to ORIGIN
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu committed Oct 18, 2024
1 parent 4c5fb1e commit a5283ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand All @@ -30,8 +28,6 @@ class InstitutionServiceImpl implements InstitutionService {
private final OpenDataRestClient openDataRestClient;
private final IndexWriterService<Institution> institutionIndexWriterService;



@Autowired
InstitutionServiceImpl(IndexSearchService<Institution> indexSearchService, OpenDataRestClient openDataRestClient, IndexWriterService<Institution> institutionIndexWriterService) {
this.openDataRestClient = openDataRestClient;
Expand All @@ -40,7 +36,6 @@ class InstitutionServiceImpl implements InstitutionService {
this.indexSearchService = indexSearchService;
}


@Override
public QueryResult<Institution> search(Optional<String> searchText, int page, int limit) {
log.trace("search start");
Expand All @@ -59,13 +54,11 @@ public QueryResult<Institution> search(Optional<String> searchText, String categ
final QueryResult<Institution> queryResult = searchText.map(text -> indexSearchService.fullTextSearch(Field.DESCRIPTION, searchText.orElseThrow(), Field.CATEGORY, categories, page, limit))
.orElseGet(() -> indexSearchService.findAll(page, limit, Entity.INSTITUTION.toString()));


log.debug("search result = {}", queryResult);
log.trace("search end");
return queryResult;
}


@Override
public Institution findById(String id, Optional<Origin> origin, List<String> categories) {
log.trace("findById start");
Expand All @@ -75,15 +68,13 @@ public Institution findById(String id, Optional<Origin> origin, List<String> cat
} else {
final Supplier<List<Institution>> institutionsSupplier = () -> indexSearchService.findById(Field.ID, id);
List<Institution> institutions;
if (origin.isPresent()) {
Origin orig = origin.get();
institutions = institutionsSupplier.get().stream()
.filter(institution -> institution.getOrigin().equals(orig) &&
(categories.isEmpty() || categories.contains(institution.getCategory())))
.collect(Collectors.toList());
} else {
institutions = !categories.isEmpty() ? new ArrayList<>() : institutionsSupplier.get();
}

Origin orig = origin.get();
institutions = institutionsSupplier.get().stream()
.filter(institution -> institution.getOrigin().equals(orig) &&
(categories.isEmpty() || categories.contains(institution.getCategory())))
.toList();

if (institutions.isEmpty()) {
throw new ResourceNotFoundException();
} else if (institutions.size() > 1) {
Expand Down Expand Up @@ -125,6 +116,4 @@ private List<Institution> getInstitutions() {
log.trace("getInstitutions end");
return institutions;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public InstitutionResource findInstitution(@ApiParam("${swagger.api.institution.
if (categories.isPresent()) {
categoriesList = Arrays.stream(categories.get().split(",")).collect(Collectors.toList());
}
final InstitutionResource institutionResource = InstitutionMapper.toResource(institutionService.findById(id, origin, categoriesList));
final InstitutionResource institutionResource = InstitutionMapper.toResource(institutionService.findById(id,
origin.isEmpty() ? Optional.of(Origin.IPA) : origin, categoriesList));

log.debug("findInstitution result = {}", institutionResource);
log.trace("findInstitution end");
Expand Down

0 comments on commit a5283ad

Please sign in to comment.