diff --git a/service/grails-app/controllers/org/olf/DirectoryEntryController.groovy b/service/grails-app/controllers/org/olf/DirectoryEntryController.groovy index 0c464c5..591a8c9 100644 --- a/service/grails-app/controllers/org/olf/DirectoryEntryController.groovy +++ b/service/grails-app/controllers/org/olf/DirectoryEntryController.groovy @@ -2,7 +2,6 @@ package org.olf import grails.gorm.multitenancy.CurrentTenant import groovy.util.logging.Slf4j -import com.k_int.okapi.OkapiTenantAwareController import grails.converters.JSON import org.olf.okapi.modules.directory.DirectoryEntry; import org.olf.okapi.modules.directory.NamingAuthority; @@ -19,8 +18,8 @@ import com.k_int.web.toolkit.refdata.RefdataValue */ @Slf4j @CurrentTenant -class DirectoryEntryController extends OkapiTenantAwareController { - +class DirectoryEntryController extends OkapiTenantAwareExtendedController { + final UPDATE_LOCAL_PERMISSION = "directory.entry.item-local.put"; final UPDATE_MANAGED_PERMISSION = "directory.entry.managed-item.put"; final UPDATE_ANY_PERMISSION = "directory.entry.item.put"; @@ -29,7 +28,7 @@ class DirectoryEntryController extends OkapiTenantAwareController Symbol exists = null; - + // Need to lookup the naming authority first in order to use it in findBy NamingAuthority authority = NamingAuthority.get(symbol.authority.id); @@ -179,17 +178,17 @@ class DirectoryEntryController extends OkapiTenantAwareController extends OkapiTenantAwareController { + + // Required as we override the maximum number of records that can be returned in index + SimpleLookupService simpleLookupService + + /** Specifies the maximum number of records to return for a page */ + private int maxRecordsPerPage = 1000; + + OkapiTenantAwareExtendedController(Class resource, int maxRecordsPerPage = 1000) { + this(resource, false, maxRecordsPerPage); + } + + OkapiTenantAwareExtendedController(Class resource, boolean readOnly, int maxRecordsPerPage = 1000) { + super(resource, readOnly); + this.maxRecordsPerPage = maxRecordsPerPage; + } + + @Override + /** + * We override this method so we can vary what the maximum number of items that get returned is. + * So for a large record we can restrict it to the default of 100 that is in the library + * and for smaller records we can make it a larger number. + * The method was copied from com.k_int.web.toolkit.rest.RestfulController.groovy with maxRecordsPerPage replacing 100 + * Note: simpleLookupService still caps it at 1000 regardless + * + * @param res The class that we are returning records for + * @param baseQuery A closure that contains any extra queries beyond what has been asked for in the parameters + * @return The results of the query + */ + protected def doTheLookup (Class res = this.resource, Closure baseQuery) { + final int offset = params.int("offset") ?: 0; + final int perPage = Math.min(params.int('perPage') ?: params.int('max') ?: 10, maxRecordsPerPage); + final int page = params.int("page") ?: (offset ? (offset / perPage) + 1 : 1); + final List filters = getParamList("filters"); + final List match_in = getParamList("match"); + final List sorts = getParamList("sort"); + + if (params.boolean('stats')) { + return(simpleLookupService.lookupWithStats(res, params.term, perPage, page, filters, match_in, sorts, null, baseQuery)); + } else { + return(simpleLookupService.lookup(res, params.term, perPage, page, filters, match_in, sorts, baseQuery)); + } + } +}