Commit 942f1658 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Added AuditLog to AccessionDetails

- AccessionAuditLog moved to separate model, added endpoint to load AccessionAuditLog by doi/uuid
parent cc79bc31
......@@ -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 })
......
......@@ -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;
}
}
......@@ -29,6 +29,7 @@ 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;
......@@ -57,6 +58,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;
......@@ -98,6 +100,9 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private RepositoryService repositoryService;
@Autowired
private AuditTrailService auditService;
private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) {
AccessionId accessionId = accession.getAccessionId();
......@@ -163,7 +168,7 @@ public class AccessionServiceImpl implements AccessionService {
accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets;
try {
try {
if (StringUtils.contains(accession.getAccessionNumber(), "/")) {
throw new InvalidRepositoryPathException("AccessionNumber contains /, cannot load folder for " + accession.getAccessionNumber());
}
......@@ -188,6 +193,19 @@ public class AccessionServiceImpl implements AccessionService {
return accessionDetails;
}
@Override
@PreAuthorize("isAuthenticated()")
public AccessionAuditLog getAuditLog(Accession accession) {
AccessionAuditLog auditLog = new AccessionAuditLog();
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 auditLog;
}
@Override
public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) {
......
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