Commit bc498717 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '198-record-changes-to-accession-data' into 'master'

Resolve "Record changes to Accession data"

Closes #198

See merge request genesys-pgr/genesys-server!96
parents 5742de5a 521d6ac1
......@@ -131,11 +131,7 @@ public class FirstRunListener extends RunAsAdminListener {
LOG.warn("Skipping creation of initial OAuth client");
}
if (accessionRepository.count() == 0) {
addSomeAccessions();
} else {
LOG.warn("Skipping creation of dummy accession data");
}
addSomeAccessions();
}
private void addCrop(String shortName) {
......
......@@ -11,16 +11,15 @@ import javax.persistence.PrePersist;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;
@Entity
@Table(name = "ds2")
public class DS extends BasicModel {
/**
*
*/
private static final long serialVersionUID = -8152480522578736947L;
@Column(columnDefinition = "binary(16)", unique = true, nullable=false, updatable = false)
@Column(unique = true, nullable = false, updatable = false)
@Type(type = "uuid-binary")
private UUID uuid;
@OrderBy("index")
......
......@@ -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 {
......
......@@ -36,9 +36,11 @@ import javax.persistence.Table;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.IdUUID;
import org.genesys2.server.model.impl.AccessionList;
import org.hibernate.annotations.Type;
/**
* Entity holds the assigned accession identifiers regardless of active or historic records.
* Entity holds the assigned accession identifiers regardless of active or
* historic records.
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
......@@ -50,7 +52,8 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
*/
private static final long serialVersionUID = -6224417080504343264L;
@Column(columnDefinition = "binary(16)")
@Column(updatable = false)
@Type(type = "uuid-binary")
protected UUID uuid;
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", orphanRemoval = false)
......
......@@ -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;
......
/**
* Copyright 2015 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.
......@@ -31,6 +31,7 @@ import javax.persistence.Table;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys2.server.model.genesys.AccessionId;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
......@@ -41,11 +42,12 @@ public class AccessionList extends AuditedVersionedModel implements AclAwareMode
private static final long serialVersionUID = 991886970995006680L;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
@Column(name = "uuid", unique = true, nullable = false, updatable = false, columnDefinition = "binary(16)")
@Column(name = "uuid", unique = true, nullable = false, updatable = false)
@Type(type = "uuid-binary")
protected UUID uuid;
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "accelistitems", joinColumns = @JoinColumn(name = "listid") , inverseJoinColumns = @JoinColumn(name = "acceid") )
@JoinTable(name = "accelistitems", joinColumns = @JoinColumn(name = "listid"), inverseJoinColumns = @JoinColumn(name = "acceid"))
private Set<AccessionId> accessionIds;
@Column(name = "title", nullable = false)
......@@ -61,7 +63,7 @@ public class AccessionList extends AuditedVersionedModel implements AclAwareMode
return uuid;
}
protected void setUuid(UUID uuid) {
protected void setUuid(final UUID uuid) {
this.uuid = uuid;
}
......@@ -79,7 +81,7 @@ public class AccessionList extends AuditedVersionedModel implements AclAwareMode
return accessionIds;
}
protected void setAccessionIds(Set<AccessionId> accessionIds) {
protected void setAccessionIds(final Set<AccessionId> accessionIds) {
this.accessionIds = accessionIds;
}
......@@ -91,22 +93,22 @@ public class AccessionList extends AuditedVersionedModel implements AclAwareMode
return title;
}
public void setDescription(String description) {
public void setDescription(final String description) {
this.description = description;
}
public void setTitle(String title) {
public void setTitle(final String title) {
this.title = title;
}
public void setShared(boolean shared) {
public void setShared(final boolean shared) {
this.shared = shared;
}
public boolean isShared() {
return shared;
}
public boolean getShared() {
return shared;
}
......
......@@ -38,7 +38,8 @@ import org.hibernate.annotations.Type;
public class Descriptor extends BasicModel {
private static final long serialVersionUID = 3832200593904442940L;
@Column(columnDefinition = "binary(16)", unique = true, nullable=false, updatable = false)
@Column(unique = true, nullable=false, updatable = false)
@Type(type = "uuid-binary")
private UUID uuid;
@Lob
......
......@@ -18,6 +18,7 @@ package org.genesys2.server.model.impl;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.List;
......@@ -39,6 +40,7 @@ public class Project extends AuditedVersionedModel implements AclAwareModel {
private String code;
@Column(name = "uuid", nullable = false)
@Type(type = "uuid-binary")
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "project_accelist", joinColumns = @JoinColumn(name = "projectId", referencedColumnName = "id"))
private List<UUID> accessionLists;
......
......@@ -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());
......
......@@ -23,14 +23,12 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.persistence.PersistenceException;
import org.apache.commons.lang.StringUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.genesys.blocks.auditlog.service.ClassPKService;
import org.genesys.blocks.model.ClassPK;
import org.genesys.blocks.model.EntityId;
import org.genesys.blocks.persistence.ClassPKRepository;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Menu;
......@@ -53,6 +51,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@Service
......@@ -67,7 +66,7 @@ public class ContentServiceImpl implements ContentService {
private ArticleRepository articleRepository;
@Autowired
private ClassPKRepository classPkRepository;
private ClassPKService classPkService;
@Autowired
private HtmlSanitizer htmlSanitizer;
......@@ -140,7 +139,7 @@ public class ContentServiceImpl implements ContentService {
@Override
public Article getArticleBySlugLangTargetIdClassPk(String slug, String lang, Long targetId, String classPKShortName) {
ClassPK classPK = classPkRepository.findByShortName(classPKShortName);
ClassPK classPK = classPkService.findByShortName(classPKShortName);
return articleRepository.findBySlugAndLangAndTargetIdAndClassPk(slug, lang, targetId, classPK);
}
......@@ -241,60 +240,18 @@ public class ContentServiceImpl implements ContentService {
@Override
public ClassPK getClassPk(Class<?> clazz) {
return classPkRepository.getByClassname(clazz.getName());
return classPkService.getClassPk(clazz);
}
@Override
public ClassPK getClassPk(String shortName) {
return classPkRepository.findByShortName(shortName);
return classPkService.findByShortName(shortName);
}
@Override
@Transactional
public ClassPK ensureClassPK(Class<?> clazz) {
ClassPK classPk = classPkRepository.getByClassname(clazz.getName());
if (classPk == null) {
classPk = ensureClassPKInternal(clazz);
}
if (classPk.getShortName() == null) {
classPk.setShortName(generateShortPkName(clazz.getSimpleName().toLowerCase()));
classPkRepository.save(classPk);