Commit 6fad525c authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Merge branch 'ui-339-browse-filtered-accession-images' into 'master'

Added api endpoint to fetch accessions with images

See merge request genesys-pgr/genesys-server!410
parents 2ed3df6a 60a35434
......@@ -30,7 +30,6 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
......@@ -69,6 +68,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
......@@ -188,7 +188,35 @@ public class AccessionController {
filterCode = shortFilterService.getCode(filter);
}
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.list(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "seqNo")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.list(filterInfo.filter, page.toPageRequest(25, Sort.Direction.ASC, "seqNo")));
}
/**
* List accessions by filterCode or filter
*
* @param page the page
* @param filterCode short filter code
* @param filter the filter
* @return the page
* @throws IOException
* @throws SearchException
*/
@JsonView({ JsonViews.Root.class }) // same as getAccessionDetails
@PostMapping(value = "/images", produces = { MediaType.APPLICATION_JSON_VALUE })
public AccessionSuggestionPage<AccessionService.AccessionDetails> images(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, AccessionFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
FilteredPage<AccessionService.AccessionDetails> pageRes = new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.withImages(filterInfo.filter, page.toPageRequest(20, Sort.Direction.ASC, "seqNo")));
filter.images = true;
Map<String, TermResult> suggestionRes = accessionService.getSuggestions(filter);
return new AccessionSuggestionPage<>(pageRes, suggestionRes);
}
......@@ -202,8 +230,8 @@ public class AccessionController {
* @throws IOException
*/
@PostMapping(value = "/filter", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Public.class })
public AccessionSuggestionPage listSuggestions(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@JsonView({ JsonViews.Internal.class })
public AccessionSuggestionPage<Accession> listSuggestions(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException, SearchException {
if (filterCode != null) {
......@@ -213,10 +241,10 @@ public class AccessionController {
}
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
FilteredPage<Accession> pageRes = new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.list(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "seqNo")));
FilteredPage<Accession> pageRes = new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.list(filterInfo.filter, page.toPageRequest(25, Sort.Direction.ASC, "seqNo")));
Map<String, TermResult> suggestionRes = accessionService.getSuggestions(filter);
return AccessionSuggestionPage.from(pageRes, suggestionRes);
return new AccessionSuggestionPage<Accession>(pageRes, suggestionRes);
}
/**
......@@ -564,17 +592,14 @@ public class AccessionController {
}
}
public static class AccessionSuggestionPage {
public static class AccessionSuggestionPage<T> {
@JsonUnwrapped
public FilteredPage<Accession> page;
public FilteredPage<T> page;
public Map<String, TermResult> suggestions;
private static AccessionSuggestionPage from(FilteredPage<Accession> page, Map<String, TermResult> suggestions) {
AccessionSuggestionPage res = new AccessionSuggestionPage();
res.page = page;
res.suggestions = suggestions;
return res;
public AccessionSuggestionPage(FilteredPage<T> page, Map<String, TermResult> suggestions) {
this.page = page;
this.suggestions = suggestions;
}
}
......
......@@ -98,6 +98,15 @@ public interface AccessionService {
*/
Page<Accession> list(AccessionFilter filter, Pageable page);
/**
* List accessions with images by filter
*
* @param filter the filter
* @param page the page
* @return the page
*/
Page<AccessionDetails> withImages(AccessionFilter filter, Pageable page);
/**
* Filtering autocompleter with suggestions
*
......@@ -197,7 +206,7 @@ public interface AccessionService {
}
public static interface IAccessionBatchAction extends IBatchAction<Accession> {
}
class AccessionDetails {
......
......@@ -382,6 +382,37 @@ public class AccessionServiceImpl implements AccessionService {
return new PageImpl<>(content, page, total);
}
@Override
public Page<AccessionDetails> withImages(AccessionFilter filter, Pageable page) {
filter.images = true;
List<Accession> content = accessionRepository.findAll(filter, page);
content.forEach(accession -> lazyLoad(accession));
List<AccessionDetails> contentWithImages = new ArrayList<>(content.size());
for (Accession accession : content) {
AccessionDetails details = new AccessionDetails();
details.details = accession;
RepositoryFolder folder = accession.getAccessionId().getRepositoryFolder();
ImageGallery imageGallery = imageGalleryService.getImageGallery(folder);
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
details.imageGallery = imageGallery;
}
contentWithImages.add(details);
}
long total = countAccessions(filter);
return new PageImpl<>(contentWithImages, page, total);
}
@Override
public List<LabelValue<String>> autocomplete(AccessionFilter filter, String field, String text) throws IOException {
AccessionFilter suggestionFilter = filter.copy(AccessionFilter.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment