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

Added "descriptorListCount" to API info

parent 706e0c84
......@@ -17,6 +17,7 @@ package org.genesys.catalog.model.filters;
import static org.genesys.catalog.model.traits.QDescriptorList.descriptorList;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
......@@ -24,10 +25,10 @@ import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys2.server.model.PublishState;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.genesys2.server.model.PublishState;
/**
* The Class DescriptorListFilter.
......@@ -113,4 +114,14 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
return and;
}
public DescriptorListFilter state(PublishState... state) {
if (this.state == null) {
this.state = new HashSet<>();
}
for (PublishState s : state) {
this.state.add(s);
}
return this;
}
}
......@@ -15,15 +15,14 @@
*/
package org.genesys.catalog.service;
import java.util.List;
import java.util.UUID;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.UUID;
/**
* DescriptorList service interface.
......@@ -32,6 +31,14 @@ import java.util.UUID;
*/
public interface DescriptorListService {
/**
* Count descriptor lists.
*
* @param filter the filter
* @return the long
*/
long countDescriptorLists(DescriptorListFilter filter);
/**
* Create DescriptionList.
*
......@@ -117,14 +124,6 @@ public interface DescriptorListService {
*/
Page<DescriptorList> listDescriptorListsForCurrentUser(DescriptorListFilter descriptorListFilter, Pageable page);
/**
* Upload DescriptorList with Descriptor list.
*
* @param file .csv file with data
* @return Created DescriptorList
*/
DescriptorList uploadDescriptorListOfCSV(MultipartFile file);
/**
* Delete descriptor list.
*
......@@ -134,8 +133,8 @@ public interface DescriptorListService {
DescriptorList deleteDescriptorList(DescriptorList descriptorList);
/**
* Puts the descriptorList into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
* Puts the descriptorList into the Review state to be reviewed by admin. Admin
* and the user with MANAGE permission - only.
*
* @param descriptorList the descriptorList
* @return descriptorList in REVIEWING state
......@@ -143,8 +142,8 @@ public interface DescriptorListService {
DescriptorList reviewDescriptorList(DescriptorList descriptorList);
/**
* Unpublishes published descriptorList.
* Admin and the user with MANAGE permission - only.
* Unpublishes published descriptorList. Admin and the user with MANAGE
* permission - only.
*
* @param descriptorList the descriptorList
* @return unpublished descriptorList
......
......@@ -47,13 +47,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PostAuthorize;
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 org.springframework.web.multipart.MultipartFile;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
......@@ -79,6 +82,15 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Autowired
private DescriptorService descriptorService;
/* (non-Javadoc)
* @see org.genesys.catalog.service.DescriptorListService#countDescriptorLists(org.genesys.catalog.model.filters.DescriptorListFilter)
*/
@Override
public long countDescriptorLists(DescriptorListFilter filter) {
return descriptorListRepository.count(filter.buildQuery());
}
/**
* {@inheritDoc}
*/
......@@ -305,7 +317,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Override
public Page<DescriptorList> listDescriptorLists(final DescriptorListFilter filters, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page res = descriptorListRepository.findAll(new BooleanBuilder().and(filters.buildQuery()).and(descriptorList.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(new BooleanBuilder().and(filters.buildQuery()).and(descriptorList.state.in(PublishState.PUBLISHED)), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
}
......@@ -313,21 +325,15 @@ public class DescriptorListServiceImpl implements DescriptorListService {
public Page<DescriptorList> listDescriptorListsForCurrentUser(final DescriptorListFilter filter, final Pageable page) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
Page res = descriptorListRepository.findAll(filter.buildQuery(), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(filter.buildQuery(), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
} else {
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
Page res = descriptorListRepository.findAll(descriptorList.owner.id.in(partners).and(filter.buildQuery()), markdownSortPageRequest);
Page<DescriptorList> res = descriptorListRepository.findAll(descriptorList.owner.id.in(partners).and(filter.buildQuery()), markdownSortPageRequest);
return new PageImpl<DescriptorList>(res.getContent(), page, res.getTotalElements());
}
}
// TODO implement logic
@Override
public DescriptorList uploadDescriptorListOfCSV(final MultipartFile file) {
return null;
}
/**
* {@inheritDoc}
*/
......
......@@ -2,8 +2,10 @@ package org.genesys2.server.api.v1;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.filters.DescriptorFilter;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.api.ApiBaseController;
......@@ -68,6 +70,8 @@ public class ApiInfoController {
@Autowired
private DescriptorService descriptorService;
@Autowired
private DescriptorListService descriptorListService;
@Autowired
private PartnerService partnerService;
/**
......@@ -88,6 +92,7 @@ public class ApiInfoController {
apiInfo.subsetCount = subsetService.countSubsets(new SubsetFilter().state(PublishState.PUBLISHED));
apiInfo.instituteCount = instituteService.countActive();
apiInfo.descriptorCount = descriptorService.countDescriptors(new DescriptorFilter().state(PublishState.PUBLISHED));
apiInfo.descriptorListCount = descriptorListService.countDescriptorLists(new DescriptorListFilter().state(PublishState.PUBLISHED));
apiInfo.partnerCount = partnerService.countPartners(new PartnerFilter());
apiInfo.captchaSiteKey = this.captchaSiteKey;
apiInfo.googleAnalyticsId = this.googleAnalyticsId;
......@@ -100,16 +105,17 @@ public class ApiInfoController {
* The Class ApiInfo.
*/
public static class ApiInfo {
public String artifactId;
public String artifactId;
public String version;
public String revision;
public String baseUrl;
public String[] cdnServers;
public long instituteCount;
public long accessionCount;
public long datasetCount;
public long subsetCount;
public long instituteCount;
public long descriptorListCount;
public long descriptorCount;
public long partnerCount;
public String captchaSiteKey;
......
......@@ -26,6 +26,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
/**
* Declare sorts of things that upgrade the existing database
......@@ -67,6 +68,7 @@ public class ApplicationUpgrades implements InitializingBean {
*/
// TODO Remove in 2.5
@Bean
@DependsOn({ "currentApplicationContext" })
protected RepositoryUpgrade20180920 repositoryUpgrade20180920() throws Exception {
return new RepositoryUpgrade20180920();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment