Commit 589c458c authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-179-filter-for-accessions-with-images' into 'master'

Ui 179 filter for accessions with images

See merge request genesys-pgr/genesys-server!329
parents cc79bc31 9c6ad612
......@@ -239,6 +239,21 @@ public class AccessionController {
return accessionService.getAccessionDetails(accession);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/auditlog/10.{doi1:[0-9]+}/{doi2:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView(JsonViews.Root.class)
public AccessionService.AccessionAuditLog getAccessionAuditLogByDoi(@PathVariable("doi1") String doi1, @PathVariable("doi2") String doi2) {
Accession accession = accessionService.getByDoi("10." + doi1 + "/" + doi2);
return accessionService.getAuditLog(accession);
}
@PreAuthorize("isAuthenticated()")
@GetMapping(value = "/auditlog/{uuid:\\w{8}\\-\\w{4}.+}", produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView(JsonViews.Root.class)
public AccessionService.AccessionAuditLog getAccessionAuditLogByUUID(@PathVariable("uuid") final UUID uuid) {
Accession accession = accessionService.getByUuid(uuid);
return accessionService.getAuditLog(accession);
}
@PostMapping(value = "/mapinfo", produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView({ JsonViews.Public.class })
......
......@@ -27,6 +27,7 @@ import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
......@@ -65,7 +66,8 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "acce")
@Table(name = "acce", indexes = {
@Index(name = "IX_imageCount", columnList = "imageCount") })
@Audited
public class AccessionId extends AuditedVersionedModel implements IdUUID {
......
......@@ -616,6 +616,13 @@ public class AdminController {
if (accession != null) {
LOG.warn("Folder for accession {}:{} is {}", instCode, accession.getAccessionNumber(), acceFolder.getPath());
accession.getAccessionId().setRepositoryFolder(acceFolder);
{
// Get number of images in the gallery
ImageGallery gallery = acceFolder.getGallery();
if (gallery != null) {
accession.getAccessionId().setImageCount(gallery.getImages().size());
}
}
accessionIdRepository.save(accession.getAccessionId());
} else {
LOG.warn("No accession {}:{} for folder {}", instCode, acceFolder.getName(), acceFolder.getPath());
......
......@@ -30,6 +30,7 @@ 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;
import org.genesys.blocks.auditlog.model.AuditLog;
public interface AccessionService {
......@@ -85,6 +86,14 @@ public interface AccessionService {
*/
AccessionDetails getAccessionDetails(Accession accession);
/**
* Gets accession audit log, requires authentication
*
* @param accession the accession
* @return the accession audit log
*/
AccessionAuditLog getAuditLog(Accession accession);
/**
* Get only available for distribution accessions id-s.
*
......@@ -150,4 +159,11 @@ public interface AccessionService {
public ImageGallery imageGallery;
public List<RepositoryFile> files;
}
class AccessionAuditLog {
public Map<String, List<AuditLog>> auditAccession;
public Map<String, List<AuditLog>> auditAccessionId;
public Map<String, List<AuditLog>> auditAccessionCollect;
public Map<String, List<AuditLog>> auditAccessionGeo;
}
}
......@@ -35,6 +35,8 @@ import com.querydsl.core.types.Predicate;
*/
public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> implements Serializable {
private static final long serialVersionUID = -1441103961567816877L;
/** The historic. */
public Boolean historic;
......@@ -94,6 +96,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** accession aliases */
public StringFilter alias;
/** accessions with images */
public Boolean images;
/* (non-Javadoc)
......@@ -178,9 +183,19 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
}
// TODO Do we have to change this?
if (sgsv != null) {
and.and(accession.accessionId.duplSite.any().eq("NOR051"));
if (sgsv == Boolean.TRUE) {
and.and(accession.accessionId.duplSite.any().eq("NOR051"));
} else {
and.andNot(accession.accessionId.duplSite.any().eq("NOR051"));
}
}
if (images != null) {
if (images == Boolean.TRUE) {
and.and(accession.accessionId.imageCount.gt(0));
} else {
and.and(accession.accessionId.imageCount.eq(0));
}
}
return and;
}
......
......@@ -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,14 +27,13 @@ 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;
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;
......@@ -57,6 +55,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -96,7 +95,7 @@ public class AccessionServiceImpl implements AccessionService {
private ImageGalleryService imageGalleryService;
@Autowired
private RepositoryService repositoryService;
private AuditTrailService auditService;
private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) {
......@@ -150,42 +149,47 @@ public class AccessionServiceImpl implements AccessionService {
@Override
public AccessionDetails getAccessionDetails(Accession accession) {
if (accession == null) {
throw new ResourceNotFoundException();
}
if (accession == null) {
throw new ResourceNotFoundException();
}
accession = accessionRepository.findOneByUuid(accession.getUuid());
List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession);
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;
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 = accession.getAccessionId().getRepositoryFolder();
if (folder != null) {
accessionDetails.files = folder.getFiles().stream().filter((file) -> !file.getContentType().contains("image/")).collect(Collectors.toList());
ImageGallery imageGallery = imageGalleryService.getImageGallery(folder);
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
accessionDetails.imageGallery = imageGallery;
}
}
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());
return accessionDetails;
}
ImageGallery imageGallery = imageGalleryService.loadImageGallery(folder.getFolderPath());
if (imageGallery != null) {
if (imageGallery.getImages() != null) {
imageGallery.getImages().size();
}
accessionDetails.imageGallery = imageGallery;
}
@Override
@PreAuthorize("isAuthenticated()")
public AccessionAuditLog getAuditLog(Accession accession) {
AccessionAuditLog auditLog = new AccessionAuditLog();
}
} catch (InvalidRepositoryPathException e) {
LOG.warn("Error loading files folder for accession={}. {}", accession.getAccessionNumber(), e.getMessage());
}
auditLog.auditAccession = auditService.auditLogs(accession);
auditLog.auditAccessionId = auditService.auditLogs(accession.getAccessionId());
auditLog.auditAccessionCollect = auditService.auditLogs(accession.getAccessionId().getColl());
auditLog.auditAccessionGeo = auditService.auditLogs(accession.getAccessionId().getGeo());
return accessionDetails;
return auditLog;
}
@Override
......
......@@ -4761,3 +4761,15 @@ databaseChangeLog:
columnNames: folderId
constraintName: UK_3x3s9vul09xif4y29o2rwx939
tableName: acce
- changeSet:
id: 1547568102000-1
author: mobreza
comment: Add index on acce#imageCount
changes:
- createIndex:
columns:
- column:
name: imageCount
indexName: IX_imageCount
tableName: acce
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