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

Updated Catalog data model

- Adjusted Json views
- Added back-reference from VocabularyTerm to Descriptor and ControlledVocabulary
parent f3abd1ad
......@@ -37,6 +37,7 @@ import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.Publishable;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
......@@ -48,6 +49,7 @@ import org.genesys.common.model.SelfCleaning;
import org.genesys.filerepository.model.RepositoryFile;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
/**
* {@link Dataset} captures the metadata information as a snapshot. Multiple
......@@ -76,6 +78,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@PublishValidation
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
private Partner owner;
/** The accession identifiers. */
......@@ -83,12 +86,14 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@CollectionTable(name = "datasetAccessions", joinColumns = @JoinColumn(name = "datasetId"),
// index
indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") })
@JsonView({ JsonViews.Public.class })
private Set<AccessionIdentifier> accessionIdentifiers;
/** The descriptors. */
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "datasetDescriptor", joinColumns = @JoinColumn(name = "datasetId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "descriptorId", referencedColumnName = "id"))
@OrderColumn(name = "position")
@JsonView({ JsonViews.Public.class })
private List<Descriptor> descriptors;
/** The repository files. */
......@@ -96,16 +101,19 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@OneToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "datasetRepositoryfile", joinColumns = @JoinColumn(name = "datasetId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "repositoryfileId", referencedColumnName = "id"))
@OrderColumn(name = "position")
@JsonView({ JsonViews.Public.class })
private List<RepositoryFile> repositoryFiles;
/** The creators. */
@PublishValidation(innerCheck = true)
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataset", orphanRemoval = true, fetch = FetchType.LAZY)
@JsonView({ JsonViews.Public.class })
private List<DatasetCreator> creators;
/** The locations. */
@PublishValidation(innerCheck = true)
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataset", orphanRemoval = true, fetch = FetchType.LAZY)
@JsonView({ JsonViews.Public.class })
private List<DatasetLocation> locations;
/** The accession count. */
......@@ -124,6 +132,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
// index
indexes = { @Index(columnList = "datasetId, crop") })
@Column(name = "crop", nullable = false, length = 20)
@JsonView({ JsonViews.Minimal.class })
private Set<String> crops;
/**
......
......@@ -26,8 +26,6 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.UuidModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys.catalog.service.PublishValidationInterface;
......@@ -66,39 +64,32 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
}
/** The full name. */
@JsonView(JsonViews.Public.class)
@PublishValidation
@Column(length = 200, nullable = false)
private String fullName;
/** The email. */
@JsonView(JsonViews.Public.class)
@PublishValidation
private String email;
/** The phone number. */
@JsonView(JsonViews.Public.class)
@PublishValidation
private String phoneNumber;
/** The fax. */
@JsonView(JsonViews.Public.class)
@PublishValidation
private String fax;
/** The institutional affiliation. */
@JsonView(JsonViews.Public.class)
@PublishValidation
private String institutionalAffiliation;
/** The institute address. */
@JsonView(JsonViews.Public.class)
@PublishValidation
private String instituteAddress;
/** The role. */
@Enumerated(EnumType.STRING)
@JsonView(JsonViews.Public.class)
@PublishValidation
private DatasetCreatorRole role;
......
......@@ -39,6 +39,7 @@ import javax.persistence.UniqueConstraint;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.Publishable;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
......@@ -53,6 +54,7 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
/**
......@@ -178,6 +180,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
@JoinColumn(name = "vocabularyId")
@JsonIdentityReference(alwaysAsId = false)
@JsonIgnoreProperties(value = { "terms" })
@JsonView({ JsonViews.Public.class })
private ControlledVocabulary vocabulary;
/**
......@@ -190,12 +193,14 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
// unique constraints
uniqueConstraints = { @UniqueConstraint(columnNames = { "descriptorId", "termId" }) })
@OrderColumn(name = "idx")
@JsonView({ JsonViews.Public.class })
private List<VocabularyTerm> terms;
/** The owner. */
@JsonIdentityReference(alwaysAsId = false)
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
private Partner owner;
/** The descriptor lists. */
......
......@@ -103,12 +103,14 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@ManyToMany(cascade = { CascadeType.REMOVE, CascadeType.REFRESH }, fetch = FetchType.LAZY)
@JoinTable(name = "descriptorListDescriptor", joinColumns = @JoinColumn(name = "descriptorListId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "descriptorId", referencedColumnName = "id"))
@OrderColumn(name = "position")
@JsonView({ JsonViews.Public.class })
@JsonIgnoreProperties(value = { "descriptorLists", "datasets", "owner", "vocabulary", "terms" })
List<Descriptor> descriptors;
/** The owner. */
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
private Partner owner;
/** The publisher. */
......
......@@ -31,6 +31,7 @@ import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.UniqueConstraint;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.Publishable;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
......@@ -40,6 +41,8 @@ import org.hibernate.annotations.ColumnDefault;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
/**
......@@ -99,6 +102,8 @@ public class ControlledVocabulary extends UuidModel implements Publishable, Self
// unique constraints
uniqueConstraints = { @UniqueConstraint(columnNames = { "vocabularyId", "termId" }) })
@OrderColumn(name = "idx")
@JsonIgnoreProperties({ "vocabulary", "descriptor" })
@JsonView({ JsonViews.Minimal.class })
private List<VocabularyTerm> terms;
/** Number of terms in the vocabulary */
......@@ -109,6 +114,7 @@ public class ControlledVocabulary extends UuidModel implements Publishable, Self
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonIdentityReference(alwaysAsId = false)
@JsonView({ JsonViews.Public.class })
private Partner owner;
/**
......
......@@ -17,16 +17,27 @@ package org.genesys.catalog.model.vocab;
import java.text.MessageFormat;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.common.model.SelfCleaning;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
/**
* A single vocabulary term, belonging to a {@link ControlledVocabulary}.
*
......@@ -57,6 +68,30 @@ public class VocabularyTerm extends BasicModel implements SelfCleaning {
@Column(nullable = false)
private String title;
/**
* Link back to Descriptor
*/
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
@JoinTable(name = "DescriptorTerm", joinColumns = @JoinColumn(name = "termId"),
// other side
inverseJoinColumns = @JoinColumn(name = "descriptorId"))
@JsonView({ JsonViews.Indexed.class, JsonViews.Minimal.class })
@JsonIgnoreProperties(value = { "terms", "owner" })
@JsonIdentityReference(alwaysAsId = false)
private Descriptor descriptor;
/**
* Link back to Descriptor
*/
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
@JoinTable(name = "ControlledVocabularyTerm", joinColumns = @JoinColumn(name = "termId"),
// other side
inverseJoinColumns = @JoinColumn(name = "vocabularyId"))
@JsonView({ JsonViews.Indexed.class, JsonViews.Minimal.class })
@JsonIgnoreProperties(value = { "terms", "owner" })
@JsonIdentityReference(alwaysAsId = false)
private ControlledVocabulary vocabulary;
/**
* Term description in English.
*/
......@@ -140,6 +175,24 @@ public class VocabularyTerm extends BasicModel implements SelfCleaning {
return term;
}
/**
* Get the descriptor associated with this term
*
* @return null or the descriptor
*/
public Descriptor getDescriptor() {
return descriptor;
}
/**
* Get the vocabulary associated with this term
*
* @return null or the vocabulary
*/
public ControlledVocabulary getVocabulary() {
return vocabulary;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
......
......@@ -15,6 +15,8 @@
*/
package org.genesys.catalog.service;
import static org.genesys.catalog.model.vocab.QVocabularyTerm.vocabularyTerm;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
......@@ -28,11 +30,13 @@ import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.persistence.vocab.ControlledVocabularyRepository;
import org.genesys.catalog.persistence.vocab.VocabularyTermRepository;
import org.genesys.catalog.test.CatalogServiceTest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Lists;
public class CodedDescriptorTest extends CatalogServiceTest {
......@@ -51,6 +55,8 @@ public class CodedDescriptorTest extends CatalogServiceTest {
private VocabularyService vocabularyService;
@Autowired
private ControlledVocabularyRepository vocabRepository;
@Autowired
private VocabularyTermRepository termRepository;
@Override
public void cleanup() {
......@@ -104,4 +110,13 @@ public class CodedDescriptorTest extends CatalogServiceTest {
assertThat(descriptor.getTerms(), hasSize(2));
}
@Test
public void queryTermByDescriptor() throws JsonProcessingException {
testCreateCodedDescriptorWithTerms();
VocabularyTerm term = termRepository.findOne(vocabularyTerm.descriptor.title.eq(DESCRIPTOR_TITLE_1).and(vocabularyTerm.code.eq("2")));
assertThat(term, not(nullValue()));
assertThat(term.getCode(), equalTo("2"));
assertThat(term.getTitle(), equalTo("Two"));
}
}
Supports Markdown
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