Small refactor

This commit is contained in:
Raf Ponsaerts
2021-02-04 11:10:34 +01:00
parent d0aec95b28
commit ed26f7494c
5 changed files with 8 additions and 12 deletions

View File

@@ -115,12 +115,12 @@ public class AuthorizeSolrServiceImpl implements AuthorizeSolrService {
* @throws SearchServiceException * @throws SearchServiceException
*/ */
@Override @Override
public int countAdminAuthorizedCommunity(Context context, String query) public Long countAdminAuthorizedCommunity(Context context, String query)
throws SearchServiceException, SQLException { throws SearchServiceException, SQLException {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:Community", DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:Community",
null, null); null, null);
return (int)discoverResult.getTotalSearchResults(); return discoverResult.getTotalSearchResults();
} }
/** /**
@@ -160,12 +160,12 @@ public class AuthorizeSolrServiceImpl implements AuthorizeSolrService {
* @throws SearchServiceException * @throws SearchServiceException
*/ */
@Override @Override
public int countAdminAuthorizedCollection(Context context, String query) public Long countAdminAuthorizedCollection(Context context, String query)
throws SearchServiceException, SQLException { throws SearchServiceException, SQLException {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:Collection", DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:Collection",
null, null); null, null);
return (int)discoverResult.getTotalSearchResults(); return discoverResult.getTotalSearchResults();
} }
private boolean performCheck(Context context, String query) throws SQLException { private boolean performCheck(Context context, String query) throws SQLException {

View File

@@ -70,7 +70,7 @@ public interface AuthorizeSolrService {
* @throws SearchServiceException * @throws SearchServiceException
* @throws SQLException * @throws SQLException
*/ */
int countAdminAuthorizedCommunity(Context context, String query) Long countAdminAuthorizedCommunity(Context context, String query)
throws SearchServiceException, SQLException; throws SearchServiceException, SQLException;
/** /**
@@ -96,6 +96,6 @@ public interface AuthorizeSolrService {
* @throws SearchServiceException * @throws SearchServiceException
* @throws SQLException * @throws SQLException
*/ */
int countAdminAuthorizedCollection(Context context, String query) Long countAdminAuthorizedCollection(Context context, String query)
throws SearchServiceException, SQLException; throws SearchServiceException, SQLException;
} }

View File

@@ -9,8 +9,6 @@ package org.dspace.app.rest.authorization.impl;
import java.sql.SQLException; import java.sql.SQLException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.authorization.AuthorizationFeature; import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
@@ -32,8 +30,6 @@ import org.springframework.stereotype.Component;
description = "It can be used to verify if the current user is admin of any community in the site") description = "It can be used to verify if the current user is admin of any community in the site")
public class CommunityAdminFeature implements AuthorizationFeature { public class CommunityAdminFeature implements AuthorizationFeature {
private static Logger log = LogManager.getLogger(CommunityAdminFeature.class);
public final static String NAME = "isCommunityAdmin"; public final static String NAME = "isCommunityAdmin";
@Autowired @Autowired

View File

@@ -212,7 +212,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = authorizeSolrService.findAdminAuthorizedCollection(context, query, List<Collection> collections = authorizeSolrService.findAdminAuthorizedCollection(context, query,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
int tot = authorizeSolrService.countAdminAuthorizedCollection(context, query); Long tot = authorizeSolrService.countAdminAuthorizedCollection(context, query);
return converter.toRestPage(collections, pageable, tot , utils.obtainProjection()); return converter.toRestPage(collections, pageable, tot , utils.obtainProjection());
} catch (SearchServiceException | SQLException e) { } catch (SearchServiceException | SQLException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);

View File

@@ -216,7 +216,7 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
List<Community> communities = authorizeSolrService.findAdminAuthorizedCommunity(context, query, List<Community> communities = authorizeSolrService.findAdminAuthorizedCommunity(context, query,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
int tot = authorizeSolrService.countAdminAuthorizedCommunity(context, query); Long tot = authorizeSolrService.countAdminAuthorizedCommunity(context, query);
return converter.toRestPage(communities, pageable, tot , utils.obtainProjection()); return converter.toRestPage(communities, pageable, tot , utils.obtainProjection());
} catch (SearchServiceException | SQLException e) { } catch (SearchServiceException | SQLException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);