...
 
Commits (46)
......@@ -186,8 +186,8 @@ public class DescriptorController {
final Descriptor descriptor = descriptorService.getDescriptor(uuid);
return new Object() {
public List<DescriptorList> descriptorLists = descriptorService.getDescriptorLists(descriptor);
public List<Dataset> datasets = descriptorService.getDatasets(descriptor);
public List<DescriptorList> descriptorLists = descriptor.getDescriptorLists();
public List<Dataset> datasets = descriptor.getDatasets();
};
}
......
......@@ -17,12 +17,9 @@ package org.genesys.catalog.persistence;
import org.genesys.catalog.model.Partner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
/**
......@@ -55,13 +52,4 @@ public interface PartnerRepository extends JpaRepository<Partner, Long>, QueryDs
* @return the partner
*/
Partner findByUuidAndVersion(UUID uuid, int version);
/**
* Load list by ids.
*
* @param ids the ids
* @return the list
*/
@Query("select distinct p from Partner p where p.id in :ids")
List<Partner> loadListByIds(@Param("ids") List<Long> ids);
}
......@@ -16,12 +16,8 @@
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.UUID;
......@@ -41,14 +37,4 @@ public interface DatasetCreatorRepository extends JpaRepository<DatasetCreator,
* @return the dataset creator
*/
DatasetCreator findByUuid(UUID uuid);
/**
* List by U uid of dataset.
*
* @param page the page
* @param uuid the uuid
* @return the page
*/
@Query("select distinct dc from DatasetCreator dc where dc.dataset.uuid = :uuid")
Page<DatasetCreator> listByUUidOfDataset(Pageable page, @Param("uuid") UUID uuid);
}
......@@ -16,12 +16,8 @@
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.DatasetLocation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.UUID;
......@@ -41,15 +37,4 @@ public interface DatasetLocationRepository extends JpaRepository<DatasetLocation
* @return the location
*/
DatasetLocation findByUuid(UUID uuid);
/**
* List by U uid of dataset.
*
* @param page the page
* @param uuid the uuid
* @return the page
*/
@Query("select distinct loc from DatasetLocation loc where loc.dataset.uuid = :uuid")
Page<DatasetLocation> listByUUidOfDataset(Pageable page, @Param("uuid") UUID uuid);
}
......@@ -16,15 +16,10 @@
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.Dataset;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
/**
......@@ -50,29 +45,4 @@ public interface DatasetRepository extends JpaRepository<Dataset, Long>, QueryDs
*/
Dataset findByUuidAndVersion(UUID uuid, int version);
/**
* List all current version.
*
* @param page the page
* @return the page
*/
@Query("select distinct d from Dataset d where d.versions.currentVersion.uuid = d.uuid")
Page<Dataset> listAllCurrentVersion(Pageable page);
/**
* Load list by ids.
*
* @param ids the ids
* @return the list
*/
@Query("select distinct d from Dataset d where d.id in :ids")
List<Dataset> loadListByIds(@Param("ids") List<Long> ids);
/**
* Load data about last published datasets.
*
* @return the data about last published datasets
*/
@Query("select year(d.lastModifiedDate), month(d.lastModifiedDate), day(d.lastModifiedDate), d.title, d.uuid, d.owner.shortName from Dataset d where d.state = 1 order by year(d.lastModifiedDate) desc, month(d.lastModifiedDate) desc, day(d.lastModifiedDate) desc")
List<Object[]> lastPublished();
}
......@@ -15,16 +15,11 @@
*/
package org.genesys.catalog.persistence.traits;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
/**
......@@ -49,22 +44,4 @@ public interface DescriptorRepository extends JpaRepository<Descriptor, Long>, Q
* @return the descriptor
*/
Descriptor findByUuidAndVersion(UUID uuid, int version);
/**
* List descriptor lists.
*
* @param descriptor the descriptor
* @return the list
*/
@Query("select d.descriptorLists from Descriptor d where d = :descriptor")
List<DescriptorList> listDescriptorLists(@Param("descriptor") Descriptor descriptor);
/**
* List datasets.
*
* @param descriptor the descriptor
* @return the list
*/
@Query("select d.datasets from Descriptor d where d = :descriptor")
List<Dataset> listDatasets(@Param("descriptor") Descriptor descriptor);
}
......@@ -16,11 +16,7 @@
package org.genesys.catalog.persistence.vocab;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.stereotype.Repository;
......@@ -49,35 +45,4 @@ public interface ControlledVocabularyRepository extends JpaRepository<Controlled
* @return the by uuid and version
*/
ControlledVocabulary getByUuidAndVersion(UUID uuid, int version);
/**
* Gets the vocabulary term.
*
* @param vocabularyUuid the vocabulary uuid
* @param code the code
* @return the vocabulary term
*/
@Query("select vt from ControlledVocabulary cv inner join cv.terms as vt where cv.uuid = ?1 and vt.code = ?2")
VocabularyTerm getVocabularyTerm(UUID vocabularyUuid, String code);
/**
* Autocomplete vocabulary term.
*
* @param vocabularyUuid the vocabulary uuid
* @param text the text
* @param page the page
* @return the list
*/
@Query("select vt from ControlledVocabulary cv inner join cv.terms as vt where cv.uuid = ?1 and (vt.code like concat(?2, '%') or vt.title like concat(?2, '%') or vt.description like concat(?2, '%'))")
List<VocabularyTerm> autocompleteVocabularyTerm(UUID vocabularyUuid, String text, Pageable page);
/**
* List vocabulary terms.
*
* @param vocabulary the vocabulary
* @param page the page
* @return the page
*/
@Query("select vt from ControlledVocabulary cv inner join cv.terms as vt where cv = ?1")
Page<VocabularyTerm> listVocabularyTerms(ControlledVocabulary vocabulary, Pageable page);
}
......@@ -146,22 +146,6 @@ public interface DescriptorService {
*/
Descriptor rejectDescriptor(Descriptor descriptor);
/**
* Gets the descriptor lists using specified descriptor.
*
* @param descriptor the descriptor
* @return the descriptor lists
*/
List<DescriptorList> getDescriptorLists(Descriptor descriptor);
/**
* Gets the datasets where descriptor is used.
*
* @param descriptor the descriptor
* @return the datasets
*/
List<Dataset> getDatasets(Descriptor descriptor);
/**
* Create next version of the descriptor.
*
......
......@@ -15,7 +15,7 @@
*/
package org.genesys.catalog.service.impl;
import static org.genesys.catalog.model.dataset.QDatasetCreator.datasetCreator;
import static org.genesys.catalog.model.dataset.QDatasetCreator.*;
import java.util.HashSet;
import java.util.List;
......@@ -25,6 +25,7 @@ import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetCreator;
import org.genesys.catalog.model.dataset.QDatasetCreator;
import org.genesys.catalog.persistence.dataset.DatasetCreatorRepository;
import org.genesys.catalog.service.DatasetCreatorService;
import org.genesys.catalog.service.DatasetService;
......@@ -114,7 +115,7 @@ public class DatasetCreatorServiceImpl implements DatasetCreatorService {
*/
@Override
public Page<DatasetCreator> listDatasetCreators(final UUID datasetUuid, final Pageable page) {
return datasetCreatorRepository.listByUUidOfDataset(page, datasetUuid);
return datasetCreatorRepository.findAll(QDatasetCreator.datasetCreator.dataset.uuid.eq(datasetUuid), page);
}
/**
......
......@@ -27,6 +27,9 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import com.querydsl.core.Tuple;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
......@@ -70,7 +73,6 @@ import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.querydsl.core.BooleanBuilder;
/**
* The Class DatasetServiceImpl.
*/
......@@ -98,8 +100,11 @@ public class DatasetServiceImpl implements DatasetService {
private SecurityUtils securityUtils;
@Autowired
private JPAQueryFactory jpaQueryFactory;
@Autowired
private AccessionRepository accessionRepository;
/** The file repository path. */
@Value("${file.repository.datasets.folder}")
public String datasetRepositoryPath;
......@@ -301,7 +306,7 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
public Page<Dataset> loadCurrentVersionList(final Pageable page) {
return datasetRepository.listAllCurrentVersion(page);
return datasetRepository.findAll(QDataset.dataset.versions.currentVersion.uuid.eq(dataset.uuid), page);
}
/**
......@@ -541,7 +546,22 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
public List<Object[]> lastPublished() {
return datasetRepository.lastPublished();
QDataset dataset = QDataset.dataset;
JPAQuery<Tuple> query = jpaQueryFactory.select(dataset.lastModifiedDate.year(), dataset.lastModifiedDate.month(),
dataset.lastModifiedDate.dayOfMonth(), dataset.title, dataset.uuid, dataset.owner.shortName).from(dataset);
query.where(dataset.state.eq(PublishState.PUBLISHED))
.orderBy(dataset.lastModifiedDate.year().desc(), dataset.lastModifiedDate.month().desc(), dataset.lastModifiedDate.dayOfMonth().desc());
return query.fetch().stream()
.map(item -> new Object[]{
item.get(dataset.lastModifiedDate.year()),
item.get(dataset.lastModifiedDate.month()),
item.get(dataset.lastModifiedDate.dayOfMonth()),
item.get(dataset.title),
item.get(dataset.uuid),
item.get(dataset.owner.shortName),
}).collect(Collectors.toList());
}
/**
......@@ -598,9 +618,9 @@ public class DatasetServiceImpl implements DatasetService {
private Set<AccessionIdentifier> lookupMatchingAccessions(final Set<AccessionIdentifier> accessionIdentifiers) {
List<AccessionIdentifier> list = new ArrayList<AccessionIdentifier>(accessionIdentifiers);
List<Accession> foundAccessions = accessionRepository.findById(list);
LOG.info("Found {} matches for {} identifiers", foundAccessions.size(), accessionIdentifiers.size());
accessionIdentifiers.forEach(accei -> {
Accession foundAccession = foundAccessions.stream().filter(a -> {
return StringUtils.equalsIgnoreCase(a.getInstCode(), accei.getInstCode())
......@@ -621,7 +641,7 @@ public class DatasetServiceImpl implements DatasetService {
return accessionIdentifiers;
}
@Override
@Transactional(readOnly = false)
public void rematchDatasetAccessions() {
......
......@@ -24,15 +24,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import javax.persistence.EntityManager;
import com.querydsl.core.types.Predicate;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DescriptorFilter;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.traits.QDescriptor;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
......@@ -54,14 +51,12 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
/**
* The Class DescriptorServiceImpl.
......@@ -87,9 +82,6 @@ public class DescriptorServiceImpl implements DescriptorService {
@Autowired
private SecurityUtils securityUtils;
@Autowired
private EntityManager entityManager;
@Autowired
private VersionManager versionManager;
......@@ -404,36 +396,6 @@ public class DescriptorServiceImpl implements DescriptorService {
return lazyLoad(descriptorRepository.save(loaded));
}
/*
* (non-Javadoc)
* @see
* org.genesys.catalog.service.DescriptorService#getDescriptorLists(org.genesys.
* catalog.model.traits.Descriptor)
*/
@Override
@PreAuthorize("#descriptor.isPublished() || hasRole('ADMINISTRATOR') || hasPermission(#descriptor, 'read')")
@PostFilter("hasRole('ADMINISTRATOR') || filterObject==null || filterObject.isPublished() || hasPermission(filterObject, 'write')")
public List<DescriptorList> getDescriptorLists(final Descriptor descriptor) {
final List<DescriptorList> list = descriptorRepository.listDescriptorLists(descriptor);
list.forEach(d -> entityManager.detach(d));
return list;
}
/*
* (non-Javadoc)
* @see
* org.genesys.catalog.service.DescriptorService#getDescriptorLists(org.genesys.
* catalog.model.traits.Descriptor)
*/
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || #descriptor.isPublished() || hasPermission(#descriptor, 'read')")
@PostFilter("hasRole('ADMINISTRATOR') || filterObject==null || filterObject.isPublished() || hasPermission(filterObject, 'write')")
public List<Dataset> getDatasets(final Descriptor descriptor) {
final List<Dataset> list = descriptorRepository.listDatasets(descriptor);
list.forEach(d -> entityManager.detach(d));
return list;
}
@Override
@Transactional
@PreAuthorize("#descriptor.isPublished() || hasRole('ADMINISTRATOR') || hasPermission(#descriptor, 'read')")
......
......@@ -22,6 +22,7 @@ import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetLocation;
import org.genesys.catalog.model.dataset.QDatasetLocation;
import org.genesys.catalog.persistence.dataset.DatasetLocationRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.LocationService;
......@@ -109,7 +110,7 @@ public class LocationServiceImpl implements LocationService {
@Override
public Page<DatasetLocation> listLocation(final UUID datasetUuid, final Pageable page) {
LOG.info("Load list DatasetLocation for dataset {}", datasetUuid);
return locationRepository.listByUUidOfDataset(page, datasetUuid);
return locationRepository.findAll(QDatasetLocation.datasetLocation.dataset.uuid.eq(datasetUuid), page);
}
/**
......
......@@ -25,6 +25,7 @@ import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.filters.ControlledVocabularyFilter;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.QVocabularyTerm;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.persistence.vocab.ControlledVocabularyRepository;
import org.genesys.catalog.persistence.vocab.VocabularyTermRepository;
......@@ -39,7 +40,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.querydsl.QSort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -124,7 +125,7 @@ public class VocabularyServiceImpl implements VocabularyService {
if (vocabulary != null) {
// Do not load all terms, only first 50
if (vocabulary.getTerms() != null) {
vocabulary.setTerms(vocabRepository.listVocabularyTerms(vocabulary, new PageRequest(0, 50)).getContent());
vocabulary.setTerms(listTerms(vocabulary, new PageRequest(0, 50)).getContent());
}
if (vocabulary.getOwner() != null) {
......@@ -268,16 +269,28 @@ public class VocabularyServiceImpl implements VocabularyService {
@Override
public VocabularyTerm getVocabularyTerm(final UUID vocabularyUuid, final String code) throws NotFoundElement {
return vocabRepository.getVocabularyTerm(vocabularyUuid, code);
VocabularyTerm term = termRepository.findOne(QVocabularyTerm.vocabularyTerm.vocabulary.uuid.eq(vocabularyUuid).and(QVocabularyTerm.vocabularyTerm.code.eq(code)));
if (term == null) {
throw new NotFoundElement("No vocabulary term with code=" + code);
}
return term;
}
@Override
public List<VocabularyTerm> autocompleteTerms(final UUID vocabularyUuid, final String text) {
return vocabRepository.autocompleteVocabularyTerm(vocabularyUuid, text, new PageRequest(0, 20, new Sort("vt.code")));
QVocabularyTerm vocabularyTerm = QVocabularyTerm.vocabularyTerm;
String term = text + "%";
PageRequest page = new PageRequest(0, 20, new QSort(vocabularyTerm.code.desc()));
return termRepository.findAll(vocabularyTerm.vocabulary.uuid.eq(vocabularyUuid)
// likes
.and(vocabularyTerm.code.like(term).or(vocabularyTerm.title.like(term)).or(vocabularyTerm.description.like(term)))
// sort and paginate
, page).getContent();
}
@Override
public Page<VocabularyTerm> listTerms(final ControlledVocabulary vocabulary, final Pageable page) {
return vocabRepository.listVocabularyTerms(vocabulary, page);
return termRepository.findAll(QVocabularyTerm.vocabularyTerm.vocabulary.eq(vocabulary), page);
}
}
......@@ -107,7 +107,7 @@ public class SelectionController extends BaseController {
AccessionList list = accessionListService.getList(uuid);
if (list != null) {
Set<Long> accessionIds = accessionListService.getAccessionIds(list);
List<Long> accessionIds = accessionListService.getAccessionIds(list);
selectionBean.clear();
for (Long accessionId : accessionIds) {
selectionBean.add(accessionId);
......
......@@ -23,8 +23,6 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang.time.StopWatch;
......@@ -34,14 +32,7 @@ import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.PDCIRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CountryNamesUpdater;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.*;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.worker.AccessionProcessor;
import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
......@@ -109,11 +100,11 @@ public class AdminController {
@Autowired
private DatasetService datasetService;
@PersistenceContext
private EntityManager entityManager;
ObjectMapper mapper = new ObjectMapper();
@Autowired
private AccessionService accessionService;
@Autowired
private AccessionRepository accessionRepository;
......@@ -122,10 +113,10 @@ public class AdminController {
@Autowired
private AccessionProcessor accessionProcessor;
@Autowired
private PDCIRepository pdciRepository;
@RequestMapping("/")
public String root(Model model) {
return "/admin/index";
......@@ -239,14 +230,14 @@ public class AdminController {
@RequestMapping(value = "/pdci", method = RequestMethod.POST, params = "action=filtered-pdci")
public String updateFilteredPDCI(@RequestParam(name = "filter") String filters) throws JsonParseException, JsonMappingException, IOException {
AccessionFilter filter = mapper.readValue(filters, AccessionFilter.class);
LOG.warn("Recalculating PDCI for accessions matching filter: {}", filter);
accessionProcessor.apply(filter, (accession) -> {
// Everything here is executed within a @Transaction(readOnly = false) context
AccessionId accessionId = accession.getAccessionId();
PDCI pdci = accessionId.getPdci();
// create new PDCI if missing
......@@ -264,7 +255,7 @@ public class AdminController {
return accession;
}
});
return "redirect:/admin/";
}
......@@ -305,7 +296,7 @@ public class AdminController {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
final Set<Long> batch = Collections.synchronizedSet(new HashSet<>(100));
List<Long> list = accessionRepository.listAccessionIdsWithCropname();
List<Long> list = accessionService.listAccessionIdsWithCropname();
LOG.info("The list has {} elements", list.size());
list.stream().parallel().forEach(accessionId -> {
batch.add(accessionId);
......
......@@ -8,6 +8,7 @@ import org.genesys2.server.service.KPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -46,7 +47,7 @@ public class KPIController {
@RequestParam(value = "dk", required = true) long dimensionKeyId) {
Execution execution = kpiService.getExecution(executionName);
model.addAttribute("execution", execution);
model.addAttribute("observations", kpiService.listObservations(execution, dimensionKeyId, new PageRequest(0, pageSize)));
model.addAttribute("observations", kpiService.listObservations(execution, dimensionKeyId, new PageRequest(0, pageSize, new Sort("executionRun.timestamp"))));
return "/admin/kpi/execution";
}
......
......@@ -16,31 +16,10 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AccessionAliasRepository extends JpaRepository<AccessionAlias, Long> {
List<AccessionAlias> findByAccession(AccessionId accession);
@Query("select aa from AccessionAlias aa where aa.accession = ?1 and aa.aliasType = ?2")
List<AccessionAlias> findByAccessionAndAliasType(AccessionId accession, int aliasType);
@Modifying
@Query("delete from AccessionAlias aa where aa.accession.id in ( :ids )")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
@Query("select distinct a from Accession a where a.accessionId in (select distinct aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3) and a.institute.code=?1")
Accession findAccession(String instCode, String name, int aliasType);
public interface AccessionAliasRepository extends JpaRepository<AccessionAlias, Long>, QueryDslPredicateExecutor<AccessionAlias> {
@Query("from AccessionAlias aa where aa.accession.id in ?1")
List<AccessionAlias> findAllFor(Collection<Long> accessionIds);
}
......@@ -16,23 +16,10 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface AccessionCollectRepository extends JpaRepository<AccessionCollect, Long> {
AccessionCollect findByAccession(AccessionId accession);
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
@Modifying
@Query("delete from AccessionCollect ac where ac.accession.id in ?1")
void deleteForAccessions(Collection<Long> accessionIds);
public interface AccessionCollectRepository extends JpaRepository<AccessionCollect, Long>, QueryDslPredicateExecutor<AccessionCollect> {
@Query("from AccessionCollect ac where ac.accession.id in ?1")
List<AccessionCollect> findAllFor(Collection<Long> accessionIds);
}
......@@ -16,34 +16,10 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface AccessionGeoRepository extends JpaRepository<AccessionGeo, Long> {
AccessionGeo findByAccession(AccessionId accession);
@Query("select ag from AccessionGeo ag join fetch ag.accession a where a.id in ?1")
List<AccessionGeo> findForAccessions(Set<Long> accessionIds);
@Modifying
@Query("delete from AccessionGeo ag where ag.accession.id in ?1")
void deleteForAccessions(Collection<Long> accessionIds);
@Query("from AccessionGeo ag where ag.accession.id in ?1")
List<AccessionGeo> findAllFor(Collection<Long> accessionIds);
@Query("select distinct(ag.tileIndex) from AccessionGeo ag where ag.tileIndex is not null")
Collection<Long> getTileIndexes();
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
@Query("select distinct(ag.accession.id) from AccessionGeo ag where ag.longitude between -180 and 180 and ag.latitude between -90 and 90 and ag.tileIndex is null")
Set<Long> withMissingTileIndex();
public interface AccessionGeoRepository extends JpaRepository<AccessionGeo, Long>, QueryDslPredicateExecutor<AccessionGeo> {
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,20 +17,16 @@
package org.genesys2.server.persistence;
import java.util.List;
import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface AccessionHistoricRepository extends JpaRepository<AccessionHistoric, Long> {
public interface AccessionHistoricRepository extends JpaRepository<AccessionHistoric, Long>, AccessionHistoricRepositoryCustom, QueryDslPredicateExecutor<AccessionHistoric> {
List<AccessionHistoric> findByInstituteAndAccessionNumber(FaoInstitute faoInstitute, String acceNumb);
List<AccessionHistoric> findByInstituteAndAccessionNumber(FaoInstitute faoInstitute, String acceNumb);
List<AccessionHistoric> findByAccessionNumber(String acceNumb);
@Query("select a from AccessionHistoric a where a.accessionId.uuid = ?1")
AccessionHistoric findOneByUuid(UUID uuid);
List<AccessionHistoric> findByAccessionNumber(String acceNumb);
}
package org.genesys2.server.persistence;
import org.genesys2.server.model.genesys.AccessionHistoric;
import java.util.UUID;
public interface AccessionHistoricRepositoryCustom {
AccessionHistoric findOneByUuid(UUID uuid);
}
package org.genesys2.server.persistence;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.model.genesys.QAccessionHistoric;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
@Repository
@Transactional(readOnly = true)
public class AccessionHistoricRepositoryCustomImpl implements AccessionHistoricRepositoryCustom {
@Autowired
private JPAQueryFactory jpaQueryFactory;
@Override
public AccessionHistoric findOneByUuid(UUID uuid) {
QAccessionHistoric accessionHistoric = QAccessionHistoric.accessionHistoric;
JPAQuery<AccessionHistoric> query = jpaQueryFactory.selectFrom(accessionHistoric)
.where(accessionHistoric.accessionId.uuid.eq(uuid));
return query.fetchOne();
}
}
......@@ -16,23 +16,10 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface AccessionIdRepository extends JpaRepository<AccessionId, Long> {
@Query("select aid from AccessionId aid where aid.uuid is null")
List<AccessionId> findMissingUuid(Pageable pageable);
@Query("select aid.id from AccessionId aid left join aid.pdci pdci where pdci.score is null")
Collection<Long> findMissingPDCI();
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
@Query("select id from AccessionId")
Collection<Long> findAllIds();
public interface AccessionIdRepository extends JpaRepository<AccessionId, Long>, QueryDslPredicateExecutor<AccessionId> {
}
......@@ -17,7 +17,6 @@
package org.genesys2.server.persistence;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionId;
......@@ -25,38 +24,20 @@ import org.genesys2.server.model.genesys.AccessionList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface AccessionListRepository extends JpaRepository<AccessionList, Long>, AccessionListCustomRepository {
@Query("from AccessionList al where al.createdBy=?1")
List<AccessionList> listByOwner(Long userId);
@Query("select a.id from AccessionList al join al.accessionIds a where al = ?1")
Set<Long> getAccessionIds(AccessionList list);
public interface AccessionListRepository extends JpaRepository<AccessionList, Long>, AccessionListCustomRepository, QueryDslPredicateExecutor<AccessionList> {
AccessionList findByUuid(UUID uuid);
@Query("from AccessionList al where al.uuid in (?1)")
List<AccessionList> findByUuids(List<UUID> uuid);
@Query(nativeQuery = true, value = "insert into accession_listitem (listid, acceid) values (?1, ?2)")
@Modifying
void addOne(AccessionList list, AccessionId accession);
@Query(nativeQuery = true, value = "insert into accession_listitem (listid, acceid) values (?1, ?2)")
@Modifying
void addOne(AccessionList acceList, long acceId);
@Query(nativeQuery=true, value="select count(acceid) from accession_listitem where listid = ?1")
int sizeOf(AccessionList list);
@Query(nativeQuery=true, value="select count(distinct acceid) from accession_listitem where listid in (?1)")
int distinctCount(List<AccessionList> accessionLists);
@Query("from AccessionList al where al.shared=1 order by al.title asc")
List<AccessionList> findShared();
@Query("select uuid from AccessionList al where al.title=?1")
UUID getUUIDByTitle(String title);
}
......@@ -16,21 +16,12 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.AllAccnames;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface AccessionNameRepository extends JpaRepository<AllAccnames, Long> {
public interface AccessionNameRepository extends JpaRepository<AllAccnames, Long>, QueryDslPredicateExecutor<AllAccnames> {
AllAccnames findByAccession(AccessionId accession);
@Modifying
@Query("delete from AllAccnames an where an.accession.id in ?1")
void deleteForAccessions(Collection<Long> accessionIds);
}
......@@ -16,27 +16,10 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import javax.persistence.OrderBy;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AccessionRemarkRepository extends JpaRepository<AccessionRemark, Long> {
@OrderBy("fieldName")
List<AccessionRemark> findByAccession(AccessionId accession);
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
@Modifying
@Query("delete from AccessionRemark ar where ar.accession.id in (:ids)")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
public interface AccessionRemarkRepository extends JpaRepository<AccessionRemark, Long>, QueryDslPredicateExecutor<AccessionRemark> {
@Query("from AccessionRemark ar where ar.accession.id in ?1")
List<AccessionRemark> findAllFor(Collection<Long> accessionIds);
}
......@@ -16,150 +16,31 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;
public interface AccessionRepository extends JpaRepository<Accession, Long>, AccessionRepositoryCustom, QueryDslPredicateExecutor<Accession> {
@Query("select a.id from Accession a")
public List<Long> listAccessionsIds(Pageable pageable);
List<Accession> findByInstitute(FaoInstitute institute);
/**
* Return the number of active ({@link Accession#historic} == false) accession records held at the institute
*/
@Query("select count(a) from Accession a where a.institute = ?1 and a.historic = false")
long countByInstitute(FaoInstitute institute);
/**
* Return the number of active ({@link Accession#historic} == false) accession records held at the institute with DOI
*/
@Query("select count(a) from Accession a where a.institute = ?1 and a.historic = false and a.doi is not null")
long countByInstituteWithDoi(FaoInstitute institute);
/**
* Return the number of active ({@link Accession#historic} == false) accession records originating from specified country
*/
@Query("select count(a) from Accession a where a.countryOfOrigin = ?1 and a.historic = false")
long countByOrigin(Country country);
/**
* Return the number of active ({@link Accession#historic} == false) accession records where holding institute is in the specified country
*/
@Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country);
@Query("select count(a) from Accession a where a.crop = ?1 and a.historic = false")
long countByCrop(Crop crop);
@Query(value = "select a.cropName, count(a.id) from Accession a where a.institute = ?1 and a.historic = false group by a.cropName order by count(a) desc", countQuery = "select count(distinct a.cropName) from Accession a where a.institute = ?1")
Page<Object[]> statisticsCropNameInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 and a.historic = false group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.taxSpecies, count(a) from Accession a inner join a.taxonomy t where a.institute = ?1 and a.historic = false group by t.taxSpecies order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxSpecies) from Accession a where a.institute = ?1")
Page<Object[]> statisticsSpeciesInInstitute(FaoInstitute institute, Pageable pageable);
@Query("select a from Accession a where a.institute in ( ?1 )")
Page<Accession> findByInstitute(List<FaoInstitute> institutes, Pageable pageable);
List<Accession> findByInstituteAndAccessionNumber(FaoInstitute faoInstitute, String accessionNumber);
public List<Accession> findByInstituteAndAccessionNumber(FaoInstitute institute, List<String> acceNumbs);
@Query("from Accession a where a.id in ( ?1 )")
Page<Accession> findById(Collection<Long> accessionIds, Pageable pageable);
@Query("from Accession a where a.id in ( ?1 )")
List<Accession> listById(Collection<Long> accessionIds, Sort sort);
List<Accession> findByInstituteAndAccessionNumber(FaoInstitute institute, List<String> acceNumbs);
Page<Accession> findByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy2 taxonomy, Pageable pageable);
Page<Accession> findByTaxonomy(Taxonomy2 taxonomy, Pageable pageable);
@Query("select a from Accession a where a.taxonomy in ( ?1 )")
Page<Accession> findByTaxonomy(Collection<Taxonomy2> taxonomies, Pageable pageable);
@Query("select a from Accession a where a.institute.code = ?1 and a.accessionNumber = ?2")
Accession findByInstituteCodeAndAccessionNumber(String instCode, String accessionNumber);
@Query("select distinct a from Accession a where a.accessionNumber=?2 and (a.institute.code=?1 or a.institute.codeSGSV=?1) and a.taxonomy.genus=?3")
Accession findOneSGSV(String instCode, String acceNumb, String genus);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.historic = false and (a.available is null or a.available = true) and a.institute.allowMaterialRequests = true")
long countAvailableForDistribution(Set<Long> accessionIds);
@Query("select a.id from Accession a where a.id in ( ?1 ) and a.historic = false and (a.available is null or a.available = true) and a.institute.allowMaterialRequests = true")
Set<Long> filterAvailableForDistribution(Set<Long> accessionIds);
@Query("select distinct a.institute from Accession a where a.id in ( ?1 )")
List<FaoInstitute> findDistinctInstitutesFor(Set<Long> accessionIds);
@Query("select distinct a.id from Accession a where a.institute = :institute and a.id in ( :ids )")
Set<Long> findByInstituteAndIds(@Param("institute") FaoInstitute institute, @Param("ids") Set<Long> accessionIds);
@Query("select a.id from Accession a where a.taxonomy = ?1")
public List<Long> listAccessionsIds(Taxonomy2 taxonomy);
@Modifying
@Query(nativeQuery = true, value = "delete from accession where id = ?1")
public void deleteActive(long id);
@Query("select a from Accession a where a.accessionId.uuid = ?1")
public Accession findOneByUuid(UUID uuid);
public List<Accession> findByAccessionNumber(String acceNumb);
@Query("select a from Accession a")
Stream<Accession> streamAll();
public long countByHistoric(boolean historic);
@Query(nativeQuery = true, value = "update accession a inner join sgsvdeposit sd on sd.acceId=a.id set a.inSGSV=true where sd.id in (?1)")
@Modifying
public void setInSvalbard(List<Long> sgsvId);
@Query("select a from Accession a where a.cropName != null")
Stream<Accession> streamWithCropname();
@Query("select a.id from Accession a where a.cropName != null")
List<Long> listAccessionIdsWithCropname();
@Query("update Accession a set a.crop = ?2 where a = ?1")
@Modifying
public void updateCrop(Accession accession, Crop crop);
@Query("select year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), a.institute.id, count(a) from Accession a group by year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), a.institute order by year(a.lastModifiedDate) desc, month(a.lastModifiedDate) desc, day(a.lastModifiedDate) desc, count(*) desc, a.institute.id")
public List<Object[]> lastUpdatedStatistics();
@Query("select year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), count(a) from Accession a where a.institute = ?1 group by year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate) order by year(a.lastModifiedDate) desc, month(a.lastModifiedDate) desc, day(a.lastModifiedDate) desc")
public List<Object[]> lastUpdatedStatistics(FaoInstitute faoInstitute);
@Query("select year(a.lastModifiedDate), count(a) from Accession a where a.institute = ?1 and a.historic = ?2 group by year(a.lastModifiedDate) order by year(a.lastModifiedDate) desc")
public List<Object[]> lastUpdatedStatistics(FaoInstitute faoInstitute, boolean historic);
List<Accession> findByAccessionNumber(String acceNumb);
public Accession findByDoi(String doi);
long countByHistoric(boolean historic);
@Query("update Accession accession set accession.doi = null where accession.doi is not null")
@Modifying
void removeDOIs();
Accession findByDoi(String doi);
}
......@@ -42,4 +42,6 @@ public interface AccessionRepositoryCustom {
Accession findOne(FaoInstitute institute, String doi, String acceNumb, String genus);
List<Accession> findAll(AccessionFilter filter, Pageable page);
Accession findOneByUuid(UUID uuid);
}
......@@ -33,6 +33,8 @@ import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionHistoric;
......@@ -45,16 +47,12 @@ import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.Querydsl;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.core.types.dsl.PathBuilderFactory;
import com.querydsl.jpa.JPQLQuery;
@Repository
@Transactional(readOnly = true)
public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, InitializingBean {
......@@ -64,10 +62,11 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
@PersistenceContext
private EntityManager em;
@Autowired
private JPAQueryFactory jpaQueryFactory;
private CriteriaBuilder criteriaBuilder;
PathBuilder<Accession> pathBuilder = new PathBuilderFactory().create(Accession.class);
@Override
public void afterPropertiesSet() throws Exception {
this.criteriaBuilder = em.getCriteriaBuilder();
......@@ -268,16 +267,24 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
@Override
public List<Accession> findAll(AccessionFilter filter, Pageable page) {
Querydsl querydsl = new Querydsl(em, pathBuilder);
JPQLQuery<Accession> query = querydsl.createQuery(QAccession.accession).select(QAccession.accession);
JPAQuery<Accession> query = jpaQueryFactory.selectFrom(QAccession.accession);
if (filter != null) {
// apply filter
query.where(filter.buildQuery());
}
querydsl.applyPagination(page, query);
query.offset(page.getOffset());
query.limit(page.getPageSize());
return query.fetch();
}
@Override
public Accession findOneByUuid(UUID uuid) {
JPAQuery<Accession> query = jpaQueryFactory.selectFrom(QAccession.accession)
.where(QAccession.accession.accessionId.uuid.eq(uuid));
return query.fetchOne();
}
}
......@@ -21,39 +21,12 @@ import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface AccessionTraitRepository extends JpaRepository<AccessionTrait, Long> {
public interface AccessionTraitRepository extends JpaRepository<AccessionTrait, Long>, QueryDslPredicateExecutor<AccessionTrait> {
List<AccessionTrait> findByAccession(AccessionId accession);
@Query("select distinct at.metadataId from AccessionTrait at where at.accession = ?1")
List<Long> listMetadataIds(AccessionId accession);
@Query("select distinct at.methodId from AccessionTrait at where at.accession = ?1")
List<Long> listMethodIds(AccessionId accession);
@Query(value = "select distinct a from AccessionTrait at inner join at.accession a where at.metadataId = ?1", countQuery = "select count(ma.accessionId) from MetadataAccession ma where ma.metadata.id = ?1")
Page<AccessionId> listMetadataAccessions(long metadataId, Pageable pageable);
List<AccessionTrait> findByMetadataIdAndAccession(Long id, Accession accession);
@Query("select count(id) from AccessionTrait at where at.metadataId = ?1 and at.accession = ?2")
long countByMetadataAndAccessionId(long metadataId, AccessionId accession);
@Modifying
@Query("delete from AccessionTrait where accession = ?1 and metadataId= ?2 and methodId = ?3")
void deleteByAccessionAndMetadataIdAndMethodId(AccessionId accession, long metadataId, long methodId);
@Query("select a.id, count(distinct at.methodId) from Accession a join a.accessionId.traits at where a.institute = ?1 group by a.id")
List<Object[]> statisticsAccessionMethod(FaoInstitute faoInstitute);
@Query("select a.id, count(distinct at.metadataId) from Accession a join a.accessionId.traits at where a.institute = ?1 group by a.id")
List<Object[]> statisticsAccessionMetadata(FaoInstitute faoInstitute);
}
......@@ -18,7 +18,8 @@ package org.genesys2.server.persistence;
import org.genesys2.server.model.impl.ActivityPost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface ActivityPostRepository extends JpaRepository<ActivityPost, Long> {
public interface ActivityPostRepository extends JpaRepository<ActivityPost, Long>, QueryDslPredicateExecutor<ActivityPost> {
}
......@@ -18,27 +18,14 @@ package org.genesys2.server.persistence;
import org.genesys.blocks.model.ClassPK;
import org.genesys2.server.model.impl.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import java.util.List;
public interface ArticleRepository extends JpaRepository<Article, Long> {
public interface ArticleRepository extends JpaRepository<Article, Long>, QueryDslPredicateExecutor<Article> {
Article findByClassPkAndTargetIdAndSlugAndLang(ClassPK classPk, Long id, String slug, String lang);
@Query("select a from Article a where a.lang = :lang")
Page<Article> getAllByLang(@Param("lang") String lang, Pageable pageable);
@Query("select a from Article a where a.slug = :slug and a.lang = :lang")
Article findBySlugAndLang(@Param("slug")String slug,
@Param("lang")String lang);
Article findBySlugAndLang(String slug, String lang);
Article findBySlugAndLangAndTargetIdAndClassPk(String slug, String lang, Long targetId, ClassPK classPK);
@Query("select a from Article a where a.template = :isTemplate")
List<Article> findAllByTemplate(@Param("isTemplate") Boolean isTemplate);
}
......@@ -22,48 +22,19 @@ import org.genesys2.server.model.impl.Country;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
public interface CountryRepository extends JpaRepository<Country, Long> {
public interface CountryRepository extends JpaRepository<Country, Long>, QueryDslPredicateExecutor<Country> {
Country findByName(String name);
// @Query("from Country c where c.code3= ?1 and c.current=true")
Country findByCode3(String code3);
Country findByCode2AndCurrent(String code2, boolean current);
// List<Country> findByRegion(Region region);
@Query("from Country c where c.current=false")
List<Country> findInactive();
@Query("select count(c) from Country c where c.current = ?1")
long countByCurrent(boolean current);
List<Country> findByCurrent(boolean current);
Page<Country> findByCurrent(boolean current, Pageable pageable);
@Modifying
@Query("update Country c set c.current=false")
void deactivateAll();
Country findByRefnameId(Long refnameId);
@Query("select distinct c.refnameId from Country c where c.refnameId is not null")
List<Long> listRefnameIds();
@Query("select distinct itpgrfa.country from ITPGRFAStatus itpgrfa where itpgrfa.contractingParty = 'Yes'")
List<Country> findITPGRFA();
@Query("select distinct c from Country c where c.nameL like :pattern")
List<Country> findWithI18N(@Param("pattern") String pattern);