Commit 4d84d753 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Added imageGallery and files to AccessionDetails

- fixed accession folder path
- added several checks to accession details loading (null handle, "accession number with `/`" handle)
- now accession RepositoryFolder loads before ImageGallery
- AccessionDetailsJson renamed to AccessionDetails
parent a5ef1ddd
......@@ -32,8 +32,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
......@@ -41,18 +39,14 @@ import org.genesys2.server.api.Pagination;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AccessionGeoFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.server.service.worker.AccessionProcessor;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -106,11 +100,6 @@ public class AccessionController {
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private DatasetService datasetService;
@Autowired
private SubsetService subsetService;
@Autowired
private AccessionProcessor accessionProcessor;
......@@ -220,35 +209,19 @@ public class AccessionController {
}
@RequestMapping(value = "/details/10.{doi1:[0-9]+}/{doi2:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView(JsonViews.Protected.class)
public AccessionDetailsJson getAccessionDetailsByDoi(@PathVariable("doi1") String doi1, @PathVariable("doi2") String doi2) {
@JsonView(JsonViews.Root.class)
public AccessionService.AccessionDetails getAccessionDetailsByDoi(@PathVariable("doi1") String doi1, @PathVariable("doi2") String doi2) {
Accession accession = accessionService.getByDoi("10." + doi1 + "/" + doi2);
return getAccessionDetails(accession);
return accessionService.getAccessionDetails(accession);
}
@GetMapping(value = "/details/{UUID:\\w{8}\\-\\w{4}.+}", produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView(JsonViews.Protected.class)
public AccessionDetailsJson getAccessionDetailsByUUID(@PathVariable("UUID") final UUID uuid) {
@JsonView(JsonViews.Root.class)
public AccessionService.AccessionDetails getAccessionDetailsByUUID(@PathVariable("UUID") final UUID uuid) {
Accession accession = accessionService.getByUuid(uuid);
return getAccessionDetails(accession);
return accessionService.getAccessionDetails(accession);
}
private AccessionDetailsJson getAccessionDetails(Accession accession) {
if (accession == null) {
throw new ResourceNotFoundException();
}
List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession);
AccessionDetailsJson accessionDetails = new AccessionDetailsJson();
accessionDetails.details = accession;
accessionDetails.pdci = accession.getAccessionId().getPdci();
accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets;
return accessionDetails;
}
@PostMapping(value = "/mapinfo", produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView({ JsonViews.Public.class })
......@@ -404,12 +377,6 @@ public class AccessionController {
}
}
public static class AccessionDetailsJson {
public Accession details;
public PDCI pdci;
public List<Dataset> datasets;
public List<Subset> subsets;
}
public static class AccessionMapInfo {
public String filterCode;
......
......@@ -20,8 +20,13 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.filter.AccessionFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -70,6 +75,13 @@ public interface AccessionService {
*/
Accession getByDoi(String doi);
/**
* Gets accession details
*
* @param accession the accession
* @return the accession details
*/
AccessionDetails getAccessionDetails(Accession accession);
/**
* Get only available for distribution accessions id-s.
......@@ -127,4 +139,13 @@ public interface AccessionService {
*/
List<Accession> apply(List<Accession> a) throws Exception;
}
class AccessionDetails {
public Accession details;
public PDCI pdci;
public List<Dataset> datasets;
public List<Subset> subsets;
public ImageGallery imageGallery;
public List<RepositoryFile> files;
}
}
......@@ -15,6 +15,7 @@
*/
package org.genesys2.server.service.impl;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
......@@ -24,16 +25,28 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.QAccession;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -69,6 +82,18 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private JPAQueryFactory jpaQueryFactory;
@Autowired
private DatasetService datasetService;
@Autowired
private SubsetService subsetService;
@Autowired
private ImageGalleryService imageGalleryService;
@Autowired
private RepositoryService repositoryService;
private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) {
AccessionId accessionId = accession.getAccessionId();
......@@ -119,6 +144,46 @@ public class AccessionServiceImpl implements AccessionService {
return lazyLoad(accessionRepository.findByDoi(doi));
}
@Override
public AccessionDetails getAccessionDetails(Accession accession) {
if (accession == null) {
throw new ResourceNotFoundException();
}
List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession);
AccessionDetails accessionDetails = new AccessionDetails();
accessionDetails.details = accession;
accessionDetails.pdci = accession.getAccessionId().getPdci();
accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets;
try {
if (StringUtils.contains(accession.getAccessionNumber(), "/")) {
throw new InvalidRepositoryPathException("AccessionNumber contains /, cannot load folder for " + accession.getAccessionNumber());
}
RepositoryFolder folder = repositoryService.getFolder(Paths.get("/wiews", accession.getInstCode(), "acn", accession.getAccessionNumber()));
if (folder != null) {
accessionDetails.files = folder.getFiles().stream().filter((file) -> !file.getContentType().contains("image/")).collect(Collectors.toList());
ImageGallery imageGallery = imageGalleryService.loadImageGallery(folder.getFolderPath());
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
accessionDetails.imageGallery = imageGallery;
}
}
} catch (InvalidRepositoryPathException e) {
LOG.warn("Error loading files folder for accession={}. {}", accession.getAccessionNumber(), e.getMessage());
}
return accessionDetails;
}
@Override
public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) {
Map<UUID, AccessionIdentifier3> res = new HashMap<>();
......
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