Commit bcfa454d authored by Matija Obreza's avatar Matija Obreza

AccessionService: use AccessionId#repositoryFolder instead of folder lookups by name

parent 942f1658
......@@ -15,7 +15,6 @@
*/
package org.genesys2.server.service.impl;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
......@@ -28,7 +27,6 @@ import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
......@@ -36,7 +34,6 @@ 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.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
......@@ -97,9 +94,6 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private ImageGalleryService imageGalleryService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private AuditTrailService auditService;
......@@ -155,42 +149,34 @@ public class AccessionServiceImpl implements AccessionService {
@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;
if (accession == null) {
throw new ResourceNotFoundException();
}
accession = accessionRepository.findOneByUuid(accession.getUuid());
try {
if (StringUtils.contains(accession.getAccessionNumber(), "/")) {
throw new InvalidRepositoryPathException("AccessionNumber contains /, cannot load folder for " + accession.getAccessionNumber());
}
List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession);
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());
AccessionDetails accessionDetails = new AccessionDetails();
accessionDetails.details = accession;
accessionDetails.pdci = accession.getAccessionId().getPdci();
accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets;
ImageGallery imageGallery = imageGalleryService.loadImageGallery(folder.getFolderPath());
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
accessionDetails.imageGallery = imageGallery;
}
RepositoryFolder folder = accession.getAccessionId().getRepositoryFolder();
if (folder != null) {
accessionDetails.files = folder.getFiles().stream().filter((file) -> !file.getContentType().contains("image/")).collect(Collectors.toList());
ImageGallery imageGallery = imageGalleryService.loadImageGallery(folder);
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
} catch (InvalidRepositoryPathException e) {
LOG.warn("Error loading files folder for accession={}. {}", accession.getAccessionNumber(), e.getMessage());
accessionDetails.imageGallery = imageGallery;
}
}
return accessionDetails;
return accessionDetails;
}
@Override
......
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