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 { ...@@ -239,6 +239,21 @@ public class AccessionController {
return accessionService.getAccessionDetails(accession); 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) @PostMapping(value = "/mapinfo", produces = MediaType.APPLICATION_JSON_VALUE)
@JsonView({ JsonViews.Public.class }) @JsonView({ JsonViews.Public.class })
......
...@@ -27,6 +27,7 @@ import javax.persistence.Column; ...@@ -27,6 +27,7 @@ import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
...@@ -65,7 +66,8 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators; ...@@ -65,7 +66,8 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
*/ */
@Entity @Entity
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "acce") @Table(name = "acce", indexes = {
@Index(name = "IX_imageCount", columnList = "imageCount") })
@Audited @Audited
public class AccessionId extends AuditedVersionedModel implements IdUUID { public class AccessionId extends AuditedVersionedModel implements IdUUID {
......
...@@ -616,6 +616,13 @@ public class AdminController { ...@@ -616,6 +616,13 @@ public class AdminController {
if (accession != null) { if (accession != null) {
LOG.warn("Folder for accession {}:{} is {}", instCode, accession.getAccessionNumber(), acceFolder.getPath()); LOG.warn("Folder for accession {}:{} is {}", instCode, accession.getAccessionNumber(), acceFolder.getPath());
accession.getAccessionId().setRepositoryFolder(acceFolder); 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()); accessionIdRepository.save(accession.getAccessionId());
} else { } else {
LOG.warn("No accession {}:{} for folder {}", instCode, acceFolder.getName(), acceFolder.getPath()); LOG.warn("No accession {}:{} for folder {}", instCode, acceFolder.getName(), acceFolder.getPath());
......
...@@ -30,6 +30,7 @@ import org.genesys2.server.model.impl.Subset; ...@@ -30,6 +30,7 @@ import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.filter.AccessionFilter; import org.genesys2.server.service.filter.AccessionFilter;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.genesys.blocks.auditlog.model.AuditLog;
public interface AccessionService { public interface AccessionService {
...@@ -85,6 +86,14 @@ public interface AccessionService { ...@@ -85,6 +86,14 @@ public interface AccessionService {
*/ */
AccessionDetails getAccessionDetails(Accession accession); 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. * Get only available for distribution accessions id-s.
* *
...@@ -150,4 +159,11 @@ public interface AccessionService { ...@@ -150,4 +159,11 @@ public interface AccessionService {
public ImageGallery imageGallery; public ImageGallery imageGallery;
public List<RepositoryFile> files; 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; ...@@ -35,6 +35,8 @@ import com.querydsl.core.types.Predicate;
*/ */
public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> implements Serializable { public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> implements Serializable {
private static final long serialVersionUID = -1441103961567816877L;
/** The historic. */ /** The historic. */
public Boolean historic; public Boolean historic;
...@@ -94,6 +96,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -94,6 +96,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** accession aliases */ /** accession aliases */
public StringFilter alias; public StringFilter alias;
/** accessions with images */
public Boolean images;
/* (non-Javadoc) /* (non-Javadoc)
...@@ -178,9 +183,19 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -178,9 +183,19 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
} }
// TODO Do we have to change this? // TODO Do we have to change this?
if (sgsv != null) { 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; return and;
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.genesys2.server.service.impl; package org.genesys2.server.service.impl;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -28,14 +27,13 @@ import java.util.UUID; ...@@ -28,14 +27,13 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils; 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.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService; import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.InvalidRepositoryPathException; import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery; import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder; import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService; import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData; import org.genesys2.server.model.genesys.AccessionData;
...@@ -57,6 +55,7 @@ import org.springframework.context.annotation.Lazy; ...@@ -57,6 +55,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -96,7 +95,7 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -96,7 +95,7 @@ public class AccessionServiceImpl implements AccessionService {
private ImageGalleryService imageGalleryService; private ImageGalleryService imageGalleryService;
@Autowired @Autowired
private RepositoryService repositoryService; private AuditTrailService auditService;
private <T extends AccessionData> T lazyLoad(T accession) { private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) { if (accession != null) {
...@@ -150,42 +149,47 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -150,42 +149,47 @@ public class AccessionServiceImpl implements AccessionService {
@Override @Override
public AccessionDetails getAccessionDetails(Accession accession) { public AccessionDetails getAccessionDetails(Accession accession) {
if (accession == null) { if (accession == null) {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
accession = accessionRepository.findOneByUuid(accession.getUuid());
List<Dataset> datasets = datasetService.listByAccession(accession); List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession); List<Subset> subsets = subsetService.listByAccession(accession);
AccessionDetails accessionDetails = new AccessionDetails(); AccessionDetails accessionDetails = new AccessionDetails();
accessionDetails.details = accession; accessionDetails.details = accession;
accessionDetails.pdci = accession.getAccessionId().getPdci(); accessionDetails.pdci = accession.getAccessionId().getPdci();
accessionDetails.datasets = datasets; accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets; accessionDetails.subsets = subsets;
try { RepositoryFolder folder = accession.getAccessionId().getRepositoryFolder();
if (StringUtils.contains(accession.getAccessionNumber(), "/")) { if (folder != null) {
throw new InvalidRepositoryPathException("AccessionNumber contains /, cannot load folder for " + accession.getAccessionNumber()); 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())); return accessionDetails;
if (folder != null) { }
accessionDetails.files = folder.getFiles().stream().filter((file) -> !file.getContentType().contains("image/")).collect(Collectors.toList());
ImageGallery imageGallery = imageGalleryService.loadImageGallery(folder.getFolderPath()); @Override
if (imageGallery != null) { @PreAuthorize("isAuthenticated()")
if (imageGallery.getImages() != null) { public AccessionAuditLog getAuditLog(Accession accession) {
imageGallery.getImages().size(); AccessionAuditLog auditLog = new AccessionAuditLog();
}
accessionDetails.imageGallery = imageGallery;
}
} auditLog.auditAccession = auditService.auditLogs(accession);
} catch (InvalidRepositoryPathException e) { auditLog.auditAccessionId = auditService.auditLogs(accession.getAccessionId());
LOG.warn("Error loading files folder for accession={}. {}", accession.getAccessionNumber(), e.getMessage()); auditLog.auditAccessionCollect = auditService.auditLogs(accession.getAccessionId().getColl());
} auditLog.auditAccessionGeo = auditService.auditLogs(accession.getAccessionId().getGeo());
return accessionDetails; return auditLog;
} }
@Override @Override
......
...@@ -4761,3 +4761,15 @@ databaseChangeLog: ...@@ -4761,3 +4761,15 @@ databaseChangeLog:
columnNames: folderId columnNames: folderId
constraintName: UK_3x3s9vul09xif4y29o2rwx939 constraintName: UK_3x3s9vul09xif4y29o2rwx939
tableName: acce 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