From 0c952eb557979509fda5b1fdbdaf237659efc56b Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Fri, 2 Apr 2010 05:34:52 +0000 Subject: [PATCH] CSPACE-863 Added support in the configuration for default values in the service config, that cascades to set default values in the tenants, and into each service. Added pageSize default to verify this, and adjusted the creation of documentFilter instances to pick up this default. The various resource classes must still be changed to use getFiltered in place of getAll. --- .../services/account/AccountResource.java | 2 +- .../storage/AccountDocumentHandler.java | 8 +- .../acquisition/AcquisitionResource.java | 2 +- .../CollectionObjectResource.java | 2 +- .../main/config/services/service-config.xml | 10 +- .../services/common/ServiceMain.java | 17 +++ .../common/config/PropertyItemUtils.java | 130 ++++++++++++++++++ .../common/config/ServiceConfigUtils.java | 76 ++++++++++ .../config/TenantBindingConfigReaderImpl.java | 19 +++ .../common/config/TenantBindingUtils.java | 88 ++++++++++++ .../context/AbstractServiceContextImpl.java | 30 ++-- .../common/context/ServiceBindingUtils.java | 93 ++++++++----- .../common/context/ServiceContext.java | 6 + .../document/AbstractDocumentHandlerImpl.java | 4 +- .../common/document/DocumentFilter.java | 22 ++- .../common/document/DocumentHandler.java | 4 +- .../storage/jpa/JpaStorageClientImpl.java | 4 +- .../vocabulary/RefNameServiceUtils.java | 2 +- .../client/java/DocumentModelHandler.java | 9 +- .../src/main/resources/service-config.xsd | 4 + .../common/src/main/resources/service.xsd | 1 + services/common/src/main/resources/tenant.xsd | 1 + .../services/intake/IntakeResource.java | 2 +- .../organization/OrgAuthorityResource.java | 8 +- .../person/PersonAuthorityResource.java | 10 +- .../vocabulary/VocabularyResource.java | 4 +- 26 files changed, 476 insertions(+), 82 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java create mode 100644 services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java create mode 100644 services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingUtils.java diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java index 03141d7dc..8c35ff148 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -182,7 +182,7 @@ public class AccountResource ServiceContext ctx = createServiceContext((AccountsCommonList) null); DocumentHandler handler = createDocumentHandler(ctx); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = handler.createDocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); myFilter.setPagination(queryParams); myFilter.setQueryParams(queryParams); handler.setDocumentFilter(myFilter); diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java index 437bbc9b7..40907bcd0 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java @@ -145,8 +145,12 @@ public class AccountDocumentHandler } @Override - public DocumentFilter createDocumentFilter() { - return new AccountJpaFilter(); + public DocumentFilter createDocumentFilter(ServiceContext ctx) { + DocumentFilter filter = new AccountJpaFilter(); + filter.setPageSize( + ctx.getServiceBindingPropertyValue( + DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY)); + return filter; } private void setTenant(AccountsCommon account) { diff --git a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java index ed0079e1e..e9b5fb34e 100644 --- a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java +++ b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java @@ -383,7 +383,7 @@ public class AcquisitionResource // perform a keyword search if (keywords != null && !keywords.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); - DocumentFilter documentFilter = handler.getDocumentFilter(); + DocumentFilter documentFilter = handler.createDocumentFilter(ctx); documentFilter.setWhereClause(whereClause); if (logger.isDebugEnabled()) { logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 3ab41c047..069db4b2c 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -481,7 +481,7 @@ public class CollectionObjectResource // perform a keyword search if (keywords != null && !keywords.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); - DocumentFilter documentFilter = handler.getDocumentFilter(); + DocumentFilter documentFilter = handler.createDocumentFilter(ctx); documentFilter.setWhereClause(whereClause); if (logger.isDebugEnabled()) { logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); diff --git a/services/common/src/main/config/services/service-config.xml b/services/common/src/main/config/services/service-config.xml index 7cea39a03..8e15920cf 100644 --- a/services/common/src/main/config/services/service-config.xml +++ b/services/common/src/main/config/services/service-config.xml @@ -9,8 +9,9 @@ Service layer configuration --> - @@ -23,7 +24,10 @@ Administrator java org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl + + pageSizeDefault10 + - + diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index 3426171ec..ebcbdc31c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -4,8 +4,13 @@ package org.collectionspace.services.common; import java.util.Hashtable; +import java.util.List; + import org.collectionspace.services.common.config.ServicesConfigReaderImpl; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; +import org.collectionspace.services.common.tenant.TenantBindingType; +import org.collectionspace.services.common.types.PropertyItemType; +import org.collectionspace.services.common.types.PropertyType; import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,6 +65,7 @@ public class ServiceMain { private void initialize() throws Exception { setServerRootDir(); readConfig(); + propagateConfiguredProperties(); if(getClientType().equals(ClientType.JAVA)){ nuxeoConnector = NuxeoConnector.getInstance(); nuxeoConnector.initialize( @@ -91,6 +97,17 @@ public class ServiceMain { tenantBindingConfigReader = new TenantBindingConfigReaderImpl(getServerRootDir()); getTenantBindingConfigReader().read(); } + + private void propagateConfiguredProperties() { + List repoPropListHolder = + servicesConfigReader.getConfiguration().getRepositoryClient().getProperties(); + if(repoPropListHolder != null && !repoPropListHolder.isEmpty()) { + List propList = repoPropListHolder.get(0).getItem(); + if(propList != null && !propList.isEmpty()) { + tenantBindingConfigReader.setDefaultPropertiesOnTenants(propList, true); + } + } + } void retrieveAllWorkspaceIds() throws Exception { //all configs are read, connector is initialized, retrieve workspaceids diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java b/services/common/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java new file mode 100644 index 000000000..6c56370e1 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java @@ -0,0 +1,130 @@ +package org.collectionspace.services.common.config; + +import java.util.ArrayList; +import java.util.List; + +import org.collectionspace.services.common.types.PropertyItemType; +import org.collectionspace.services.common.types.PropertyType; + +public class PropertyItemUtils { + + /** + * @param propNodeList the wrapping list node from JAXB + * @param propName the property to fetch + * @return the String value of the named property + */ + public static String getPropertyValueFromNodeList(List propNodeList, + String propName) { + if(propNodeList.isEmpty()) { + return null; + } + return getPropertyValue(propNodeList.get(0).getItem(), propName); + } + + + /** + * @param propList the list of properties. + * @param propName the property to fetch + * @return the String value of the named property + */ + public static String getPropertyValue(List propList, + String propName) { + if(propName==null) { + throw new IllegalArgumentException("PropertyItemUtils.getPropertyValues: null property name!"); + } + for(PropertyItemType propItem:propList) { + if(propName.equals(propItem.getKey())) { + return propItem.getValue(); + } + } + return null; + } + + public static List getPropertyValuesByNameInNodeList( + List propNodeList, String propName) { + return getPropertyValuesByNameInNodeList(propNodeList, propName, null); + } + + public static List getPropertyValuesByNameInNodeList( + List propNodeList, String propName, List values) { + if(propNodeList.isEmpty()) { + if(values==null) + return new ArrayList(); + } + return getPropertyValuesByName(propNodeList.get(0).getItem(), propName, null); + } + + public static List getPropertyValuesByName( + List propItems, String propName) { + return getPropertyValuesByName(propItems, propName, null); + } + + public static List getPropertyValuesByName( + List propItems, String propName, + List values ) { + if(values==null) + values = new ArrayList(); + for(PropertyItemType propItem:propItems) { + if(propName.equals(propItem.getKey())) { + String value = propItem.getValue(); + if(value!=null) { + values.add(value); + } + } + } + return values; + } + + /** + * @param propNodeList the wrapping list node from JAXB + * @param propName the property to set + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValueInNodeList(List propNodeList, + String propName, String value, + boolean onlyIfNotSet) { + if(propNodeList.isEmpty()) { + propNodeList.add(new PropertyType()); + } + List propList = propNodeList.get(0).getItem(); + return setPropertyValue(propList, propName, value, onlyIfNotSet); + } + + /** + * @param propName the property to set + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValue(List propList, + String propName, String value, + boolean onlyIfNotSet) { + boolean valueFound = false; + boolean valueSet = false; + if(propName==null) { + throw new IllegalArgumentException("ServiceBindingUtils.setPropertyValue: null property name!"); + } + for(PropertyItemType propItem:propList) { + if(propName.equals(propItem.getKey())) { + if(!onlyIfNotSet) { + propItem.setValue(value); + valueSet = true; + } + // whether we set it or not, we found it, so break; + valueFound = true; + break; + } + } + if(!valueFound) { + PropertyItemType propItem = new PropertyItemType(); + propItem.setKey(propName); + propItem.setValue(value); + propList.add(propItem); + valueSet = true; + } + return valueSet; + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java new file mode 100644 index 000000000..dc52cabce --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java @@ -0,0 +1,76 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.common.config; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.collectionspace.services.common.RepositoryClientConfigType; +import org.collectionspace.services.common.ServiceConfig; +import org.collectionspace.services.common.types.PropertyItemType; +import org.collectionspace.services.common.types.PropertyType; + +/** + * @author pschmitz + * + */ +public class ServiceConfigUtils { + + + /** + * @param serviceConfig + * @param propName the property to fetch (allows multiple property values) + * @return + */ + public static List getPropertyValues(ServiceConfig serviceConfig, + String propName) { + List propValues = null; + if(propName==null) { + throw new IllegalArgumentException("ServiceConfilUtils.getPropertyValues: null property name!"); + } + RepositoryClientConfigType repoClient = serviceConfig.getRepositoryClient(); + if(repoClient==null) { + throw new RuntimeException("ServiceConfilUtils.getPropertyValues: serviceConfig has NULL repoClient!"); + } + List propList = repoClient.getProperties(); + if(propList!=null && propList.size()>0) { + List propItems = propList.get(0).getItem(); + for(PropertyItemType propItem:propItems) { + if(propName.equals(propItem.getKey())) { + String value = propItem.getValue(); + if(value!=null) { + if(propValues==null) { + propValues = new ArrayList(); + } + propValues.add(value); + } + } + } + } + return propValues; + } + + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java index 347bbf100..5419b46e3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java @@ -36,6 +36,8 @@ import org.collectionspace.services.common.repository.RepositoryClientFactory; import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.common.tenant.TenantBindingType; import org.collectionspace.services.common.tenant.TenantBindingConfig; +import org.collectionspace.services.common.types.PropertyItemType; +import org.collectionspace.services.common.types.PropertyType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -259,4 +261,21 @@ public class TenantBindingConfigReaderImpl private RepositoryClient getRepositoryClient(String clientName) { return RepositoryClientFactory.getInstance().getClient(clientName); } + + public void setDefaultPropertiesOnTenants(List propList, + boolean propagateToServices) { + // For each tenant, set properties in list that are not already set + if(propList == null || propList.isEmpty()) + return; + for(TenantBindingType tenant:tenantBindings.values()) { + for(PropertyItemType prop:propList){ + TenantBindingUtils.setPropertyValue(tenant, + prop, TenantBindingUtils.SET_PROP_IF_MISSING ); + } + if(propagateToServices) { + TenantBindingUtils.propagatePropertiesToServices(tenant, + TenantBindingUtils.SET_PROP_IF_MISSING); + } + } + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingUtils.java new file mode 100644 index 000000000..3aa85947e --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingUtils.java @@ -0,0 +1,88 @@ +package org.collectionspace.services.common.config; + +import java.util.ArrayList; +import java.util.List; + +import org.collectionspace.services.common.context.ServiceBindingUtils; +import org.collectionspace.services.common.service.ServiceBindingType; +import org.collectionspace.services.common.tenant.TenantBindingType; +import org.collectionspace.services.common.types.PropertyItemType; +import org.collectionspace.services.common.types.PropertyType; + +public class TenantBindingUtils { + + public static final boolean SET_PROP_IF_MISSING = true; + public static final boolean SET_PROP_ALWAYS = false; + + /** + * @param tenantBinding + * @param propName the property to fetch + * @return the String value of the named property + */ + public static String getPropertyValue(TenantBindingType tenantBinding, + String propName) { + if(propName==null) { + throw new IllegalArgumentException("TenantBindingUtils.getPropertyValues: null property name!"); + } + List tenantPropList = tenantBinding.getProperties(); + return PropertyItemUtils.getPropertyValueFromNodeList(tenantPropList, propName ); + } + + /** + * @param service + * @param propName the property to fetch + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValue(TenantBindingType tenantBinding, + PropertyItemType prop, boolean onlyIfNotSet) { + if(prop==null) { + throw new IllegalArgumentException( + "TenantBindingUtils.setPropertyValue: null property!"); + } + return setPropertyValue(tenantBinding, prop.getKey(), prop.getValue(), + onlyIfNotSet); + } + + /** + * @param tenantBinding + * @param propName the property to fetch + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValue(TenantBindingType tenantBinding, + String propName, String value, + boolean onlyIfNotSet) { + boolean valueFound = false; + boolean valueSet = false; + if(propName==null) { + throw new IllegalArgumentException("TenantBindingUtils.setPropertyValue: null property name!"); + } + List tenantPropertiesNode = tenantBinding.getProperties(); + return PropertyItemUtils.setPropertyValueInNodeList(tenantPropertiesNode, + propName, value, onlyIfNotSet); + } + + + /** + * @param tenantBinding + * @param propName the property to fetch + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static void propagatePropertiesToServices( + TenantBindingType tenantBinding, boolean onlyIfNotSet) { + List tenantPropList = + tenantBinding.getProperties().get(0).getItem(); + for(PropertyItemType tenantPropItem:tenantPropList) { + for(ServiceBindingType service:tenantBinding.getServiceBindings()) { + ServiceBindingUtils.setPropertyValue(service, + tenantPropItem, onlyIfNotSet); + } + } + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 9542d9012..2715a1b1f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -38,6 +38,7 @@ import org.collectionspace.authentication.CSpaceTenant; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.config.PropertyItemUtils; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.ValidatorHandler; @@ -126,25 +127,30 @@ public abstract class AbstractServiceContextImpl return objectPartMap; } - public List getPropertiesForPart(String partLabel) { - Map partMap = getPartsMetadata(); - ObjectPartType part = partMap.get(partLabel); - if (part == null) { - throw new RuntimeException("No such part found: " + partLabel); - } - return part.getProperties(); + public List getPropertiesForPart(String partLabel) { + Map partMap = getPartsMetadata(); + ObjectPartType part = partMap.get(partLabel); + if(part==null) { + throw new RuntimeException("No such part found: "+partLabel); + } + List propNodeList = part.getProperties(); + return propNodeList.isEmpty()?null:propNodeList.get(0).getItem(); } public List getPropertyValuesForPart(String partLabel, String propName) { - List allProps = getPropertiesForPart(partLabel); - return ServiceBindingUtils.getPropertyValuesByName(allProps, propName); + List allProps = getPropertiesForPart(partLabel); + return PropertyItemUtils.getPropertyValuesByName(allProps, propName); } - public List getPropertyValues(String propName) { - return ServiceBindingUtils.getPropertyValues(getServiceBinding(), propName); + public List getAllPartsPropertyValues(String propName) { + return ServiceBindingUtils.getAllPartsPropertyValues(getServiceBinding(), propName); + } + + public String getServiceBindingPropertyValue(String propName) { + return ServiceBindingUtils.getPropertyValue(getServiceBinding(), propName); } - public List getCommonPartProperties() { + public List getCommonPartProperties() { return getPropertiesForPart(getCommonPartLabel()); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java index f9c39ef9a..31e2f4db5 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java @@ -4,9 +4,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.collectionspace.services.common.config.PropertyItemUtils; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.common.service.ServiceObjectType; +import org.collectionspace.services.common.tenant.TenantBindingType; import org.collectionspace.services.common.types.PropertyItemType; import org.collectionspace.services.common.types.PropertyType; @@ -21,13 +23,14 @@ public class ServiceBindingUtils { } } - public static List getPropertiesForPart(ServiceBindingType serviceBinding, + public static List getPropertiesForPart(ServiceBindingType serviceBinding, String partLabel) { ServiceObjectType objectType = serviceBinding.getObject(); List objectPartTypes = objectType.getPart(); for (ObjectPartType objectPartType : objectPartTypes) { if(partLabel.equals(objectPartType.getLabel())) { - return objectPartType.getProperties(); + List propNodeList = objectPartType.getProperties(); + return propNodeList.isEmpty()?null:propNodeList.get(0).getItem(); } } throw new RuntimeException("No such part found: "+partLabel); @@ -35,47 +38,69 @@ public class ServiceBindingUtils { public static List getPropertyValuesForPart(ServiceBindingType serviceBinding, String partLabel, String propName) { - List partProps = getPropertiesForPart(serviceBinding, partLabel); - return getPropertyValuesByName(partProps, propName); + List partProps = getPropertiesForPart(serviceBinding, partLabel); + return PropertyItemUtils.getPropertyValuesByName(partProps, propName); } - public static List getPropertyValuesByName(List partProps, String propName) { - List values = new ArrayList(); - if(partProps.size()>0) { - List propItems = partProps.get(0).getItem(); - for(PropertyItemType propItem:propItems) { - if(propName.equals(propItem.getKey())) { - String value = propItem.getValue(); - if(value!=null) { - values.add(value); - } - } - } - } - return values; - } - - public static List getPropertyValues(ServiceBindingType serviceBinding, + public static List getAllPartsPropertyValues(ServiceBindingType serviceBinding, String propName) { List values = new ArrayList(); ServiceObjectType objectType = serviceBinding.getObject(); List objectPartTypes = objectType.getPart(); for (ObjectPartType objectPartType : objectPartTypes) { - List partProps = objectPartType.getProperties(); - if(partProps.size()>0) { - List propItems = partProps.get(0).getItem(); - for(PropertyItemType propItem:propItems) { - if(propName.equals(propItem.getKey())) { - String value = propItem.getValue(); - if(value!=null) { - values.add(value); - } - } - } - } + List propNodeList = objectPartType.getProperties(); + PropertyItemUtils.getPropertyValuesByNameInNodeList(propNodeList, propName, values); } return values; } - + /** + * @param service + * @param propName the property to fetch + * @return the String value of the named property + */ + public static String getPropertyValue(ServiceBindingType service, + String propName) { + if(propName==null) { + throw new IllegalArgumentException("ServiceBindingUtils.getPropertyValues: null property name!"); + } + List servicePropList = service.getProperties(); + return PropertyItemUtils.getPropertyValueFromNodeList(servicePropList, propName ); + } + + /** + * @param service + * @param propName the property to set + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValue(ServiceBindingType service, + PropertyItemType prop, boolean onlyIfNotSet) { + if(prop==null) { + throw new IllegalArgumentException( + "ServiceBindingUtils.setPropertyValue: null property!"); + } + return setPropertyValue(service, prop.getKey(), prop.getValue(), + onlyIfNotSet); + } + + /** + * @param service + * @param propName the property to set + * @param value the new value to set + * @param onlyIfNotSet if true, will not override an existing value + * @return true if set, false if an existing value was left as is. + */ + public static boolean setPropertyValue(ServiceBindingType service, + String propName, String value, + boolean onlyIfNotSet) { + if(propName==null) { + throw new IllegalArgumentException("ServiceBindingUtils.setPropertyValue: null property name!"); + } + List servicePropertiesNode = service.getProperties(); + return PropertyItemUtils.setPropertyValueInNodeList(servicePropertiesNode, + propName, value, onlyIfNotSet); + } + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index ac06bd2f4..9cebceadb 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -195,6 +195,12 @@ public interface ServiceContext { * setProperty sets user-defined property with given name */ public void setProperty(String name, Object o); + + /** + * getServiceBindingPropertyValue returns configured property + */ + public String getServiceBindingPropertyValue(String propName); + /** diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index 3abbe7c93..39fb955d8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -44,7 +44,7 @@ public abstract class AbstractDocumentHandlerImpl private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandlerImpl.class); private Map properties = new HashMap(); - private DocumentFilter docFilter = new DocumentFilter(); + private DocumentFilter docFilter = null; private ServiceContext serviceContext; public AbstractDocumentHandlerImpl() { @@ -77,7 +77,7 @@ public abstract class AbstractDocumentHandlerImpl } @Override - public abstract DocumentFilter createDocumentFilter(); + public abstract DocumentFilter createDocumentFilter(ServiceContext ctx); /** * @return the DocumentFilter diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 72fb4d30a..1fd48204e 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -33,6 +33,7 @@ import org.jboss.resteasy.specimpl.MultivaluedMapImpl; */ public class DocumentFilter { + public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault"; public static final String PAGE_SIZE_PARAM = "pgSz"; public static final String START_PAGE_PARAM = "pgNum"; public static final int DEFAULT_PAGE_SIZE_INIT = 40; @@ -103,17 +104,11 @@ public class DocumentFilter { if (list != null) { pageSizeStr = list.get(0); } + setPageSize(pageSizeStr); list = queryParams.remove(START_PAGE_PARAM); if (list != null) { startPageStr = list.get(0); } - if (pageSizeStr != null) { - try { - pageSize = Integer.valueOf(pageSizeStr); - } catch (NumberFormatException e) { - throw new NumberFormatException("Bad value for: " + PAGE_SIZE_PARAM); - } - } if (startPageStr != null) { try { startPage = Integer.valueOf(startPageStr); @@ -205,6 +200,19 @@ public class DocumentFilter { this.pageSize = pageSize; } + /** + * @param pageSize the max number of items to return for list requests + */ + public void setPageSize(String pageSizeStr) { + if (pageSizeStr != null) { + try { + pageSize = Integer.valueOf(pageSizeStr); + } catch (NumberFormatException e) { + throw new NumberFormatException("Bad value for: " + PAGE_SIZE_PARAM); + } + } + } + /** * @return the offset computed from the startPage and the pageSize */ diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index fb28393e9..360169c22 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -229,9 +229,11 @@ public interface DocumentHandler { * createDocumentFilter is a factory method to create a document * filter that is relevant to be used with this document handler * and corresponding storage client + * + * @param ctx ServiceContext used to fetch default pagination, etc. * @return */ - public DocumentFilter createDocumentFilter(); + public DocumentFilter createDocumentFilter(ServiceContext ctx); /** * getDocumentFilter diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java index 6568653fb..70a282c48 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java @@ -127,7 +127,7 @@ public class JpaStorageClientImpl implements StorageClient { throw new IllegalArgumentException( "JpaStorageClient.get: handler is missing"); } - DocumentFilter docFilter = handler.getDocumentFilter(); + DocumentFilter docFilter = handler.createDocumentFilter(ctx); if (docFilter == null) { throw new IllegalArgumentException( "JpaStorageClient.get: handler has no Filter specified"); @@ -212,7 +212,7 @@ public class JpaStorageClientImpl implements StorageClient { throw new IllegalArgumentException( "JpaStorageClient.getFiltered: handler is missing"); } - DocumentFilter docFilter = handler.getDocumentFilter(); + DocumentFilter docFilter = handler.createDocumentFilter(ctx); if (docFilter == null) { throw new IllegalArgumentException( "JpaStorageClient.getFiltered: handler has no Filter specified"); diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 83c0ec18b..98aab7e38 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -68,7 +68,7 @@ public class RefNameServiceUtils { ArrayList docTypes = new ArrayList(); StringBuilder whereClause = new StringBuilder(); for(ServiceBindingType sb:servicebindings) { - List authRefFields = ServiceBindingUtils.getPropertyValues(sb, AUTH_REF_PROP); + List authRefFields = ServiceBindingUtils.getAllPartsPropertyValues(sb, AUTH_REF_PROP); String docType = sb.getObject().getName(); docTypes.add(docType); for(String field:authRefFields) { diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 3a97be2a1..005229fb2 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -23,6 +23,7 @@ */ package org.collectionspace.services.nuxeo.client.java; +import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; @@ -114,8 +115,12 @@ public abstract class DocumentModelHandler public abstract void setCommonPartList(TL obj); @Override - public DocumentFilter createDocumentFilter() { - return new NuxeoDocumentFilter(); + public DocumentFilter createDocumentFilter(ServiceContext ctx) { + DocumentFilter filter = new NuxeoDocumentFilter(); + filter.setPageSize( + ctx.getServiceBindingPropertyValue( + DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY)); + return filter; } } diff --git a/services/common/src/main/resources/service-config.xsd b/services/common/src/main/resources/service-config.xsd index 06b12d008..514d3fd17 100644 --- a/services/common/src/main/resources/service-config.xsd +++ b/services/common/src/main/resources/service-config.xsd @@ -13,10 +13,13 @@ + + @@ -40,6 +43,7 @@ + diff --git a/services/common/src/main/resources/service.xsd b/services/common/src/main/resources/service.xsd index c6d97a40c..e55c43754 100644 --- a/services/common/src/main/resources/service.xsd +++ b/services/common/src/main/resources/service.xsd @@ -44,6 +44,7 @@ + diff --git a/services/common/src/main/resources/tenant.xsd b/services/common/src/main/resources/tenant.xsd index a9811f120..5dd8ea1ac 100644 --- a/services/common/src/main/resources/tenant.xsd +++ b/services/common/src/main/resources/tenant.xsd @@ -41,6 +41,7 @@ --> + diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java index 0c4005807..8167a2c70 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java @@ -452,7 +452,7 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl { // perform a keyword search if (keywords != null && !keywords.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); - DocumentFilter documentFilter = handler.getDocumentFilter(); + DocumentFilter documentFilter = handler.createDocumentFilter(ctx); documentFilter.setWhereClause(whereClause); if (logger.isDebugEnabled()) { logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 122867b2c..367a4130c 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -300,7 +300,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); MultivaluedMap queryParams = ui.getQueryParameters(); DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { @@ -511,7 +511,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" + @@ -563,7 +563,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl { ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx);// new DocumentFilter(); myFilter.setPagination(queryParams); // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'" @@ -751,7 +751,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName()); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + ContactJAXBSchema.IN_AUTHORITY + diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index cfb962a7f..8bdf3a9b5 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -243,8 +243,6 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl @GET @Path("{csid}") public MultipartOutput getPersonAuthority(@PathParam("csid") String csid) { - String idValue = null; - DocumentFilter myFilter = null; if (csid == null) { logger.error("getPersonAuthority: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( @@ -298,7 +296,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); MultivaluedMap queryParams = ui.getQueryParameters(); DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { @@ -509,7 +507,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" @@ -565,7 +563,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" @@ -753,7 +751,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName()); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + ContactJAXBSchema.IN_AUTHORITY + diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index b740f96e4..9eedd8298 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -206,7 +206,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); MultivaluedMap queryParams = ui.getQueryParameters(); DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { @@ -413,7 +413,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = new DocumentFilter(); + DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); myFilter.setPagination(queryParams); // "vocabularyitems_common:inVocabulary='" + parentcsid + "'"); myFilter.setWhereClause( -- 2.47.3