Commit 521d6ac1 authored by Matija Obreza's avatar Matija Obreza

Display audited changes to accession data

- New taglibs: taxonName, country, display, auditlog-changes
parent d6dda6db
...@@ -25,12 +25,17 @@ import java.util.UUID; ...@@ -25,12 +25,17 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.blocks.security.SecurityContextUtil;
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.service.ImageGalleryService; import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.model.dataset.DS; import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.elastic.AccessionDetails; import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo; import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.PDCI; import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.genesys.Taxonomy2; import org.genesys2.server.model.genesys.Taxonomy2;
...@@ -52,6 +57,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -52,6 +57,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -98,6 +104,9 @@ public class AccessionController extends BaseController { ...@@ -98,6 +104,9 @@ public class AccessionController extends BaseController {
@Autowired @Autowired
private DownloadService downloadService; private DownloadService downloadService;
@Autowired
private AuditTrailService auditService;
@Value("${base.url}") @Value("${base.url}")
private String baseUrl; private String baseUrl;
...@@ -138,13 +147,31 @@ public class AccessionController extends BaseController { ...@@ -138,13 +147,31 @@ public class AccessionController extends BaseController {
*/ */
public ModelAndView displayAccession(ModelMap model, Accession accession) { public ModelAndView displayAccession(ModelMap model, Accession accession) {
model.addAttribute("accession", accession); model.addAttribute("accession", accession);
model.addAttribute("auditAccession", auditService.auditLogs(accession));
model.addAttribute("accessionNames", genesysService.listAccessionNames(accession.getAccessionId())); model.addAttribute("accessionNames", genesysService.listAccessionNames(accession.getAccessionId()));
model.addAttribute("accessionAliases", genesysService.listAccessionAliases(accession.getAccessionId())); model.addAttribute("accessionAliases", genesysService.listAccessionAliases(accession.getAccessionId()));
model.addAttribute("accessionExchange", genesysService.listAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.listAccessionCollect(accession.getAccessionId())); AccessionExchange accessionExchange = genesysService.getAccessionExchange(accession.getAccessionId());
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession.getAccessionId())); model.addAttribute("accessionExchange", accessionExchange);
AccessionGeo accessionGeo = genesysService.listAccessionGeo(accession.getAccessionId());
AccessionCollect accessionCollect = genesysService.getAccessionCollect(accession.getAccessionId());
model.addAttribute("accessionCollect", accessionCollect);
AccessionBreeding accessionBreeding = genesysService.getAccessionBreeding(accession.getAccessionId());
model.addAttribute("accessionBreeding", accessionBreeding);
AccessionGeo accessionGeo = genesysService.getAccessionGeo(accession.getAccessionId());
model.addAttribute("accessionGeo", accessionGeo); model.addAttribute("accessionGeo", accessionGeo);
if (SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) {
// only for authenticated users
model.addAttribute("auditAccessionExchange", auditService.auditLogs(accessionExchange));
model.addAttribute("auditAccessionCollect", auditService.auditLogs(accessionCollect));
model.addAttribute("auditAccessionBreeding", auditService.auditLogs(accessionBreeding));
model.addAttribute("auditAccessionGeo", auditService.auditLogs(accessionGeo));
}
model.addAttribute("svalbardDeposits", genesysService.getSvalbardData(accession.getAccessionId())); model.addAttribute("svalbardDeposits", genesysService.getSvalbardData(accession.getAccessionId()));
model.addAttribute("accessionRemarks", genesysService.listAccessionRemarks(accession.getAccessionId())); model.addAttribute("accessionRemarks", genesysService.listAccessionRemarks(accession.getAccessionId()));
......
...@@ -886,3 +886,5 @@ geo.country=Country: ...@@ -886,3 +886,5 @@ geo.country=Country:
article.is.template=Is template: article.is.template=Is template:
article.template.false=Article is not a template. article.template.false=Article is not a template.
article.template.true=This is a template. article.template.true=This is a template.
auditLog.no-value=No value
...@@ -6539,3 +6539,17 @@ table.accessions { ...@@ -6539,3 +6539,17 @@ table.accessions {
.margin-top-20 { margin-top: 20px; } .margin-top-20 { margin-top: 20px; }
.margin-top-25 { margin-top: 25px; } .margin-top-25 { margin-top: 25px; }
.margin-top-30 { margin-top: 30px; } .margin-top-30 { margin-top: 30px; }
.auditlog-entries {
opacity: .5;
}
.change-arrow {
// [dir="ltr"]
&::before {
content: '\2192' // →
}
// [dir="rtl"] &::before {
// content: '\2190' // ←
// }
}
...@@ -191,7 +191,7 @@ ...@@ -191,7 +191,7 @@
<td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"> <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>">
<p> <p>
<c:if test="${accession.doi ne null}"> <c:if test="${accession.doi ne null}">
<a href="<c:url value="${baseUrl}/${accession.doi}" />"><c:out value="${accession.doi}" /></a> <a href="<c:url value="/${accession.doi}" />"><c:out value="${accession.doi}" /></a>
</c:if> </c:if>
</p> </p>
</td> </td>
...@@ -1129,5 +1129,3 @@ ...@@ -1129,5 +1129,3 @@
</content> </content>
</body> </body>
</html> </html>
\ No newline at end of file
<%@ tag description="Displays audit log for a single property" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="local" tagdir="/WEB-INF/tags" %>
<%@ attribute name="auditLogs" required="true" type="java.util.List" %>
<%@ attribute name="property" required="false" type="java.lang.String" %>
<%@ attribute name="i18n" required="false" type="java.lang.String" %>
<%-- <p>
<small>
Logs=${auditLogs}
</small>
</p> --%>
<security:authorize access="isAuthenticated()">
<c:if test="${auditLogs.size() gt 0}">
<div class="auditlog-entries">
<c:forEach items="${auditLogs}" var="auditLog">
<p>
<span dir="ltr">
<c:if test="${auditLog.referencedEntity == null}">
<local:display value="${auditLog.previousState}" i18n="${i18n}" />
<span class="change-arrow"></span>
<local:display value="${auditLog.newState}" i18n="${i18n}" />
</c:if>
<c:if test="${auditLog.referencedEntity != null}">
<local:display value="${auditLog.previousEntity}" property="${property}" i18n="${i18n}" />
<span class="change-arrow"></span>
<local:display value="${auditLog.newEntity}" property="${property}" i18n="${i18n}" />
</c:if>
</span>
<span class="pull-right">
<local:prettyTime date="${auditLog.logDate}" locale="${pageContext.response.locale}" />
</span>
</p>
</c:forEach>
</div>
</c:if>
</security:authorize>
<%@ tag description="Pretty print taxon name" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="country" required="true" type="org.genesys2.server.model.impl.Country" %>
<%@ attribute name="flag" required="false" type="java.lang.Boolean" %>
<c:if test="${country ne null}">
<c:if test="${! flag}">
<a href="<c:url value="/geo/${country.code3}" />"><c:out value="${country.getName(pageContext.response.locale)}" /></a>
</c:if>
<c:if test="${flag}">
<img class="flag" src="<c:url value="${cdnFlagsUrl}" />/${country.code3.toUpperCase()}.svg" />
<a href="<c:url value="/geo/${country.code3}" />">
<c:out value="${country.getName(pageContext.response.locale)}" />
</a>
</c:if>
</c:if>
<%@ tag description="Displays stuff" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="local" tagdir="/WEB-INF/tags" %>
<%@ attribute name="value" required="true" type="java.lang.Object" %>
<%@ attribute name="property" required="false" type="java.lang.String" %>
<%@ attribute name="i18n" required="false" type="java.lang.String" %>
<c:if test="${value eq null}">
<code><spring:message code="auditLog.no-value" /></code>
</c:if>
<c:if test="${value ne null}">
<c:if test="${property eq '' or property eq null}">
<c:set var="clazz" value="${value.getClass().name}" />
<%-- No prop --%>
<c:choose>
<c:when test="${clazz == 'org.genesys2.server.model.genesys.Taxonomy2'}">
<local:taxonName taxon="${value}" />
</c:when>
<c:when test="${clazz == 'org.genesys2.server.model.impl.Country'}">
<local:country country="${value}" />
</c:when>
<c:otherwise>
<c:if test="${i18n eq '' or i18n eq null}">
<c:out value="${value}" />
</c:if>
<c:if test="${i18n ne ''}">
<spring:message code="${i18n.concat('.').concat(value)}" />
</c:if>
</c:otherwise>
</c:choose>
</c:if>
<c:if test="${property ne '' and property ne null}">
<%-- Prop='${property}' --%>
<c:if test="${i18n eq '' or i18n eq null}">
<c:out value="${value[property]}" />
</c:if>
<c:if test="${i18n ne '' and i18n ne null}">
<%-- i18n=${i18n}.${value[property]} --%>
<spring:message code="${i18n}.${value[property]}" />
</c:if>
</c:if>
</c:if>
<%@ tag description="Pretty print taxon name" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="taxon" required="true" type="org.genesys2.server.model.genesys.Taxonomy2" %>
<span dir="ltr" class="sci-name">
<c:out escapeXml="false" value="${taxon.taxonNameHtml}" />
</span>
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