import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
getRepositoryClient(ctx).getDoc(ctx, csid);
RemoteDocumentModelHandlerImpl handler
= (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
- List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
- String prefix = ctx.getCommonPartLabel()+":";
- authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
+ List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(RefNameServiceUtils.AUTH_REF_PROP);
+ authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.intake.IntakeResource;
import org.collectionspace.services.intake.IntakesCommonList;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
getRepositoryClient(ctx).getDoc(ctx, csid);
RemoteDocumentModelHandlerImpl handler
= (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
- List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
- String prefix = ctx.getCommonPartLabel()+":";
- authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
+ List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(RefNameServiceUtils.AUTH_REF_PROP);
+ authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
<!-- begin movingimages.us tenant meta-data -->
<tenant:tenantBinding
id="1" name="movingimages.us" displayName="Museum of Moving Images" version="0.1" repositoryDomain="default-domain">
- <tenant:serviceBindings name="CollectionObjects" version="0.1">
+ <tenant:serviceBindings name="CollectionObjects" type="object" version="0.1">
<!-- begin collectionobject service meta-data -->
<service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>
nuxeo-java
</tenant:serviceBindings>
<!--end collectionobject service meta-data -->
<!-- begin intake service meta-data -->
- <tenant:serviceBindings name="Intakes" version="0.1">
+ <tenant:serviceBindings name="Intakes" type="procedure" version="0.1">
<service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>
nuxeo-java
</service:repositoryClient>
</tenant:serviceBindings>
<!-- end person service meta-data -->
<!-- begin acquisition service meta-data -->
- <tenant:serviceBindings name="Acquisitions" version="0.1">
+ <tenant:serviceBindings name="Acquisitions" type="procedure" version="0.1">
<service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>
nuxeo-java
</service:repositoryClient>
package org.collectionspace.services.common.config;
import java.io.File;
+import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
+
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.RepositoryClientConfigType;
import org.collectionspace.services.common.ServiceMain;
return serviceBindings.get(key);
}
+ /**
+ * getServiceBinding gets service binding for given tenant for a given service
+ * @param tenantId
+ * @param serviceName
+ * @return
+ */
+ public List<ServiceBindingType> getServiceBindingsByType(
+ String tenantId, String serviceType) {
+ ArrayList<ServiceBindingType> list = null;
+ TenantBindingType tenant = tenantBindings.get(tenantId);
+ if(tenant!=null) {
+ for(ServiceBindingType sb:tenant.getServiceBindings()) {
+ if(sb.getType().equals(serviceType)) {
+ if(list==null)
+ list = new ArrayList<ServiceBindingType>();
+ list.add(sb);
+ }
+ }
+ }
+ return list;
+ }
+
/**
* getWorkspaceId retrieves workspace id for given tenant for given service
* @param tenantId
if (objectPartMap.size() != 0) {
return objectPartMap;
}
- ServiceBindingType serviceBinding = getServiceBinding();
- ServiceObjectType objectType = serviceBinding.getObject();
- List<ObjectPartType> objectPartTypes = objectType.getPart();
- for (ObjectPartType objectPartType : objectPartTypes) {
- objectPartMap.put(objectPartType.getLabel(), objectPartType);
- }
+ ServiceBindingUtils.getPartsMetadata(getServiceBinding(), objectPartMap);
return objectPartMap;
}
public List<String> getPropertyValuesForPart(String partLabel, String propName) {
List<PropertyType> allProps = getPropertiesForPart(partLabel);
- List<String> values = new ArrayList<String>();
- if(allProps.size()>0) {
- List<PropertyItemType> propItems = allProps.get(0).getItem();
- for(PropertyItemType propItem:propItems) {
- if(propName.equals(propItem.getKey())) {
- String value = propItem.getValue();
- if(value!=null) {
- values.add(value);
- }
- }
- }
- }
- return values;
+ return ServiceBindingUtils.getPropertyValuesByName(allProps, propName);
}
+ public List<String> getPropertyValues(String propName) {
+ return ServiceBindingUtils.getPropertyValues(getServiceBinding(), propName);
+ }
+
public List<PropertyType> getCommonPartProperties() {
return getPropertiesForPart(getCommonPartLabel());
}
--- /dev/null
+package org.collectionspace.services.common.context;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.collectionspace.services.common.service.ObjectPartType;\r
+import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.common.service.ServiceObjectType;\r
+import org.collectionspace.services.common.types.PropertyItemType;\r
+import org.collectionspace.services.common.types.PropertyType;\r
+\r
+public class ServiceBindingUtils {\r
+\r
+ public static void getPartsMetadata(ServiceBindingType serviceBinding, \r
+ Map<String, ObjectPartType> objectPartMap) {\r
+ ServiceObjectType objectType = serviceBinding.getObject();\r
+ List<ObjectPartType> objectPartTypes = objectType.getPart();\r
+ for (ObjectPartType objectPartType : objectPartTypes) {\r
+ objectPartMap.put(objectPartType.getLabel(), objectPartType);\r
+ }\r
+ }\r
+ \r
+ public static List<PropertyType> getPropertiesForPart(ServiceBindingType serviceBinding,\r
+ String partLabel) {\r
+ ServiceObjectType objectType = serviceBinding.getObject();\r
+ List<ObjectPartType> objectPartTypes = objectType.getPart();\r
+ for (ObjectPartType objectPartType : objectPartTypes) {\r
+ if(partLabel.equals(objectPartType.getLabel())) {\r
+ return objectPartType.getProperties();\r
+ }\r
+ }\r
+ throw new RuntimeException("No such part found: "+partLabel);\r
+ }\r
+\r
+ public static List<String> getPropertyValuesForPart(ServiceBindingType serviceBinding,\r
+ String partLabel, String propName) {\r
+ List<PropertyType> partProps = getPropertiesForPart(serviceBinding, partLabel);\r
+ return getPropertyValuesByName(partProps, propName);\r
+ }\r
+\r
+ public static List<String> getPropertyValuesByName(List<PropertyType> partProps, String propName) {\r
+ List<String> values = new ArrayList<String>();\r
+ if(partProps.size()>0) {\r
+ List<PropertyItemType> propItems = partProps.get(0).getItem();\r
+ for(PropertyItemType propItem:propItems) {\r
+ if(propName.equals(propItem.getKey())) {\r
+ String value = propItem.getValue();\r
+ if(value!=null) {\r
+ values.add(value);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return values;\r
+ }\r
+\r
+ public static List<String> getPropertyValues(ServiceBindingType serviceBinding,\r
+ String propName) {\r
+ List<String> values = new ArrayList<String>();\r
+ ServiceObjectType objectType = serviceBinding.getObject();\r
+ List<ObjectPartType> objectPartTypes = objectType.getPart();\r
+ for (ObjectPartType objectPartType : objectPartTypes) {\r
+ List<PropertyType> partProps = objectPartType.getProperties();\r
+ if(partProps.size()>0) {\r
+ List<PropertyItemType> propItems = partProps.get(0).getItem();\r
+ for(PropertyItemType propItem:propItems) {\r
+ if(propName.equals(propItem.getKey())) {\r
+ String value = propItem.getValue();\r
+ if(value!=null) {\r
+ values.add(value);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return values;\r
+ }\r
+\r
+\r
+}\r
*/
package org.collectionspace.services.common.repository;
+import java.util.List;
+
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.storage.StorageClient;
import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
/**
* RepositoryClient is a generic Document Repository client
*/
public String createWorkspace(String tenantDomain, String workspaceName) throws Exception;
- /**
+ /**
* getWorkspaceId gets an id of given workspace in default repository under given domain
* @param tenantDomain domain representing tenant
* @param workspaceName name of the workspace
throws DocumentNotFoundException, DocumentException;
/**
- * find wrapped documentModel from the Nuxeo repository
+ * Find wrapped documentModel from the Nuxeo repository
* @param ctx service context under which this method is invoked
* @param specifies docType. If null, uses ctx.getDocumentType()
* @param where NXQL where clause to get the document
throws DocumentNotFoundException, DocumentException;
/**
- * find doc and return CSID from the Nuxeo repository
+ * Find doc and return CSID from the Nuxeo repository
* @param ctx service context under which this method is invoked
* @param specifies docType. If null, uses ctx.getDocumentType()
* @param where NXQL where clause to get the document
ServiceContext ctx, String where)
throws DocumentNotFoundException, DocumentException;
+ /**
+ * Find a list of documentModels from the Nuxeo repository
+ * @param docTypes a list of DocType names to match
+ * @param where the clause to qualify on
+ * @param domain the domain for the associated services
+ * @return
+ */
+ public DocumentWrapper<DocumentModelList> findDocs(
+ List<String> docTypes, String where, String domain,
+ int pageSize, int pageNum, boolean computeTotal )
+ throws DocumentNotFoundException, DocumentException;
}
--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+\r
+ * Copyright 2009 University of California at Berkeley\r
+\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.collectionspace.services.common.vocabulary;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.nuxeo.ecm.core.api.DocumentModelList;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.collectionspace.services.common.ServiceMain;\r
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
+import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.common.context.ServiceBindingUtils;\r
+import org.collectionspace.services.common.document.DocumentException;\r
+import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+import org.collectionspace.services.common.document.DocumentWrapper;\r
+import org.collectionspace.services.common.repository.RepositoryClient;\r
+import org.collectionspace.services.common.service.ServiceBindingType;\r
+\r
+/**\r
+ * RefNameServiceUtils is a collection of services utilities related to refName usage.\r
+ *\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ */\r
+public class RefNameServiceUtils {\r
+ \r
+ public static final String AUTH_REF_PROP = "authRef";\r
+\r
+ private final Logger logger = LoggerFactory.getLogger(RefNameServiceUtils.class);\r
+ \r
+ public AuthorityRefDocList getAuthorityRefDocs(RepositoryClient repoClient, \r
+ String tenantId, String serviceType, String refName,\r
+ int pageSize, int pageNum, boolean computeTotal )\r
+ throws DocumentException, DocumentNotFoundException {\r
+ AuthorityRefDocList wrapperList = new AuthorityRefDocList();\r
+ List<AuthorityRefDocList.AuthorityRefDocItem> list = \r
+ wrapperList.getAuthorityRefDocItem();\r
+ TenantBindingConfigReaderImpl tReader =\r
+ ServiceMain.getInstance().getTenantBindingConfigReader();\r
+ List<ServiceBindingType> servicebindings = tReader.getServiceBindingsByType(tenantId, serviceType);\r
+ if(servicebindings==null || servicebindings.size()>0)\r
+ return null;\r
+ String domain = tReader.getTenantBinding(tenantId).getRepositoryDomain();\r
+ ArrayList<String> docTypes = new ArrayList<String>(); \r
+ StringBuilder whereClause = new StringBuilder();\r
+ for(ServiceBindingType sb:servicebindings) {\r
+ List<String> authRefFields = ServiceBindingUtils.getPropertyValues(sb, AUTH_REF_PROP);\r
+ String docType = sb.getObject().getName();\r
+ docTypes.add(docType);\r
+ for(String field:authRefFields) {\r
+ // Build up the where clause for each authRef field\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ }\r
+ // Now we have to issue the search\r
+ DocumentWrapper<DocumentModelList> docListWrapper = repoClient.findDocs(\r
+ docTypes, whereClause.toString(), domain, pageSize, pageNum, computeTotal );\r
+ return null;\r
+ }\r
+\r
+ \r
+}\r
+\r
public AuthorityRefList getAuthorityRefs(
DocumentWrapper<DocumentModel> docWrapper,
- String pathPrefix,
List<String> authRefFields) {
AuthorityRefList authRefList = new AuthorityRefList();
try {
authRefList.getAuthorityRefItem();
for(String field:authRefFields){
- String refName = (String)docModel.getPropertyValue(pathPrefix+field);
+ String refName = (String)docModel.getPropertyValue(field);
if(refName==null)
continue;
try{
return csid;
}
+ /**
+ * Find a list of documentModels from the Nuxeo repository
+ * @param docTypes a list of DocType names to match
+ * @param where the clause to qualify on
+ * @param domain the domain for the associated services
+ * @return
+ */
+ @Override
+ public DocumentWrapper<DocumentModelList> findDocs(
+ List<String> docTypes, String where, String domain,
+ int pageSize, int pageNum, boolean computeTotal )
+ throws DocumentNotFoundException, DocumentException {
+ RepositoryInstance repoSession = null;
+ DocumentWrapper<DocumentModelList> wrapDoc = null;
+
+ try {
+ if (docTypes == null || docTypes.size()<1) {
+ throw new DocumentNotFoundException(
+ "findDocs must specify at least one DocumentType.");
+ }
+ if (domain == null) {
+ throw new DocumentNotFoundException("findDocs must specify Domain.");
+ }
+ repoSession = getRepositorySession();
+ DocumentModelList docList = null;
+ // force limit to 1, and ignore totalSize
+ String query = buildNXQLQuery(docTypes, where, domain );
+ docList = repoSession.query( query, null, pageSize, pageNum, computeTotal);
+ wrapDoc = new DocumentWrapperImpl<DocumentModelList>(docList);
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
+ return wrapDoc;
+ }
+
+
@Override
public void get(ServiceContext ctx, List<String> csidList, DocumentHandler handler)
throws DocumentNotFoundException, DocumentException {
return workspaceId;
}
- private final String buildNXQLQuery(String docType, String where, String domain ) {
- StringBuilder query = new StringBuilder("SELECT * FROM ");
- query.append(docType);
+ private final void appendNXQLWhere(StringBuilder query, String where, String domain ) {
// TODO This is a slow method for tenant-filter
// We should make this a property that is indexed.
query.append(" WHERE ecm:path STARTSWITH '/" + domain + "'");
// into SQL, we need to parenthesize our 'where' clause
query.append(" AND " + "(" + where +")" + "AND ecm:isProxy = 0");
}
+ }
+
+ private final String buildNXQLQuery(String docType, String where, String domain ) {
+ StringBuilder query = new StringBuilder("SELECT * FROM ");
+ query.append(docType);
+ appendNXQLWhere(query, where, domain );
+ return query.toString();
+ }
+
+ private final String buildNXQLQuery(List<String> docTypes, String where, String domain ) {
+ StringBuilder query = new StringBuilder("SELECT * FROM ");
+ boolean fFirst = true;
+ for(String docType:docTypes) {
+ if(fFirst) {
+ query.append(",");
+ fFirst = false;
+ }
+ query.append(docType);
+ }
+ appendNXQLWhere(query, where, domain );
return query.toString();
}
<xs:element name="repositoryWorkspaceId" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
+ <xs:attribute name="type" type="xs:string" use="optional"/>
<xs:attribute name="version" type="types:VersionType" use="required"/>
</xs:complexType>
* at any point during testing, even if some of those resources
* may be expected to be deleted by certain tests.
*/
- // @AfterClass(alwaysRun=true)
+ @AfterClass(alwaysRun=true)
public void cleanUp() {
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
getRepositoryClient(ctx).getDoc(ctx, csid);
RemoteDocumentModelHandlerImpl handler
= (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
- List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
- String prefix = ctx.getCommonPartLabel()+":";
- authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
+ List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(RefNameServiceUtils.AUTH_REF_PROP);
+ authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();