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; ...@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage; import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.exceptions.NotFoundElement; 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.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator; import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.dataset.DatasetLocation; import org.genesys.catalog.model.dataset.DatasetLocation;
...@@ -216,15 +216,15 @@ public class DatasetController { ...@@ -216,15 +216,15 @@ public class DatasetController {
* *
* @param uuid the uuid * @param uuid the uuid
* @param version the version * @param version the version
* @param accessionIdentifiers the accession identifiers * @param accessionRefs the accession identifiers
* @return the dataset * @return the dataset
* @throws NotFoundElement the not found element * @throws NotFoundElement the not found element
*/ */
@PostMapping(value = "/upsertaccessions/{UUID},{version}") @PostMapping(value = "/upsertaccessions/{UUID},{version}")
public Dataset upsertAccessions(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int 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); 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; ...@@ -32,7 +32,7 @@ import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.exceptions.InvalidApiUsageException; import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.model.Partner; 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.dataset.Dataset;
import org.genesys.catalog.model.filters.DatasetFilter; import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.traits.Descriptor; import org.genesys.catalog.model.traits.Descriptor;
...@@ -90,7 +90,7 @@ public class SearchController { ...@@ -90,7 +90,7 @@ public class SearchController {
Map<String, SearchResults<?>> suggestions = new HashMap<>(); 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.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.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))); suggestions.put("search.group.descriptor", SearchResults.from("uuid", Arrays.asList("descriptor.uuid"), hitsByEntity.get(Descriptor.class)));
// Search datasets // Search datasets
......
...@@ -29,6 +29,7 @@ import org.genesys.catalog.model.traits.Descriptor; ...@@ -29,6 +29,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface; import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile; import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
import org.genesys2.util.MCPDUtil; import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
...@@ -78,7 +79,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -78,7 +79,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") }) indexes = { @Index(columnList = "datasetId, instCode, acceNumb"), @Index(columnList = "datasetId, genus") })
@Field(type = FieldType.Object) @Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class }) @JsonView({ JsonViews.Public.class })
private Set<AccessionIdentifier> accessionIdentifiers; private Set<AccessionRef> accessionRefs;
/** The descriptors. */ /** The descriptors. */
@ManyToMany(fetch = FetchType.LAZY, cascade = {}) @ManyToMany(fetch = FetchType.LAZY, cascade = {})
...@@ -119,7 +120,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -119,7 +120,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private String endDate; private String endDate;
/** The accession count. */ /** The accession count. */
// Number of accessions in the {@link #accessionIdentifiers} list // Number of accessions in the {@link #accessionRefs} list
@Column(name = "accessions") @Column(name = "accessions")
private Integer accessionCount; private Integer accessionCount;
...@@ -188,8 +189,8 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -188,8 +189,8 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@PreUpdate @PreUpdate
@PrePersist @PrePersist
private void preupdate() { private void preupdate() {
if (accessionIdentifiers != null) { if (accessionRefs != null) {
this.accessionCount = accessionIdentifiers.size(); this.accessionCount = accessionRefs.size();
} }
if (descriptors != null) { if (descriptors != null) {
this.descriptorCount = descriptors.size(); this.descriptorCount = descriptors.size();
...@@ -515,19 +516,19 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -515,19 +516,19 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
/** /**
* Gets the accession identifiers. * Gets the accession identifiers.
* *
* @return the accessionIdentifiers * @return the accessionRefs
*/ */
public final Set<AccessionIdentifier> getAccessionIdentifiers() { public final Set<AccessionRef> getAccessionRefs() {
return accessionIdentifiers; return accessionRefs;
} }
/** /**
* Sets the accession identifiers. * Sets the accession identifiers.
* *
* @param accessionIdentifiers the accessionIdentifiers to set * @param accessionRefs the accessionRefs to set
*/ */
public final void setAccessionIdentifiers(final Set<AccessionIdentifier> accessionIdentifiers) { public final void setAccessionRefs(final Set<AccessionRef> accessionRefs) {
this.accessionIdentifiers = accessionIdentifiers; this.accessionRefs = accessionRefs;
} }
/** /**
......
...@@ -19,19 +19,19 @@ import java.util.HashSet; ...@@ -19,19 +19,19 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.genesys.blocks.model.filters.StringFilter; import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.catalog.model.dataset.AccessionIdentifier; import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys.catalog.model.dataset.QAccessionIdentifier;
import com.querydsl.core.BooleanBuilder; import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate; import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.SetPath; import com.querydsl.core.types.dsl.SetPath;
import org.genesys2.server.model.genesys.QAccessionRef;
/** /**
* The Class AccessionIdentifierFilter. * The Class AccessionRefFilter.
* *
* @author Matija Obreza * @author Matija Obreza
*/ */
public class AccessionIdentifierFilter { public class AccessionRefFilter {
/** The doi. */ /** The doi. */
public Set<String> doi; public Set<String> doi;
...@@ -54,10 +54,10 @@ public class AccessionIdentifierFilter { ...@@ -54,10 +54,10 @@ public class AccessionIdentifierFilter {
* @param accessionIdentifiers the accession identifiers * @param accessionIdentifiers the accession identifiers
* @return the predicate * @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 BooleanBuilder and = new BooleanBuilder();
final QAccessionIdentifier identifier = accessionIdentifiers.any(); final QAccessionRef identifier = accessionIdentifiers.any();
if (doi != null && !doi.isEmpty()) { if (doi != null && !doi.isEmpty()) {
and.and(identifier.doi.in(doi)); and.and(identifier.doi.in(doi));
} }
...@@ -83,7 +83,7 @@ public class AccessionIdentifierFilter { ...@@ -83,7 +83,7 @@ public class AccessionIdentifierFilter {
* @param value the instCode to add * @param value the instCode to add
* @return the updated filter * @return the updated filter
*/ */
public AccessionIdentifierFilter instCode(final String value) { public AccessionRefFilter instCode(final String value) {
if (instCode == null) { if (instCode == null) {
instCode = new HashSet<>(); instCode = new HashSet<>();
} }
...@@ -97,7 +97,7 @@ public class AccessionIdentifierFilter { ...@@ -97,7 +97,7 @@ public class AccessionIdentifierFilter {
* @param value the doi to add * @param value the doi to add
* @return the updated filter * @return the updated filter
*/ */
public AccessionIdentifierFilter doi(final String value) { public AccessionRefFilter doi(final String value) {
if (doi == null) { if (doi == null) {
doi = new HashSet<>(); doi = new HashSet<>();
} }
...@@ -111,7 +111,7 @@ public class AccessionIdentifierFilter { ...@@ -111,7 +111,7 @@ public class AccessionIdentifierFilter {
* @param value the genus to add * @param value the genus to add
* @return the updated filter * @return the updated filter
*/ */
public AccessionIdentifierFilter genus(final String value) { public AccessionRefFilter genus(final String value) {
if (genus == null) { if (genus == null) {
genus = new HashSet<>(); genus = new HashSet<>();
} }
......
...@@ -46,7 +46,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> { ...@@ -46,7 +46,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
public PartnerFilter owner; public PartnerFilter owner;
/** The accession identifier. */ /** The accession identifier. */
public AccessionIdentifierFilter accessionIdentifier; public AccessionRefFilter accessionIdentifier;
public DatasetLocationFilter location; public DatasetLocationFilter location;
...@@ -91,7 +91,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> { ...@@ -91,7 +91,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
and.and(owner.buildQuery(dataset.owner)); and.and(owner.buildQuery(dataset.owner));
} }
if (accessionIdentifier != null) { if (accessionIdentifier != null) {
and.and(accessionIdentifier.buildQuery(dataset.accessionIdentifiers)); and.and(accessionIdentifier.buildQuery(dataset.accessionRefs));
} }
if (descriptor != null) { if (descriptor != null) {
and.and(descriptor.buildQuery(dataset.descriptors.any())); and.and(descriptor.buildQuery(dataset.descriptors.any()));
...@@ -120,7 +120,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> { ...@@ -120,7 +120,7 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
dataset.owner.shortName, dataset.owner.shortName,
dataset.crops.any(), dataset.crops.any(),
dataset.descriptors.any().crop, 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, FilterHelpers.containsAll(_text,
dataset.title, dataset.description, dataset.title, dataset.description,
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
package org.genesys.catalog.service; package org.genesys.catalog.service;
import org.genesys.catalog.exceptions.NotFoundElement; 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.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator; import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.dataset.DatasetLocation; import org.genesys.catalog.model.dataset.DatasetLocation;
...@@ -63,13 +64,13 @@ public interface DatasetService { ...@@ -63,13 +64,13 @@ public interface DatasetService {
Dataset updateDataset(Dataset input); Dataset updateDataset(Dataset input);
/** /**
* Method updating accessionIdentifiers in Dataset. * Method updating accessionRefs in Dataset.
* *
* @param dataset the dataset * @param dataset the dataset
* @param accessionIdentifiers new accessionIdentifiers * @param accessionRefs new accessionRefs
* @return updated Dataset in db. * @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. * Method adding new descriptor to Dataset.
...@@ -118,10 +119,10 @@ public interface DatasetService { ...@@ -118,10 +119,10 @@ public interface DatasetService {
/** /**
* List published datasets by accession. * List published datasets by accession.
* *
* @param accessionId the accessionId * @param accession the accession
* @return list of Dataset * @return list of Dataset
*/ */
List<Dataset> listByAccession(AccessionId accessionId); List<Dataset> listByAccession(Accession accession);
/** /**
* List published datasets matching the filter. * List published datasets matching the filter.
...@@ -204,11 +205,11 @@ public interface DatasetService { ...@@ -204,11 +205,11 @@ public interface DatasetService {
* Register Accession identifiers with the Dataset. * Register Accession identifiers with the Dataset.
* *
* @param dataset the dataset * @param dataset the dataset
* @param accessionIdentifiers the accessionIdentifiers * @param accessionRefs the accessionRefs
* @return updated Dataset * @return updated Dataset
* @throws NotFoundElement the not found element * @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. * Puts the dataset into the Review state to be reviewed by admin.
......
...@@ -35,6 +35,10 @@ import org.genesys.blocks.security.service.CustomAclService; ...@@ -35,6 +35,10 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.exceptions.InvalidApiUsageException; import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement; import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.Partner; 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.dataset.*;
import org.genesys.catalog.model.filters.DatasetFilter; import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.traits.Descriptor; import org.genesys.catalog.model.traits.Descriptor;
...@@ -140,8 +144,8 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -140,8 +144,8 @@ public class DatasetServiceImpl implements DatasetService {
dataset.setLocations(new ArrayList<>()); dataset.setLocations(new ArrayList<>());
dataset.setCrops(source.getCrops()); dataset.setCrops(source.getCrops());
if (source.getAccessionIdentifiers() != null && !source.getAccessionIdentifiers().isEmpty()) { if (source.getAccessionRefs() != null && !source.getAccessionRefs().isEmpty()) {
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(source.getAccessionIdentifiers()))); dataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(source.getAccessionRefs())));
} }
copyDescriptors(dataset, source.getDescriptors()); copyDescriptors(dataset, source.getDescriptors());
...@@ -185,11 +189,11 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -185,11 +189,11 @@ public class DatasetServiceImpl implements DatasetService {
@Override @Override
@Transactional @Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset updateAccessionIdentifiers(Dataset dataset, final Set<AccessionIdentifier> accessionIdentifiers) { public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionIdentifiers {}", dataset, accessionIdentifiers); LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs);
dataset = loadDataset(dataset); dataset = loadDataset(dataset);
dataset.getAccessionIdentifiers().clear(); dataset.getAccessionRefs().clear();
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers))); dataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(accessionRefs)));
return lazyLoad(datasetRepository.save(dataset)); return lazyLoad(datasetRepository.save(dataset));
} }
...@@ -342,8 +346,8 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -342,8 +346,8 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public List<Dataset> listByAccession(final AccessionId accessionId) { public List<Dataset> listByAccession(final Accession accession) {
final Iterable<Dataset> datasets = datasetRepository.findAll(dataset.accessionIdentifiers.any().accession.eq(accessionId).and(dataset.state.in(PublishState.PUBLISHED))); final Iterable<Dataset> datasets = datasetRepository.findAll(dataset.accessionRefs.any().accession.eq(accession).and(dataset.state.in(PublishState.PUBLISHED)));
return Lists.newArrayList(datasets); return Lists.newArrayList(datasets);
} }
...@@ -414,8 +418,8 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -414,8 +418,8 @@ public class DatasetServiceImpl implements DatasetService {
throw new NotFoundElement("No such dataset"); throw new NotFoundElement("No such dataset");
} }
if (dataset.getAccessionIdentifiers() != null) { if (dataset.getAccessionRefs() != null) {
dataset.getAccessionIdentifiers().size(); dataset.getAccessionRefs().size();
} }
if (dataset.getDescriptors() != null) { if (dataset.getDescriptors() != null) {
dataset.getDescriptors().size(); dataset.getDescriptors().size();
...@@ -456,13 +460,13 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -456,13 +460,13 @@ public class DatasetServiceImpl implements DatasetService {
@Transactional @Transactional
@Override @Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')") @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()); final Dataset loadedDataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loadedDataset == null) { if (loadedDataset == null) {
throw new NotFoundElement("Dataset doesn't exist"); throw new NotFoundElement("Dataset doesn't exist");
} }
loadedDataset.setState(PublishState.DRAFT); loadedDataset.setState(PublishState.DRAFT);
loadedDataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers))); loadedDataset.setAccessionRefs(lookupMatchingAccessions(new HashSet<>(accessionRefs)));
return lazyLoad(datasetRepository.save(loadedDataset)); return lazyLoad(datasetRepository.save(loadedDataset));
} }
...@@ -761,18 +765,18 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -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 * @param accessionRefs the accessionRefs
* @return accessionIdentifiers with matching accessions from Genesys * @return accessionRefs with matching accessions from Genesys
*/ */
private Set<AccessionIdentifier> lookupMatchingAccessions(final Set<AccessionIdentifier> accessionIdentifiers) { private Set<AccessionRef> lookupMatchingAccessions(final Set<AccessionRef> accessionRefs) {
List<AccessionIdentifier> list = new ArrayList<AccessionIdentifier>(accessionIdentifiers); List<AccessionRef> list = new ArrayList<AccessionRef>(accessionRefs);
List<Accession> foundAccessions = accessionRepository.findById(list); 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 -> { Accession foundAccession = foundAccessions.stream().filter(a -> {
return StringUtils.equalsIgnoreCase(a.getInstCode(), accei.getInstCode()) return StringUtils.equalsIgnoreCase(a.getInstCode(), accei.getInstCode())
&& ( && (
...@@ -783,13 +787,13 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -783,13 +787,13 @@ public class DatasetServiceImpl implements DatasetService {
(StringUtils.equalsIgnoreCase(a.getAccessionNumber(), accei.getAcceNumb()) && StringUtils.equalsIgnoreCase(a.getGenus(), accei.getGenus())) (StringUtils.equalsIgnoreCase(a.getAccessionNumber(), accei.getAcceNumb()) && StringUtils.equalsIgnoreCase(a.getGenus(), accei.getGenus()))
); );
}).findFirst().orElse(null); }).findFirst().orElse(null);
accei.setAccession(foundAccession == null ? null : foundAccession.getAccessionId()); accei.setAccession(foundAccession);
if (foundAccession == null) { if (foundAccession == null) {
LOG.debug("No match for {}", accei); LOG.debug("No match for {}", accei);
} }
}); });
return accessionIdentifiers; return accessionRefs;
} }
...@@ -798,11 +802,11 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -798,11 +802,11 @@ public class DatasetServiceImpl implements DatasetService {
public void rematchDatasetAccessions() { public void rematchDatasetAccessions() {
datasetRepository.findAll().forEach(dataset -> { datasetRepository.findAll().forEach(dataset -> {
LOG.warn("Linking {} accessions with dataset {}", dataset.getAccessionCount(), dataset.getId()); 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); datasetRepository.save(dataset);
}); });
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
...@@ -933,10 +937,10 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -933,10 +937,10 @@ public class DatasetServiceImpl implements DatasetService {
target.setUserCountry(source.getUserCountry()); target.setUserCountry(source.getUserCountry());
target.setMapCountry(source.getMapCountry()); target.setMapCountry(source.getMapCountry());
target.setCountryCode(source.getCountryCode()); target.setCountryCode(source.getCountryCode());
target.setStateProvince(source.getStateProvince()); target.setStateProvince(source.getStateProvince());
target.setVerbatimLocality(source.getVerbatimLocality());