Commit 6be77327 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Linking Subsets and Datasets with Accessions using AccessionRef

- added Aspect to un-/link Accession with AccessionRef
- liquibase changes to migrate data
- updated tests
parent dadfbf70
......@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.dataset.DatasetLocation;
......@@ -216,15 +216,15 @@ public class DatasetController {
*
* @param uuid the uuid
* @param version the version
* @param accessionIdentifiers the accession identifiers
* @param accessionRefs the accession identifiers
* @return the dataset
* @throws NotFoundElement the not found element
*/
@PostMapping(value = "/upsertaccessions/{UUID},{version}")
public Dataset upsertAccessions(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version,
@RequestBody final Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement {
@RequestBody final Set<AccessionRef> accessionRefs) throws NotFoundElement {
final Dataset dataset = datasetService.loadDataset(uuid, version);
return datasetService.upsertAccessions(dataset, accessionIdentifiers);
return datasetService.upsertAccessions(dataset, accessionRefs);
}
/**
......
......@@ -32,7 +32,7 @@ import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.traits.Descriptor;
......@@ -90,7 +90,7 @@ public class SearchController {
Map<String, SearchResults<?>> suggestions = new HashMap<>();
suggestions.put("search.group.crop", SearchResults.from("code", Arrays.asList("crop"), hitsByEntity.get(Crop.class)));
suggestions.put("search.group.partner", SearchResults.from("uuid", Arrays.asList("owner.uuid"), hitsByEntity.get(Partner.class)));
suggestions.put("search.group.accession", SearchResults.from("doi", Arrays.asList("accessionIdentifier.doi"), hitsByEntity.get(AccessionIdentifier.class)));
suggestions.put("search.group.accession", SearchResults.from("doi", Arrays.asList("accessionIdentifier.doi"), hitsByEntity.get(AccessionRef.class)));
suggestions.put("search.group.descriptor", SearchResults.from("uuid", Arrays.asList("descriptor.uuid"), hitsByEntity.get(Descriptor.class)));
// Search datasets
......
......@@ -29,6 +29,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Document;
......@@ -78,7 +79,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") })
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
private Set<AccessionIdentifier> accessionIdentifiers;
private Set<AccessionRef> accessionRefs;
/** The descriptors. */
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
......@@ -119,7 +120,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private String endDate;
/** The accession count. */
// Number of accessions in the {@link #accessionIdentifiers} list
// Number of accessions in the {@link #accessionRefs} list
@Column(name = "accessions")
private Integer accessionCount;
......@@ -188,8 +189,8 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@PreUpdate
@PrePersist
private void preupdate() {
if (accessionIdentifiers != null) {
this.accessionCount = accessionIdentifiers.size();
if (accessionRefs != null) {
this.accessionCount = accessionRefs.size();
}
if (descriptors != null) {
this.descriptorCount = descriptors.size();
......@@ -515,19 +516,19 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
/**
* Gets the accession identifiers.
*
* @return the accessionIdentifiers
* @return the accessionRefs
*/
public final Set<AccessionIdentifier> getAccessionIdentifiers() {
return accessionIdentifiers;
public final Set<AccessionRef> getAccessionRefs() {
return accessionRefs;
}
/**
* Sets the accession identifiers.
*
* @param accessionIdentifiers the accessionIdentifiers to set
* @param accessionRefs the accessionRefs to set
*/
public final void setAccessionIdentifiers(final Set<AccessionIdentifier> accessionIdentifiers) {
this.accessionIdentifiers = accessionIdentifiers;
public final void setAccessionRefs(final Set<AccessionRef> accessionRefs) {
this.accessionRefs = accessionRefs;
}
/**
......
......@@ -19,19 +19,19 @@ import java.util.HashSet;
import java.util.Set;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys.catalog.model.dataset.QAccessionIdentifier;
import org.genesys2.server.model.genesys.AccessionRef;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.SetPath;
import org.genesys2.server.model.genesys.QAccessionRef;
/**
* The Class AccessionIdentifierFilter.
* The Class AccessionRefFilter.
*
* @author Matija Obreza
*/
public class AccessionIdentifierFilter {
public class AccessionRefFilter {
/** The doi. */
public Set<String> doi;
......@@ -54,10 +54,10 @@ public class AccessionIdentifierFilter {
* @param accessionIdentifiers the accession identifiers
* @return the predicate
*/
public Predicate buildQuery(final SetPath<AccessionIdentifier, QAccessionIdentifier> accessionIdentifiers) {
public Predicate buildQuery(final SetPath<AccessionRef, QAccessionRef> accessionIdentifiers) {
final BooleanBuilder and = new BooleanBuilder();
final QAccessionIdentifier identifier = accessionIdentifiers.any();
final QAccessionRef identifier = accessionIdentifiers.any();
if (doi != null && !doi.isEmpty()) {
and.and(identifier.doi.in(doi));
}
......@@ -83,7 +83,7 @@ public class AccessionIdentifierFilter {
* @param value the instCode to add
* @return the updated filter
*/
public AccessionIdentifierFilter instCode(final String value) {
public AccessionRefFilter instCode(final String value) {
if (instCode == null) {
instCode = new HashSet<>();
}
......@@ -97,7 +97,7 @@ public class AccessionIdentifierFilter {
* @param value the doi to add
* @return the updated filter
*/
public AccessionIdentifierFilter doi(final String value) {
public AccessionRefFilter doi(final String value) {
if (doi == null) {
doi = new HashSet<>();
}
......@@ -111,7 +111,7 @@ public class AccessionIdentifierFilter {
* @param value the genus to add
* @return the updated filter
*/
public AccessionIdentifierFilter genus(final String value) {
public AccessionRefFilter genus(final String value) {
if (genus == null) {
genus = new HashSet<>();
}
......
......@@ -46,7 +46,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
public PartnerFilter owner;
/** The accession identifier. */
public AccessionIdentifierFilter accessionIdentifier;
public AccessionRefFilter accessionIdentifier;
public DatasetLocationFilter location;
......@@ -91,7 +91,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
and.and(owner.buildQuery(dataset.owner));
}
if (accessionIdentifier != null) {
and.and(accessionIdentifier.buildQuery(dataset.accessionIdentifiers));
and.and(accessionIdentifier.buildQuery(dataset.accessionRefs));
}
if (descriptor != null) {
and.and(descriptor.buildQuery(dataset.descriptors.any()));
......@@ -120,7 +120,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
dataset.owner.shortName,
dataset.crops.any(),
dataset.descriptors.any().crop,
dataset.accessionIdentifiers.any().genus, dataset.accessionIdentifiers.any().instCode, dataset.accessionIdentifiers.any().acceNumb
dataset.accessionRefs.any().genus, dataset.accessionRefs.any().instCode, dataset.accessionRefs.any().acceNumb
),
FilterHelpers.containsAll(_text,
dataset.title, dataset.description,
......
......@@ -16,7 +16,8 @@
package org.genesys.catalog.service;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.dataset.DatasetLocation;
......@@ -63,13 +64,13 @@ public interface DatasetService {
Dataset updateDataset(Dataset input);
/**
* Method updating accessionIdentifiers in Dataset.
* Method updating accessionRefs in Dataset.
*
* @param dataset the dataset
* @param accessionIdentifiers new accessionIdentifiers
* @param accessionRefs new accessionRefs
* @return updated Dataset in db.
*/
Dataset updateAccessionIdentifiers(Dataset dataset, Set<AccessionIdentifier> accessionIdentifiers);
Dataset updateAccessionRefs(Dataset dataset, Set<AccessionRef> accessionRefs);
/**
* Method adding new descriptor to Dataset.
......@@ -118,10 +119,10 @@ public interface DatasetService {
/**
* List published datasets by accession.
*
* @param accessionId the accessionId
* @param accession the accession
* @return list of Dataset
*/
List<Dataset> listByAccession(AccessionId accessionId);
List<Dataset> listByAccession(Accession accession);
/**
* List published datasets matching the filter.
......@@ -204,11 +205,11 @@ public interface DatasetService {
* Register Accession identifiers with the Dataset.
*
* @param dataset the dataset
* @param accessionIdentifiers the accessionIdentifiers
* @param accessionRefs the accessionRefs
* @return updated Dataset
* @throws NotFoundElement the not found element
*/
Dataset upsertAccessions(Dataset dataset, Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement;
Dataset upsertAccessions(Dataset dataset, Set<AccessionRef> accessionRefs) throws NotFoundElement;
/**
* Puts the dataset into the Review state to be reviewed by admin.
......
......@@ -35,6 +35,10 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.Partner;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetVersions;
import org.genesys.catalog.model.dataset.QDataset;
import org.genesys.catalog.model.dataset.*;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.traits.Descriptor;
......@@ -140,8 +144,8 @@ public class DatasetServiceImpl implements DatasetService {
dataset.setLocations(new ArrayList<>());
dataset.setCrops(source.getCrops());
if (source.getAccessionIdentifiers() != null && !source.getAccessionIdentifiers().isEmpty()) {
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(source.getAccessionIdentifiers())));
if (source.getAccessionRefs() != null && !source.getAccessionRefs().isEmpty()) {
dataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(source.getAccessionRefs())));
}
copyDescriptors(dataset, source.getDescriptors());
......@@ -185,11 +189,11 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset updateAccessionIdentifiers(Dataset dataset, final Set<AccessionIdentifier> accessionIdentifiers) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionIdentifiers {}", dataset, accessionIdentifiers);
public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs);
dataset = loadDataset(dataset);
dataset.getAccessionIdentifiers().clear();
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers)));
dataset.getAccessionRefs().clear();
dataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(accessionRefs)));
return lazyLoad(datasetRepository.save(dataset));
}
......@@ -342,8 +346,8 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc}
*/
@Override
public List<Dataset> listByAccession(final AccessionId accessionId) {
final Iterable<Dataset> datasets = datasetRepository.findAll(dataset.accessionIdentifiers.any().accession.eq(accessionId).and(dataset.state.in(PublishState.PUBLISHED)));
public List<Dataset> listByAccession(final Accession accession) {
final Iterable<Dataset> datasets = datasetRepository.findAll(dataset.accessionRefs.any().accession.eq(accession).and(dataset.state.in(PublishState.PUBLISHED)));
return Lists.newArrayList(datasets);
}
......@@ -414,8 +418,8 @@ public class DatasetServiceImpl implements DatasetService {
throw new NotFoundElement("No such dataset");
}
if (dataset.getAccessionIdentifiers() != null) {
dataset.getAccessionIdentifiers().size();
if (dataset.getAccessionRefs() != null) {
dataset.getAccessionRefs().size();
}
if (dataset.getDescriptors() != null) {
dataset.getDescriptors().size();
......@@ -456,13 +460,13 @@ public class DatasetServiceImpl implements DatasetService {
@Transactional
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset upsertAccessions(final Dataset dataset, final Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement {
public Dataset upsertAccessions(final Dataset dataset, final Set<AccessionRef> accessionRefs) throws NotFoundElement {
final Dataset loadedDataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loadedDataset == null) {
throw new NotFoundElement("Dataset doesn't exist");
}
loadedDataset.setState(PublishState.DRAFT);
loadedDataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers)));
loadedDataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(accessionRefs)));
return lazyLoad(datasetRepository.save(loadedDataset));
}
......@@ -761,18 +765,18 @@ public class DatasetServiceImpl implements DatasetService {
}
/**
* Looking for matching Accession and then sets that to AccessionIdentifier
* Looking for matching Accession and then sets that to AccessionRef
*
* @param accessionIdentifiers the accessionIdentifiers
* @return accessionIdentifiers with matching accessions from Genesys
* @param accessionRefs the accessionRefs
* @return accessionRefs with matching accessions from Genesys
*/
private Set<AccessionIdentifier> lookupMatchingAccessions(final Set<AccessionIdentifier> accessionIdentifiers) {
List<AccessionIdentifier> list = new ArrayList<AccessionIdentifier>(accessionIdentifiers);
private Set<AccessionRef> lookupMatchingAccessions(final Set<AccessionRef> accessionRefs) {
List<AccessionRef> list = new ArrayList<AccessionRef>(accessionRefs);
List<Accession> foundAccessions = accessionRepository.findById(list);
LOG.info("Found {} matches for {} identifiers", foundAccessions.size(), accessionIdentifiers.size());
LOG.info("Found {} matches for {} identifiers", foundAccessions.size(), accessionRefs.size());
accessionIdentifiers.forEach(accei -> {
accessionRefs.forEach(accei -> {
Accession foundAccession = foundAccessions.stream().filter(a -> {
return StringUtils.equalsIgnoreCase(a.getInstCode(), accei.getInstCode())
&& (
......@@ -783,13 +787,13 @@ public class DatasetServiceImpl implements DatasetService {
(StringUtils.equalsIgnoreCase(a.getAccessionNumber(), accei.getAcceNumb()) && StringUtils.equalsIgnoreCase(a.getGenus(), accei.getGenus()))
);
}).findFirst().orElse(null);
accei.setAccession(foundAccession == null ? null : foundAccession.getAccessionId());
accei.setAccession(foundAccession);
if (foundAccession == null) {
LOG.debug("No match for {}", accei);
}
});
return accessionIdentifiers;
return accessionRefs;
}
......@@ -798,11 +802,11 @@ public class DatasetServiceImpl implements DatasetService {
public void rematchDatasetAccessions() {
datasetRepository.findAll().forEach(dataset -> {
LOG.warn("Linking {} accessions with dataset {}", dataset.getAccessionCount(), dataset.getId());
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(dataset.getAccessionIdentifiers())));
dataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(dataset.getAccessionRefs())));
datasetRepository.save(dataset);
});
}
/**
* {@inheritDoc}
......@@ -933,10 +937,10 @@ public class DatasetServiceImpl implements DatasetService {
target.setUserCountry(source.getUserCountry());
target.setMapCountry(source.getMapCountry());
target.setCountryCode(source.getCountryCode());
target.setStateProvince(source.getStateProvince());
target.setVerbatimLocality(source.getVerbatimLocality());
target.setDecimalLatitude(source.getDecimalLatitude());
target.setDecimalLongitude(source.getDecimalLongitude());
......
......@@ -231,8 +231,8 @@ public class AccessionController {
throw new ResourceNotFoundException();
}
List<Dataset> datasets = datasetService.listByAccession(accession.getAccessionId());
List<Subset> subsets = subsetService.listByAccession(accession.getAccessionId());
List<Dataset> datasets = datasetService.listByAccession(accession);
List<Subset> subsets = subsetService.listByAccession(accession);
AccessionDetailsJson accessionDetails = new AccessionDetailsJson();
accessionDetails.details = accession;
......
package org.genesys2.server.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.QDataset;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.QSubset;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.persistence.SubsetRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Aspect
@Component
public class AccessionAspect {
/** The Constant LOG. */
public static final Logger LOG = LoggerFactory.getLogger(AccessionAspect.class);
@Autowired
private DatasetRepository datasetRepository;
@Autowired
private SubsetRepository subsetRepository;
@Around(value = "execution(* org.genesys2.server.persistence.AccessionRepository.delete(*)) && args(accession)")
public Object aroundDeleteAccession(ProceedingJoinPoint joinPoint, Accession accession) throws Throwable {
LOG.debug("Around delete accession" + accession);
List<Dataset> datasets = (List<Dataset>) datasetRepository.findAll(QDataset.dataset.accessionRefs.any().accession.eq(accession));
for (Dataset dataset: datasets) {
dataset.getAccessionRefs().stream()
.filter(accessionRef -> accessionRef.getAccession().equals(accession))
.forEach(accessionRef -> accessionRef.setAccession(null));
datasetRepository.save(dataset);
}
List<Subset> subsets = (List<Subset>) subsetRepository.findAll(QSubset.subset.accessions.any().accession.eq(accession));
for (Subset subset: subsets) {
subset.getAccessions().stream()
.filter(accessionRef -> accessionRef.getAccession().equals(accession))
.forEach(accessionRef -> accessionRef.setAccession(null));
subsetRepository.save(subset);
}
return joinPoint.proceed();
}
@Around(value = "execution(* org.genesys2.server.persistence.AccessionRepository.save(*)) && args(accession)")
public Object aroundSaveAccession(ProceedingJoinPoint joinPoint, Accession accession) throws Throwable {
LOG.debug("Around save accession" + accession);
List<Dataset> datasets = (List<Dataset>) datasetRepository.findAll(
QDataset.dataset.accessionRefs.any().acceNumb.eq(accession.getAccessionNumber())
.and(QDataset.dataset.accessionRefs.any().genus.eq(accession.getGenus()))
.and(QDataset.dataset.accessionRefs.any().instCode.eq(accession.getInstCode()))
);
for (Dataset dataset: datasets) {
for (AccessionRef accRef: dataset.getAccessionRefs()) {
accRef.setAccession(accession);
LOG.debug("Setting accessionRef.id of {accRef} to {acceId} for dataset: {dataset}", accRef.toString(), accession.getId(), dataset.toString());
}
datasetRepository.save(dataset);
}
List<Subset> subsets = (List<Subset>) subsetRepository.findAll(
QSubset.subset.accessions.any().acceNumb.eq(accession.getAccessionNumber())
.and(QSubset.subset.accessions.any().genus.eq(accession.getGenus()))
.and(QSubset.subset.accessions.any().instCode.eq(accession.getInstCode()))
);
for (Subset subset: subsets) {
for (AccessionRef accRef: subset.getAccessions()) {
accRef.setAccession(accession);
LOG.debug("Setting accessionRef.id of {accRef} to {acceId} for subset: {subset}", accRef.toString(), subset.toString());
}
subsetRepository.save(subset);
}
return joinPoint.proceed();
}
}
......@@ -507,4 +507,17 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
public boolean getSgsv() {
return this.duplSiteStr != null && this.duplSiteStr.contains("NOR051");
}
// TODO Check if needed
public AccessionRef toAccessionRef(){
AccessionRef res = new AccessionRef();
res.setInstCode(getInstCode());
res.setGenus(getGenus());
res.setDoi(getDoi());
res.setAcceNumb(getAccessionNumber());
res.setSpecies(getTaxonomy().getSpecies());
res.setAccession((Accession) this);
return res;
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.catalog.model.dataset;
package org.genesys2.server.model.genesys;
import java.io.Serializable;
......@@ -23,14 +23,11 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys.blocks.model.JsonViews;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
/**
* Identifies an accession by it's INSTCODE, ACCENUMB and GENUS. Use of DOI
......@@ -38,9 +35,10 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
*
* @author Andrey Lugovskoy
* @author Matija Obreza
* @author Viacheslav Pavlov
*/
@Embeddable
public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
public class AccessionRef implements AccessionIdentifier3, Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
......@@ -68,10 +66,9 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
/** The accession. */
@ManyToOne(optional = true, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "accessionId", nullable = true)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
@JsonIdentityReference(alwaysAsId = true)
@JsonProperty(access = Access.READ_ONLY)
private AccessionId accession;
@JsonView({ JsonViews.Public.class })
private Accession accession;
/**
* Gets the doi.
......@@ -168,7 +165,7 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
*
* @return the accession
*/
public AccessionId getAccession() {
public Accession getAccession() {
return accession;
}
......@@ -177,7 +174,7 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
*
* @param accession the new accession
*/
public void setAccession(final AccessionId accession) {
public void setAccession(final Accession accession) {
this.accession = accession;
}
......@@ -224,7 +221,7 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
if (getClass() != obj.getClass()) {
return false;
}
final AccessionIdentifier other = (AccessionIdentifier) obj;
final AccessionRef other = (AccessionRef) obj;
if (acceNumb == null) {
if (other.acceNumb != null) {
return false;
......@@ -278,6 +275,6 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
@Override
public String toString() {
return "Dataset.AccessionIdentifier " + instCode + " " + acceNumb + " " + genus;