Commit d6dda6db authored by Matija Obreza's avatar Matija Obreza

Auditing accession data

parent 731dcbb9
......@@ -48,7 +48,7 @@ public class AccessionDetails {
private UUID uuid;
@Field(type = FieldType.String)
private String acceNumb;
private Float seqNo;
private double seqNo;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String acqDate;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
......@@ -113,7 +113,7 @@ public class AccessionDetails {
public static AccessionDetails from(AccessionData accession) {
AccessionDetails ad = new AccessionDetails();
ad.version = accession.getVersion();
ad.version = accession.getVersion() == null ? null : accession.getVersion().longValue();
ad.id = accession.getId();
ad.uuid = accession.getUuid();
ad.createdDate = accession.getCreatedDate();
......@@ -264,11 +264,11 @@ public class AccessionDetails {
this.acceNumb = acceNumb;
}
public Float getSeqNo() {
public double getSeqNo() {
return seqNo;
}
public void setSeqNo(Float seqNo) {
public void setSeqNo(double seqNo) {
this.seqNo = seqNo;
}
......
......@@ -31,6 +31,8 @@ import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys.blocks.auditlog.annotations.Audited;
/**
* Active accession records with all possible constraints.
*
......@@ -43,6 +45,7 @@ import javax.persistence.UniqueConstraint;
uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "taxGenus", "acceNumb" }), @UniqueConstraint(name = "UQ_accession_doi", columnNames = {"doi"})},
// Indexes
indexes = { @Index(name = "IX_seqNo", columnList = "seqNo"), @Index(name = "IX_accession_lastModifiedDate", columnList = "lastModifiedDate") })
@Audited
public class Accession extends AccessionData {
/**
*
......
......@@ -24,6 +24,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
/**
......@@ -31,6 +32,7 @@ import org.genesys.blocks.model.BasicModel;
*/
@Entity
@Table(name = "accessionalias")
@Audited
public class AccessionAlias extends BasicModel implements AccessionRelated {
......
......@@ -26,6 +26,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;
......@@ -34,6 +35,7 @@ import org.hibernate.annotations.Type;
*/
@Entity
@Table(name = "accessionbreeding")
@Audited
public class AccessionBreeding extends BasicModel implements AccessionRelated {
......
......@@ -26,6 +26,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;
......@@ -34,6 +35,7 @@ import org.hibernate.annotations.Type;
*/
@Entity
@Table(name = "accessioncollect")
@Audited
public class AccessionCollect extends BasicModel implements AccessionRelated {
......
......@@ -20,14 +20,12 @@ import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
......@@ -36,46 +34,22 @@ import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.IdUUID;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.util.MCPDUtil;
import org.genesys2.util.NumberUtils;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
@MappedSuperclass
public abstract class AccessionData implements IdUUID, Serializable {
public abstract class AccessionData extends AuditedVersionedModel implements IdUUID, Serializable {
private static final long serialVersionUID = -3428918862058441943L;
public static final List<AccessionData> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<AccessionData>());
@Id
private Long id;
@Version
private long version = 0;
@CreatedBy
private Long createdBy;
@CreatedDate
@Column(name = "createdDate")
private Date createdDate;
@LastModifiedBy
private Long lastModifiedBy;
@LastModifiedDate
@Column(name = "lastModifiedDate")
private Date lastModifiedDate;
@MapsId
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, optional = false, orphanRemoval = false)
@JoinColumn(name = "id")
......@@ -95,7 +69,7 @@ public abstract class AccessionData implements IdUUID, Serializable {
private String accessionName;
@Column(name = "seqNo", nullable = false)
private float seqNo = 0;
private double seqNo = 0;
@Column(name = "cropName", nullable = true, length = 100)
private String cropName;
......@@ -319,46 +293,6 @@ public abstract class AccessionData implements IdUUID, Serializable {
this.historic = historic;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Long getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(Long lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
public AccessionId getAccessionId() {
return accessionId;
}
......@@ -373,14 +307,6 @@ public abstract class AccessionData implements IdUUID, Serializable {
return accessionId.getUuid();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return MessageFormat.format("Accession id={0,number,##########} UUID={1}", accessionId.getId(), getUuid());
......@@ -394,11 +320,11 @@ public abstract class AccessionData implements IdUUID, Serializable {
this.acceUrl = acceUrl;
}
public float getSeqNo() {
public double getSeqNo() {
return seqNo;
}
public void setSeqNo(float acceNumbNumb) {
public void setSeqNo(double acceNumbNumb) {
this.seqNo = acceNumbNumb;
}
......
......@@ -25,6 +25,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
/**
......@@ -32,6 +33,7 @@ import org.genesys.blocks.model.BasicModel;
*/
@Entity
@Table(name = "accessionexchange")
@Audited
public class AccessionExchange extends BasicModel implements AccessionRelated {
......
......@@ -25,11 +25,13 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
import org.genesys2.server.model.impl.GeoReferencedEntity;
@Entity
@Table(name = "accessiongeo")
@Audited
public class AccessionGeo extends BasicModel implements GeoReferencedEntity, AccessionRelated {
......
......@@ -25,6 +25,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;
......@@ -33,6 +34,7 @@ import org.hibernate.annotations.Type;
*/
@Entity
@Table(name = "accessionremark")
@Audited
public class AccessionRemark extends BasicModel implements AccessionRelated {
/**
......
......@@ -29,10 +29,12 @@ import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.VersionedModel;
@Entity
@Table(name = "pdci", indexes = { @Index(columnList = "score") })
@Audited
public class PDCI extends VersionedModel implements AccessionRelated {
private static final long serialVersionUID = -1312366054528702261L;
......
......@@ -90,13 +90,13 @@ public interface GenesysService {
List<AccessionAlias> listAccessionAliases(AccessionId accession);
AccessionExchange listAccessionExchange(AccessionId accession);
AccessionExchange getAccessionExchange(AccessionId accession);
AccessionCollect listAccessionCollect(AccessionId accession);
AccessionCollect getAccessionCollect(AccessionId accession);
AccessionBreeding listAccessionBreeding(AccessionId accession);
AccessionBreeding getAccessionBreeding(AccessionId accession);
AccessionGeo listAccessionGeo(AccessionId accession);
AccessionGeo getAccessionGeo(AccessionId accession);
List<AccessionRemark> listAccessionRemarks(AccessionId accession);
......
......@@ -351,7 +351,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has(Api1Constants.Accession.COLL)) {
final ObjectNode collecting = (ObjectNode) accnJson.get(Api1Constants.Accession.COLL);
AccessionCollect accnColl = genesysService.listAccessionCollect(accession.getAccessionId());
AccessionCollect accnColl = genesysService.getAccessionCollect(accession.getAccessionId());
if (accnColl == null) {
accnColl = new AccessionCollect();
accnColl.setAccession(accession.getAccessionId());
......@@ -402,7 +402,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has(Api1Constants.Accession.GEO)) {
final ObjectNode geo = (ObjectNode) accnJson.get(Api1Constants.Accession.GEO);
AccessionGeo accnGeo = genesysService.listAccessionGeo(accession.getAccessionId());
AccessionGeo accnGeo = genesysService.getAccessionGeo(accession.getAccessionId());
if (accnGeo == null) {
accnGeo = new AccessionGeo();
accnGeo.setAccession(accession.getAccessionId());
......@@ -451,7 +451,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
if (accnJson.has(Api1Constants.Accession.BREDCODE) || accnJson.has(Api1Constants.Accession.ANCEST)) {
AccessionBreeding accnBred = genesysService.listAccessionBreeding(accession.getAccessionId());
AccessionBreeding accnBred = genesysService.getAccessionBreeding(accession.getAccessionId());
if (accnBred == null) {
accnBred = new AccessionBreeding();
accnBred.setAccession(accession.getAccessionId());
......@@ -472,7 +472,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
if (accnJson.has(Api1Constants.Accession.DONORCODE) || accnJson.has(Api1Constants.Accession.DONORNUMB) || accnJson.has(Api1Constants.Accession.DONORNAME)) {
AccessionExchange accnExch = genesysService.listAccessionExchange(accession.getAccessionId());
AccessionExchange accnExch = genesysService.getAccessionExchange(accession.getAccessionId());
if (accnExch == null) {
accnExch = new AccessionExchange();
accnExch.setAccession(accession.getAccessionId());
......
......@@ -54,13 +54,13 @@ public class GenesysRESTServiceImpl implements GenesysRESTService {
final AccessionJson aj = GenesysJsonFactory.from(accession);
final AccessionBreeding breeding = genesysService.listAccessionBreeding(accession.getAccessionId());
final AccessionBreeding breeding = genesysService.getAccessionBreeding(accession.getAccessionId());
GenesysJsonFactory.addBreeding(aj, breeding);
final AccessionCollect collect = genesysService.listAccessionCollect(accession.getAccessionId());
final AccessionCollect collect = genesysService.getAccessionCollect(accession.getAccessionId());
GenesysJsonFactory.addCollecting(aj, collect);
final AccessionGeo geo = genesysService.listAccessionGeo(accession.getAccessionId());
final AccessionGeo geo = genesysService.getAccessionGeo(accession.getAccessionId());
GenesysJsonFactory.addGeo(aj, geo);
List<AccessionRemark> remarks = genesysService.listAccessionRemarks(accession.getAccessionId());
......
......@@ -438,7 +438,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public AccessionBreeding listAccessionBreeding(AccessionId accession) {
public AccessionBreeding getAccessionBreeding(AccessionId accession) {
if (accession == null || !accession.isPersisted()) {
return null;
}
......@@ -446,7 +446,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public AccessionGeo listAccessionGeo(AccessionId accession) {
public AccessionGeo getAccessionGeo(AccessionId accession) {
if (accession == null || !accession.isPersisted()) {
return null;
}
......@@ -470,7 +470,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public AccessionCollect listAccessionCollect(AccessionId accession) {
public AccessionCollect getAccessionCollect(AccessionId accession) {
if (accession == null || !accession.isPersisted()) {
return null;
}
......@@ -478,7 +478,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public AccessionExchange listAccessionExchange(AccessionId accession) {
public AccessionExchange getAccessionExchange(AccessionId accession) {
if (accession == null || !accession.isPersisted()) {
return null;
}
......@@ -507,10 +507,10 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (accession == null)
return null;
AllStuff all = new AllStuff(accession);
all.bred = listAccessionBreeding(accession.getAccessionId());
all.collect = listAccessionCollect(accession.getAccessionId());
all.exch = listAccessionExchange(accession.getAccessionId());
all.geo = listAccessionGeo(accession.getAccessionId());
all.bred = getAccessionBreeding(accession.getAccessionId());
all.collect = getAccessionCollect(accession.getAccessionId());
all.exch = getAccessionExchange(accession.getAccessionId());
all.geo = getAccessionGeo(accession.getAccessionId());
all.names = listAccessionAliases(accession.getAccessionId());
all.remarks = listAccessionRemarks(accession.getAccessionId());
all.sgsvDeposits = getSvalbardData(accession.getAccessionId());
......
......@@ -75,10 +75,10 @@ public class ArchiveController extends BaseController {
model.addAttribute("accession", accession);
model.addAttribute("accessionNames", genesysService.listAccessionNames(accession.getAccessionId()));
model.addAttribute("accessionAliases", genesysService.listAccessionAliases(accession.getAccessionId()));
model.addAttribute("accessionExchange", genesysService.listAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.listAccessionCollect(accession.getAccessionId()));
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession.getAccessionId()));
AccessionGeo accessionGeo = genesysService.listAccessionGeo(accession.getAccessionId());
model.addAttribute("accessionExchange", genesysService.getAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.getAccessionCollect(accession.getAccessionId()));
model.addAttribute("accessionBreeding", genesysService.getAccessionBreeding(accession.getAccessionId()));
AccessionGeo accessionGeo = genesysService.getAccessionGeo(accession.getAccessionId());
model.addAttribute("accessionGeo", accessionGeo);
model.addAttribute("svalbardData", genesysService.getSvalbardData(accession.getAccessionId()));
model.addAttribute("accessionRemarks", genesysService.listAccessionRemarks(accession.getAccessionId()));
......
......@@ -65,10 +65,10 @@ public class AccessionControllerRdf {
model.addAttribute("accession", accession);
model.addAttribute("accessionNames", genesysService.listAccessionNames(accession.getAccessionId()));
model.addAttribute("accessionExchange", genesysService.listAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.listAccessionCollect(accession.getAccessionId()));
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession.getAccessionId()));
model.addAttribute("accessionGeo", genesysService.listAccessionGeo(accession.getAccessionId()));
model.addAttribute("accessionExchange", genesysService.getAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.getAccessionCollect(accession.getAccessionId()));
model.addAttribute("accessionBreeding", genesysService.getAccessionBreeding(accession.getAccessionId()));
model.addAttribute("accessionGeo", genesysService.getAccessionGeo(accession.getAccessionId()));
model.addAttribute("metadatas", genesysService.listMetadata(accession.getAccessionId()));
model.addAttribute("methods", traitService.listMethods(accession.getAccessionId()));
......
......@@ -40,7 +40,7 @@ import org.springframework.core.io.Resource;
@Configuration
@Import({ CommonConfig.class, SchedulerConfig.class, DatabaseConfig.class, MailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, CacheConfig.class,
ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class })
ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class, AuditConfig.class })
public class ApplicationConfig {
public static final Logger LOG = LoggerFactory.getLogger(ApplicationConfig.class);
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.spring.config;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.blocks.auditlog.service.ClassPKService;
import org.genesys.blocks.auditlog.service.impl.AuditTrailServiceImpl;
import org.genesys.blocks.auditlog.service.impl.ClassPKServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration of audit-related components and services.
*
* @author Matija Obreza
*/
@Configuration
public class AuditConfig {
@Bean
public ClassPKService classPkService() {
return new ClassPKServiceImpl();
}
@Bean
public AuditTrailService auditTrailService() {
return new AuditTrailServiceImpl();
}
}
......@@ -16,13 +16,21 @@
package org.genesys2.spring.config;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.genesys.blocks.auditlog.component.AuditTrailInterceptor;
import org.genesys2.spring.hazelcast.HazelcastCacheRegionFactoryWrapper;
import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Interceptor;
import org.hibernate.Transaction;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -38,7 +46,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import liquibase.integration.spring.SpringLiquibase;
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys.blocks.oauth.persistence",
"org.genesys2.server.persistence.domain", "org.genesys2.server.persistence.acl",
"org.genesys.blocks.auditlog.persistence", "org.genesys2.server.persistence.domain", "org.genesys2.server.persistence.acl",
"org.genesys.filerepository.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableTransactionManagement
......@@ -135,13 +143,90 @@ public class DatabaseConfig {
for (final Object key : jpaProperties.keySet()) {
System.err.println("JPA: " + key + " = " + jpaProperties.get(key));
}
jpaProperties.put("hibernate.ejb.interceptor", new EmptyInterceptor() {
private static final long serialVersionUID = 412280557897728434L;
// NOTE We're using the auditTrailInterceptor() to fetch the lazy-initialized
// bean. Otherwise you end up with "Requested bean is currently in creation: Is
// there an unresolvable circular reference?"
@Override
public boolean onFlushDirty(final Object entity, final Serializable id, final Object[] currentState, final Object[] previousState, final String[] propertyNames,
final Type[] types) {
return auditTrailInterceptor().onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
@Override
public void onDelete(final Object entity, final Serializable id, final Object[] state, final String[] propertyNames, final Type[] types) {
auditTrailInterceptor().onDelete(entity, id, state, propertyNames, types);
}
@Override
public void onCollectionRecreate(final Object collection, final Serializable key) throws CallbackException {
auditTrailInterceptor().onCollectionRecreate(collection, key);
}
@Override
public void onCollectionRemove(final Object collection, final Serializable key) throws CallbackException {
auditTrailInterceptor().onCollectionRemove(collection, key);
}
@Override
public void onCollectionUpdate(final Object collection, final Serializable key) throws CallbackException {
auditTrailInterceptor().onCollectionUpdate(collection, key);
}
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
return auditTrailInterceptor().onSave(entity, id, state, propertyNames, types);
}
@Override
public void afterTransactionBegin(Transaction tx) {
auditTrailInterceptor().afterTransactionBegin(tx);
}
@Override
public void beforeTransactionCompletion(Transaction tx) {
auditTrailInterceptor().beforeTransactionCompletion(tx);
}
@Override
public void afterTransactionCompletion(Transaction tx) {
auditTrailInterceptor().afterTransactionCompletion(tx);
}
@SuppressWarnings("rawtypes")
@Override
public void postFlush(Iterator entities) {
auditTrailInterceptor().postFlush(entities);
}
@Override