Commit 35949951 authored by Matija Obreza's avatar Matija Obreza

Merge branch '113-genesys-ui-updated-apis' into 'master'

Resolve "Subset and Dataset accession lists: server-side"

See merge request genesys-pgr/genesys-server!284
parents b440b739 9396a52c
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
*/ */
package org.genesys.catalog.model.dataset; package org.genesys.catalog.model.dataset;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.auditlog.annotations.Audited; import org.genesys.blocks.auditlog.annotations.Audited;
...@@ -36,10 +40,6 @@ import org.springframework.data.elasticsearch.annotations.Document; ...@@ -36,10 +40,6 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
/** /**
* {@link Dataset} captures the metadata information as a snapshot. Multiple * {@link Dataset} captures the metadata information as a snapshot. Multiple
* versions of the versions may exist. * versions of the versions may exist.
...@@ -78,7 +78,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -78,7 +78,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
// index // index
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.Minimal.class }) @JsonIgnore
private Set<AccessionRef> accessionRefs; private Set<AccessionRef> accessionRefs;
/** The descriptors. */ /** The descriptors. */
......
...@@ -117,6 +117,15 @@ public interface DatasetService { ...@@ -117,6 +117,15 @@ public interface DatasetService {
*/ */
Dataset loadDataset(UUID uuid, int version); Dataset loadDataset(UUID uuid, int version);
/**
* Load AccessionRef list by Dataset.
*
* @param dataset the dataset
* @param page Pageable
* @return PageImpl of AccessionRef
*/
Page<AccessionRef> listAccessions(Dataset dataset, Pageable page);
/** /**
* List published datasets by accession. * List published datasets by accession.
* *
......
...@@ -25,6 +25,7 @@ import java.nio.file.Paths; ...@@ -25,6 +25,7 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -33,6 +34,7 @@ import java.util.UUID; ...@@ -33,6 +34,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.lang3.time.StopWatch;
import org.genesys.blocks.security.service.CustomAclService; import org.genesys.blocks.security.service.CustomAclService;
...@@ -166,10 +168,6 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -166,10 +168,6 @@ public class DatasetServiceImpl implements DatasetService {
dataset.setLocations(new ArrayList<>()); dataset.setLocations(new ArrayList<>());
dataset.setCrops(source.getCrops()); dataset.setCrops(source.getCrops());
if (source.getAccessionRefs() != null && !source.getAccessionRefs().isEmpty()) {
dataset.setAccessionRefs(lookupMatchingAccessions(source.getAccessionRefs()));
}
copyDescriptors(dataset, source.getDescriptors()); copyDescriptors(dataset, source.getDescriptors());
dataset = datasetRepository.save(dataset); dataset = datasetRepository.save(dataset);
...@@ -229,7 +227,9 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -229,7 +227,9 @@ public class DatasetServiceImpl implements DatasetService {
public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) { public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs); LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs);
dataset = loadDataset(dataset); dataset = loadDataset(dataset);
dataset.getAccessionRefs().clear(); if (dataset.getAccessionRefs() != null && !dataset.getAccessionRefs().isEmpty()) {
dataset.getAccessionRefs().clear();
}
dataset.setAccessionRefs(lookupMatchingAccessions(accessionRefs)); dataset.setAccessionRefs(lookupMatchingAccessions(accessionRefs));
return lazyLoad(datasetRepository.save(dataset)); return lazyLoad(datasetRepository.save(dataset));
} }
...@@ -379,6 +379,26 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -379,6 +379,26 @@ public class DatasetServiceImpl implements DatasetService {
return lazyLoad(dataset); return lazyLoad(dataset);
} }
/**
* {@inheritDoc}
*/
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || dataset.published || hasPermission(dataset, 'read')")
public Page<AccessionRef> listAccessions(Dataset dataset, final Pageable page) {
dataset = loadDataset(dataset);
final List<AccessionRef> accessionRefs = new ArrayList<AccessionRef>(dataset.getAccessionRefs());
if (CollectionUtils.isEmpty(accessionRefs)) {
return new PageImpl<>(Collections.emptyList(), page, 0);
}
accessionRefs.sort((a, b) -> a.getAcceNumb().compareTo(b.getAcceNumb()));
int fromIndex = Math.multiplyExact(page.getPageNumber(), page.getPageSize());
int toIndex = Math.min(fromIndex + page.getPageSize(), accessionRefs.size());
return new PageImpl<>(accessionRefs.subList(fromIndex, toIndex), page, accessionRefs.size());
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
...@@ -463,9 +483,6 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -463,9 +483,6 @@ public class DatasetServiceImpl implements DatasetService {
throw new NotFoundElement("No such dataset"); throw new NotFoundElement("No such dataset");
} }
if (dataset.getAccessionRefs() != null) {
dataset.getAccessionRefs().size();
}
if (dataset.getDescriptors() != null) { if (dataset.getDescriptors() != null) {
dataset.getDescriptors().size(); dataset.getDescriptors().size();
} }
......
...@@ -387,7 +387,7 @@ public class AccessionController { ...@@ -387,7 +387,7 @@ public class AccessionController {
public String[] tileServers; public String[] tileServers;
} }
private static class AccessionOverview { public static class AccessionOverview {
public String filterCode; public String filterCode;
public AccessionFilter filter; public AccessionFilter filter;
public Map<String, TermResult> overview; public Map<String, TermResult> overview;
......
...@@ -218,6 +218,20 @@ public class DatasetController extends ApiBaseController { ...@@ -218,6 +218,20 @@ public class DatasetController extends ApiBaseController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, datasetService.listDatasets(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id"))); return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, datasetService.listDatasets(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
} }
/**
* Load AccessionRef list by Dataset
*
* @param uuid uuid of Dataset
* @param page Pageable
* @return the page
* @throws NotFoundElement
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<AccessionRef> listAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
return datasetService.listAccessions(datasetService.loadDataset(uuid), page.toPageRequest(100));
}
/** /**
* Removes the descriptors. * Removes the descriptors.
* *
......
...@@ -20,18 +20,22 @@ import java.io.IOException; ...@@ -20,18 +20,22 @@ import java.io.IOException;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService; import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo; import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage; import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination; import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset; import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.InstituteService; import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SubsetService; import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.SubsetFilter; import org.genesys2.server.service.filter.SubsetFilter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -161,6 +165,20 @@ public class SubsetController { ...@@ -161,6 +165,20 @@ public class SubsetController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, subsetService.listSubsetsForCurrentUser(filterInfo.filter, page.toPageRequest(100, Sort.Direction.DESC, "lastModifiedDate"))); return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, subsetService.listSubsetsForCurrentUser(filterInfo.filter, page.toPageRequest(100, Sort.Direction.DESC, "lastModifiedDate")));
} }
/**
* Load AccessionRef list by Subset
*
* @param uuid uuid of Subset
* @param page Pageable
* @return the page
* @throws NotFoundElement
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<AccessionRef> listAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
return subsetService.listAccessions(subsetService.get(uuid), page.toPageRequest(100));
}
/** /**
* Remove accessions form subset. * Remove accessions form subset.
* *
......
...@@ -47,6 +47,7 @@ import org.hibernate.annotations.Type; ...@@ -47,6 +47,7 @@ import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
/** /**
...@@ -94,7 +95,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning { ...@@ -94,7 +95,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
// index // index
indexes = { @Index(columnList = "subsetId, instCode, acceNumb"), @Index(columnList = "subsetId, genus") }) indexes = { @Index(columnList = "subsetId, instCode, acceNumb"), @Index(columnList = "subsetId, genus") })
@Field(type = FieldType.Object) @Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class }) @JsonIgnore
private Set<AccessionRef> accessionRefs; private Set<AccessionRef> accessionRefs;
/** The accession count. */ /** The accession count. */
......
...@@ -88,30 +88,36 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -88,30 +88,36 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
cq.distinct(true); cq.distinct(true);
cq.select(root.get("id")); cq.select(root.get("id"));
List<Predicate> restrictions = new ArrayList<Predicate>(); List<Accession> res = new ArrayList<>(forUpdate.size());
Set<String> uniqueDois = forUpdate.stream().map(aid -> aid.getDoi()).filter(doi -> doi != null).distinct().collect(Collectors.toSet());
Path<Object> theDoi = root.get("doi"); final int chunkSize = 200;
Path<Object> theInstCode = root.get("instituteCode"); for (int fromIndex = 0; fromIndex < forUpdate.size(); fromIndex += chunkSize) {
Path<Object> theAcceNumb = root.get("accessionNumber"); List<? extends AccessionIdentifier3> sublist = forUpdate.subList(fromIndex, Math.min(forUpdate.size(), fromIndex + chunkSize));
Path<Object> theGenus = root.get("genus");
if (uniqueDois.size() > 0) { List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(theDoi.in(uniqueDois)); Set<String> uniqueDois = sublist.stream().map(aid -> aid.getDoi()).filter(doi -> doi != null).distinct().collect(Collectors.toSet());
LOG.trace("*** {} dois={}", uniqueDois.size(), uniqueDois);
} Path<Object> theDoi = root.get("doi");
Path<Object> theInstCode = root.get("instituteCode");
// A lot of .. (instCode=? and acceNumb=? and genus=?) Path<Object> theAcceNumb = root.get("accessionNumber");
for (AccessionIdentifier3 ah : forUpdate) { Path<Object> theGenus = root.get("genus");
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah
.getAccessionNumber()), criteriaBuilder.equal(theGenus, ah.getGenus()))); if (uniqueDois.size() > 0) {
restrictions.add(theDoi.in(uniqueDois));
LOG.trace("*** {} dois={}", uniqueDois.size(), uniqueDois);
}
// A lot of .. (instCode=? and acceNumb=? and genus=?)
for (AccessionIdentifier3 ah : sublist) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah
.getAccessionNumber()), criteriaBuilder.equal(theGenus, ah.getGenus())));
}
cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)));
res.addAll(jpaQueryFactory.selectFrom(QAccession.accession).where(QAccession.accession.id.in(em.createQuery(cq).getResultList())).fetch());
} }
cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)));
List<Accession> res = jpaQueryFactory.selectFrom(QAccession.accession).where(QAccession.accession.id.in(em.createQuery(cq).getResultList())).fetch();
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.trace("*** Loaded accessions {} of {}", res.size(), forUpdate.size()); LOG.trace("*** Loaded accessions {} of {}", res.size(), forUpdate.size());
......
...@@ -23,6 +23,7 @@ import java.util.UUID; ...@@ -23,6 +23,7 @@ import java.util.UUID;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset; import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.model.impl.SubsetCreator; import org.genesys2.server.model.impl.SubsetCreator;
...@@ -44,6 +45,15 @@ public interface SubsetService { ...@@ -44,6 +45,15 @@ public interface SubsetService {
*/ */
Page<Subset> list(SubsetFilter filter, Pageable page); Page<Subset> list(SubsetFilter filter, Pageable page);
/**
* Load AccessionRef list by Subset.
*
* @param subset the subset
* @param page Pageable
* @return PageImpl of AccessionRef
*/
Page<AccessionRef> listAccessions(Subset subset, Pageable page);
/** /**
* Count published subsets. * Count published subsets.
* *
......
...@@ -27,6 +27,7 @@ import java.util.Set; ...@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.model.dataset.Dataset; import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService; import org.genesys.catalog.service.DatasetService;
...@@ -186,14 +187,23 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -186,14 +187,23 @@ public class AccessionServiceImpl implements AccessionService {
@Override @Override
public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) { public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) {
if (CollectionUtils.isEmpty(identifiers)) {
return Collections.emptyMap();
}
Map<UUID, AccessionIdentifier3> res = new HashMap<>(); Map<UUID, AccessionIdentifier3> res = new HashMap<>();
List<Accession> foundAccessions = accessionRepository.find(identifiers);
final int chunkSize = 200;
for (Accession accession : foundAccessions) { for (int fromIndex = 0; fromIndex < identifiers.size(); fromIndex += chunkSize) {
Optional<? extends AccessionIdentifier3> toPut = identifiers.stream().filter(id -> id.getAccessionNumber().equals(accession.getAccessionNumber()) && id.getGenus() List<Accession> foundAccessions = accessionRepository.find(identifiers.subList(fromIndex, Math.min(identifiers.size(), fromIndex + chunkSize)));
.equals(accession.getGenus()) && id.getHoldingInstitute().equals(accession.getInstCode())).findFirst(); for (Accession accession : foundAccessions) {
Optional<? extends AccessionIdentifier3> toPut = identifiers.stream().filter(id -> id.getAccessionNumber().equals(accession.getAccessionNumber()) && id.getGenus()
.equals(accession.getGenus()) && id.getHoldingInstitute().equals(accession.getInstCode())).findFirst();
toPut.ifPresent(accessionIdentifier3 -> res.put(accession.getUuid(), accessionIdentifier3)); toPut.ifPresent(accessionIdentifier3 -> res.put(accession.getUuid(), accessionIdentifier3));
}
} }
return res; return res;
...@@ -201,13 +211,17 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -201,13 +211,17 @@ public class AccessionServiceImpl implements AccessionService {
@Override @Override
public List<Accession> forUuids(Set<UUID> uuids) { public List<Accession> forUuids(Set<UUID> uuids) {
final int chunkSize = 100;
List<UUID> uuidList = new ArrayList<>(uuids); if (CollectionUtils.isEmpty(uuids)) {
List<Accession> accessions = new ArrayList<>(uuidList.size()); return Collections.emptyList();
}
List<UUID> uuidList = new ArrayList<>(uuids);
List<Accession> accessions = new ArrayList<>(uuids.size());
for (int i = 0; i < uuids.size(); i+= chunkSize){ final int chunkSize = 200;
List<UUID> chunk = uuidList.subList(i, Math.min(uuids.size(), i+chunkSize)); for (int fromIndex = 0; fromIndex < uuids.size(); fromIndex+= chunkSize){
List<UUID> chunk = uuidList.subList(fromIndex, Math.min(uuids.size(), fromIndex+chunkSize));
accessions.addAll((List<Accession>) accessionRepository.findAll(QAccession.accession.accessionId.uuid.in(chunk))); accessions.addAll((List<Accession>) accessionRepository.findAll(QAccession.accession.accessionId.uuid.in(chunk)));
} }
......
...@@ -20,6 +20,7 @@ import static org.genesys2.server.model.impl.QSubsetCreator.subsetCreator; ...@@ -20,6 +20,7 @@ import static org.genesys2.server.model.impl.QSubsetCreator.subsetCreator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -27,6 +28,7 @@ import java.util.UUID; ...@@ -27,6 +28,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.exception.InvalidApiUsageException; import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
...@@ -105,6 +107,23 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -105,6 +107,23 @@ public class SubsetServiceImpl implements SubsetService {
return subsetRepository.findAll(published, page); return subsetRepository.findAll(published, page);
} }
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || subset.published || hasPermission(subset, 'read')")
public Page<AccessionRef> listAccessions(Subset subset, final Pageable page) {
subset = loadSubset(subset);
final List<AccessionRef> accessionRefs = new ArrayList<AccessionRef>(subset.getAccessionRefs());
if (CollectionUtils.isEmpty(accessionRefs)) {
return new PageImpl<>(Collections.emptyList(), page, 0);
}
accessionRefs.sort((a, b) -> a.getAcceNumb().compareTo(b.getAcceNumb()));
int fromIndex = Math.multiplyExact(page.getPageNumber(), page.getPageSize());
int toIndex = Math.min(fromIndex + page.getPageSize(), accessionRefs.size());
return new PageImpl<>(accessionRefs.subList(fromIndex, toIndex), page, accessionRefs.size());
}
@Override @Override
public long countSubsets(SubsetFilter filter) { public long countSubsets(SubsetFilter filter) {
return subsetRepository.count(filter.buildQuery()); return subsetRepository.count(filter.buildQuery());
...@@ -138,33 +157,10 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -138,33 +157,10 @@ public class SubsetServiceImpl implements SubsetService {
} }
final Subset subset = new Subset(); final Subset subset = new Subset();
copyValues(subset, source); copyValues(subset, source);
copyAccessions(subset, source.getAccessionRefs());
subset.setState(PublishState.DRAFT); subset.setState(PublishState.DRAFT);
return deepLoad(subsetRepository.save(subset)); return deepLoad(subsetRepository.save(subset));
} }
/**
* Copy subset accessions.
*
* @param target the target
* @param list the subset accessions
*/
private void copyAccessions(final Subset target, final Set<AccessionRef> list) {
if ((list == null) || (list.size() == 0)) {
if (target.getAccessionRefs() != null)
target.getAccessionRefs().clear();
return;
}
if (target.getAccessionRefs() != null && !target.getAccessionRefs().isEmpty()) {
target.getAccessionRefs().clear();
} else {
target.setAccessionRefs(new HashSet<>());
}
target.getAccessionRefs().addAll(list);
}
/** /**
* Copy values. * Copy values.
* *
...@@ -203,9 +199,7 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -203,9 +199,7 @@ public class SubsetServiceImpl implements SubsetService {
subset.getInstitute().getId(); subset.getInstitute().getId();
if (subset.getCrops() != null) if (subset.getCrops() != null)
subset.getCrops().size(); subset.getCrops().size();
if (subset.getAccessionRefs() != null)
subset.getAccessionRefs().size();
if (subset.getCreators() != null) if (subset.getCreators() != null)
subset.getCreators().size(); subset.getCreators().size();
...@@ -260,9 +254,6 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -260,9 +254,6 @@ public class SubsetServiceImpl implements SubsetService {
public Subset update(final Subset source) { public Subset update(final Subset source) {
LOG.info("Update Subset."); LOG.info("Update Subset.");
final Subset subset = loadSubset(source); final Subset subset = loadSubset(source);
subset.getAccessionRefs().clear();
copyAccessions(subset, source.getAccessionRefs());
copyValues(subset, source); copyValues(subset, source);
return deepLoad(subsetRepository.save(subset)); return deepLoad(subsetRepository.save(subset));
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
*/ */
package org.genesys.test.catalog.services; package org.genesys.test.catalog.services;
import java.util.List;
import java.util.Set;
import org.genesys.catalog.model.Partner; import org.genesys.catalog.model.Partner;
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;
...@@ -26,25 +23,14 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository; ...@@ -26,25 +23,14 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository; import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.service.DatasetService; import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.persistence.RepositoryFilePersistence; import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef; import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionRepository; import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository; import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.worker.AccessionUploader;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public abstract class AbstractDatasetServiceTest extends CatalogServiceTest { public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
protected static final String TEST_INSTCODE = "XYZ001"; protected static final String TEST_INSTCODE = "XYZ001";
...@@ -73,10 +59,6 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest { ...@@ -73,10 +59,6 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
protected AccessionRepository accessionRepository; protected AccessionRepository accessionRepository;
@Autowired @Autowired
protected FaoInstituteRepository instituteRepository; protected FaoInstituteRepository instituteRepository;
@Autowired
private InstituteService instituteService;
@Autowired
private AccessionUploader accessionUploader;
public AbstractDatasetServiceTest() { public AbstractDatasetServiceTest() {
super(); super();
...@@ -95,22 +77,16 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest { ...@@ -95,22 +77,16 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {