Added basic support to filter objects in a get, with a default filtering for pagination. Only implemented for Vocabulary at this point. Used this to intelligently filter the vocabularyItems associated to a given vocabulary, and to support finding a vocabulary by name.
private ServiceBindingType serviceBinding;
private TenantBindingType tenantBinding;
+ private String overrideDocumentType = null;
+
public AbstractServiceContext(String serviceName) {
TenantBindingConfigReader tReader =
ServiceMain.getInstance().getTenantBindingConfigReader();
@Override
public String getServiceName() {
return serviceBinding.getName();
+ }
+
+ @Override
+ public String getDocumentType() {
+ // If they have not overridden the setting, use the type of the service
+ // object.
+ return(overrideDocumentType!=null)?overrideDocumentType:
+ serviceBinding.getObject().get(0).getName();
+ }
+
+ @Override
+ public void setDocumentType(String docType) {
+ overrideDocumentType = docType;
}
@Override
public interface ServiceContext<T1, T2> {
/**
- * The charactor used to separtate the words in a part label
+ * The character used to separate the words in a part label
*/
public static final String PART_LABEL_SEPERATOR = "_";
public static final String PART_COMMON_LABEL = "common";
*/
public String getServiceName();
+ /**
+ * getDocumentType returns the name of the (primary) DocumentType for this service
+ * The value defaults to the Service Name, unless overridden with setDocumentType();
+ * @return service name
+ */
+ public String getDocumentType();
+
+ /**
+ * setDocumentType sets the name of the Document Type for this service
+ * The value defaults to the Service Name.
+ * @return service name
+ */
+ public void setDocumentType(String docType);
+
/**
* getQualifiedServiceName returns tenant id qualified service name
* @return tenant qualified service name
private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandler.class);
private Map<String, Object> properties = new HashMap<String, Object>();
+ private DocumentFilter docFilter = new DocumentFilter();
private ServiceContext serviceContext;
public AbstractDocumentHandler() {
this.properties = properties;
}
+ /**
+ * @return the DocumentFilter
+ */
+ @Override
+ public DocumentFilter getDocumentFilter() {
+ return docFilter;
+ }
+
+ /**
+ * @param properties the DocumentFilter to set
+ */
+ @Override
+ public void setDocumentFilter(DocumentFilter docFilter) {
+ this.docFilter = docFilter;
+ }
+
@Override
public void prepare(Action action) throws Exception {
//no specific action needed
--- /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
+package org.collectionspace.services.common.repository;\r
+\r
+/**\r
+ * DocumentFilter bundles simple query filtering parameters. \r
+ * It is designed to be used with filtered get and search calls to RepositoryClient.\r
+ * The values are set up and stored on a DocumentHandler, and\r
+ * fetched by a RepositoryClient when calling filtered get methods.\r
+ */\r
+public class DocumentFilter {\r
+ public static final int DEFAULT_PAGE_SIZE_INIT = 40;\r
+ public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;\r
+ protected String whereClause; // Filtering clause. Omit the "WHERE".\r
+ protected int startPage; // Pagination offset for list results\r
+ protected int pageSize; // Pagination limit for list results\r
+\r
+ public DocumentFilter() {\r
+ this("", 0, defaultPageSize); // Use empty string for easy concatenation\r
+ }\r
+ \r
+ public DocumentFilter(String whereClause, int startPage, int pageSize) {\r
+ this.whereClause = whereClause;\r
+ this.startPage = (startPage>0)?startPage:0;\r
+ this.pageSize = (pageSize>0)?pageSize:defaultPageSize;\r
+ }\r
+ \r
+ /**\r
+ * @return the current default page size for new DocumentFilter instances\r
+ */\r
+ public static int getDefaultPageSize() {\r
+ return defaultPageSize;\r
+ }\r
+\r
+ /**\r
+ * @param defaultPageSize the working default page size for new DocumentFilter instances\r
+ */\r
+ public static void setDefaultPageSize(int defaultPageSize) {\r
+ DocumentFilter.defaultPageSize = defaultPageSize;\r
+ }\r
+\r
+ /**\r
+ * @return the WHERE filtering clause\r
+ */\r
+ public String getWhereClause() {\r
+ return whereClause;\r
+ }\r
+\r
+ /**\r
+ * @param whereClause the filtering clause (do not include "WHERE")\r
+ */\r
+ public void setWhereClause(String whereClause) {\r
+ this.whereClause = whereClause;\r
+ }\r
+ \r
+ /**\r
+ * @return the specified (0-based) page offset \r
+ */\r
+ public int getStartPage() {\r
+ return startPage;\r
+ }\r
+ \r
+ /**\r
+ * @param startPage the (0-based) page offset to use\r
+ */\r
+ public void setStartPage(int startPage) {\r
+ this.startPage = startPage;\r
+ }\r
+ \r
+ /**\r
+ * @return the max number of items to return for list requests\r
+ */\r
+ public int getPageSize() {\r
+ return pageSize;\r
+ }\r
+\r
+ /**\r
+ * @param pageSize the max number of items to return for list requests\r
+ */\r
+ public void setPageSize(int pageSize) {\r
+ this.pageSize = pageSize;\r
+ }\r
+\r
+ /**\r
+ * @return the offset computed from the startPage and the pageSize\r
+ */\r
+ public int getOffset() {\r
+ return pageSize*startPage;\r
+ }\r
+\r
+\r
+}\r
*/
public void setProperties(Map<String, Object> properties);
+ /**
+ * getDocumentFilter
+ * @return
+ */
+ public DocumentFilter getDocumentFilter();
+
+ /**
+ * setDocumentFilter provides means to the CollectionSpace service resource to
+ * set up DocumentFilter values before invoking any request via the client.
+ * @param docFilter
+ */
+ public void setDocumentFilter(DocumentFilter docFilter);
+
/**
* getCommonPart provides the common part of a CS object.
* @return common part of CS object
void get(ServiceContext ctx, String id, DocumentHandler handler) throws DocumentNotFoundException, DocumentException;
/**
- * getAll get all documents for an entity entity service from the Document repository
+ * getAll get all documents for an entity service from the Document repository
* @param ctx service context under which this method is invoked
* @param handler should be used by the caller to provide and transform the document
* @throws DocumentNotFoundException if workspace not found
*/
void getAll(ServiceContext ctx, DocumentHandler handler) throws DocumentNotFoundException, DocumentException;
+ /**
+ * getFiltered get all documents for an entity service from the Document repository,
+ * given filter parameters specified by the handler.
+ * @param ctx service context under which this method is invoked
+ * @param handler should be used by the caller to provide and transform the document
+ * @throws DocumentNotFoundException if workspace not found
+ * @throws DocumentException
+ */
+ void getFiltered(ServiceContext ctx, DocumentHandler handler) throws DocumentNotFoundException, DocumentException;
+
/**
* update given document in the Document repository
* @param ctx service context under which this method is invoked
import java.util.UUID;
-import org.collectionspace.services.common.repository.RepositoryClient;
+
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.repository.BadRequestException;
-import org.collectionspace.services.common.repository.DocumentNotFoundException;
-import org.collectionspace.services.common.repository.DocumentHandler;
import org.collectionspace.services.common.repository.DocumentException;
+import org.collectionspace.services.common.repository.DocumentFilter;
+import org.collectionspace.services.common.repository.DocumentHandler;
+import org.collectionspace.services.common.repository.DocumentNotFoundException;
+import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.repository.DocumentHandler.Action;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.nuxeo.common.utils.IdUtils;
}
}
}
+
+ /**
+ * getFiltered get all documents for an entity service from the Document repository,
+ * given filter parameters specified by the handler.
+ * @param ctx service context under which this method is invoked
+ * @param handler should be used by the caller to provide and transform the document
+ * @throws DocumentNotFoundException if workspace not found
+ * @throws DocumentException
+ */
+ public void getFiltered(ServiceContext ctx, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.getFiltered: handler is missing");
+ }
+ DocumentFilter docFilter = handler.getDocumentFilter();
+ if (docFilter == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.getFiltered: handler has no Filter specified");
+ }
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+ RepositoryInstance repoSession = null;
+ try {
+ handler.prepare(Action.GET_ALL);
+ repoSession = getRepositorySession();
+ StringBuilder query = new StringBuilder("SELECT * FROM ");
+ query.append(docType);
+ String where = docFilter.getWhereClause();
+ if((null!=where)&&(where.length()>0))
+ query.append(" WHERE "+where);
+ if(docFilter.getOffset()>0)
+ query.append(" OFFSET "+docFilter.getOffset());
+ if(docFilter.getPageSize()>0)
+ query.append(" LIMIT "+docFilter.getPageSize());
+ DocumentModelList docList = repoSession.query(query.toString());
+ //set repoSession to handle the document
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(
+ docList);
+ handler.handle(Action.GET_ALL, wrapDoc);
+ handler.complete(Action.GET_ALL, wrapDoc);
+ } 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);
+ }
+ }
+ }
+
+
/**
* update given document in the Nuxeo repository
</templates>
<rows>
<row><widget>displayName</widget></row>
+ <row><widget>refName</widget></row>
<row><widget>vocabType</widget></row>
</rows>
<widget name="displayName" type="text">
<labels>
- <label mode="any">Name</label>
+ <label mode="any">Display Name</label>
</labels>
<translated>true</translated>
<fields>
</properties>
</widget>
+ <widget name="refName" type="text">
+ <labels>
+ <label mode="any">RefName</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="vocabularies_common">refName</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="vocabType" type="text">
<labels>
<label mode="any">Type</label>
</templates>
<rows>
<row><widget>displayName</widget></row>
+ <row><widget>refName</widget></row>
<row><widget>inVocabulary</widget></row>
</rows>
<widget name="displayName" type="text">
<labels>
- <label mode="any">Name</label>
+ <label mode="any">Display Name</label>
</labels>
<translated>true</translated>
<fields>
</properties>
</widget>
+ <widget name="refName" type="text">
+ <labels>
+ <label mode="any">RefName</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="vocabularyitems_common">refName</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="inVocabulary" type="text">
<labels>
<label mode="any">Vocab</label>
<!-- Vocabulary Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
</xs:schema>
Part : Common
Used for: Nuxeo EP core document type
- $LastChangedRevision$
- $LastChangedDate$
+ $LastChangedRevision: 860 $
+ $LastChangedDate: 2009-10-14 14:48:05 -0700 (Wed, 14 Oct 2009) $
-->
<xs:schema
<!-- VocabularyItem Information Group -->
<!-- inVocabulary is the csid of the owning Vocabulary -->
<xs:element name="inVocabulary" type="xs:string" />
+ <xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
</xs:schema>
public void createEnumeration(String vocabName, List<String> enumValues ) {
- // Expected status code: 201 Created
- int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
- // Type of service request being tested
- ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-
- if(logger.isDebugEnabled()){
- logger.debug("Import: Create vocabulary: \"" + vocabName +"\"");
- }
- MultipartOutput multipart = createVocabularyInstance(vocabName, "enum");
- ClientResponse<Response> res = client.create(multipart);
-
- int statusCode = res.getStatus();
-
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create enumeration: \""+vocabName
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- }
- if(statusCode != EXPECTED_STATUS_CODE) {
- throw new RuntimeException("Unexpected Status when creating enumeration: \""
- +vocabName +"\", Status:"+ statusCode);
- }
-
- // Store the ID returned from this create operation
- // for additional tests below.
- String newVocabId = extractId(res);
- if(logger.isDebugEnabled()){
- logger.debug("Import: Created vocabulary: \"" + vocabName +"\" ID:"
- +newVocabId );
- }
- for(String itemName : enumValues){
- createItemInVocab(newVocabId, vocabName, itemName);
- }
+ // Expected status code: 201 Created
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ // Type of service request being tested
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
+ if(logger.isDebugEnabled()){
+ logger.debug("Import: Create vocabulary: \"" + vocabName +"\"");
+ }
+ MultipartOutput multipart = createVocabularyInstance(vocabName,
+ createRefName(vocabName), "enum");
+ ClientResponse<Response> res = client.create(multipart);
+
+ int statusCode = res.getStatus();
+
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+ throw new RuntimeException("Could not create enumeration: \""+vocabName
+ +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ }
+ if(statusCode != EXPECTED_STATUS_CODE) {
+ throw new RuntimeException("Unexpected Status when creating enumeration: \""
+ +vocabName +"\", Status:"+ statusCode);
+ }
+
+ // Store the ID returned from this create operation
+ // for additional tests below.
+ String newVocabId = extractId(res);
+ if(logger.isDebugEnabled()){
+ logger.debug("Import: Created vocabulary: \"" + vocabName +"\" ID:"
+ +newVocabId );
+ }
+ for(String itemName : enumValues){
+ createItemInVocab(newVocabId, vocabName, itemName, createRefName(itemName));
+ }
}
- private String createItemInVocab(String vcsid, String vocabName, String itemName) {
- // Expected status code: 201 Created
- int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
- // Type of service request being tested
- ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-
- if(logger.isDebugEnabled()){
- logger.debug("Import: Create Item: \""+itemName+"\" in vocabulary: \"" + vocabName +"\"");
- }
- MultipartOutput multipart = createVocabularyItemInstance(vcsid, itemName);
- ClientResponse<Response> res = client.createItem(vcsid, multipart);
-
- int statusCode = res.getStatus();
-
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create Item: \""+itemName
- +"\" in vocabulary: \"" + vocabName
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- }
- if(statusCode != EXPECTED_STATUS_CODE) {
- throw new RuntimeException("Unexpected Status when creating Item: \""+itemName
- +"\" in vocabulary: \"" + vocabName +"\", Status:"+ statusCode);
- }
-
- return extractId(res);
+ private String createItemInVocab(String vcsid, String vocabName, String itemName, String refName) {
+ // Expected status code: 201 Created
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ // Type of service request being tested
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
+ if(logger.isDebugEnabled()){
+ logger.debug("Import: Create Item: \""+itemName+"\" in vocabulary: \"" + vocabName +"\"");
+ }
+ MultipartOutput multipart = createVocabularyItemInstance(vcsid, itemName, refName);
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);
+
+ int statusCode = res.getStatus();
+
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+ throw new RuntimeException("Could not create Item: \""+itemName
+ +"\" in vocabulary: \"" + vocabName
+ +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ }
+ if(statusCode != EXPECTED_STATUS_CODE) {
+ throw new RuntimeException("Unexpected Status when creating Item: \""+itemName
+ +"\" in vocabulary: \"" + vocabName +"\", Status:"+ statusCode);
+ }
+
+ return extractId(res);
}
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
- private MultipartOutput createVocabularyInstance(String displayName, String vocabType) {
+ private MultipartOutput createVocabularyInstance(
+ String displayName, String refName, String vocabType) {
VocabulariesCommon vocabulary = new VocabulariesCommon();
vocabulary.setDisplayName(displayName);
+ vocabulary.setRefName(refName);
vocabulary.setVocabType(vocabType);
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
return multipart;
}
- private MultipartOutput createVocabularyItemInstance(String inVocabulary, String displayName) {
+ private MultipartOutput createVocabularyItemInstance(
+ String inVocabulary, String displayName, String refName) {
VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
vocabularyItem.setInVocabulary(inVocabulary);
vocabularyItem.setDisplayName(displayName);
+ vocabularyItem.setRefName(refName);
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
}
return id;
}
+
+ protected String createRefName(String displayName) {
+ return displayName.replaceAll("\\W", "");
+ }
public static void main(String[] args) {
final String SERVICE_PATH_COMPONENT = "vocabularies";
final String ITEM_SERVICE_PATH_COMPONENT = "items";
private String knownResourceId = null;
+ private String knownResourceRefName = null;
private String knownItemResourceId = null;
+
+ protected String createRefName(String displayName) {
+ return displayName.replaceAll("\\W", "");
+ }
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// Submit the request to the service and store the response.
String identifier = createIdentifier();
- MultipartOutput multipart = createVocabularyInstance(identifier);
+ String displayName = "displayName-" + identifier;
+ String refName = createRefName(displayName);
+ String typeName = "vocabType-" + identifier;
+ MultipartOutput multipart =
+ createVocabularyInstance(displayName, refName, typeName);
ClientResponse<Response> res = client.create(multipart);
int statusCode = res.getStatus();
// Store the ID returned from this create operation
// for additional tests below.
knownResourceId = extractId(res);
+ knownResourceRefName = refName;
if(logger.isDebugEnabled()){
logger.debug("create: knownResourceId=" + knownResourceId);
}
// Submit the request to the service and store the response.
String identifier = createIdentifier();
- MultipartOutput multipart = createVocabularyItemInstance(vcsid, identifier);
+ String refName = createRefName(identifier);
+ MultipartOutput multipart = createVocabularyItemInstance(vcsid, identifier, refName);
ClientResponse<Response> res = client.createItem(vcsid, multipart);
int statusCode = res.getStatus();
}
}
+ /*
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
+ public void readByName(String testName) throws Exception {
+
+ // Perform setup.
+ setupRead();
+
+ // Submit the request to the service and store the response.
+ ClientResponse<MultipartInput> res = client.read(knownResourceId);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ MultipartInput input = (MultipartInput) res.getEntity();
+ VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
+ client.getCommonPartName(), VocabulariesCommon.class);
+ Assert.assertNotNull(vocabulary);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ */
+
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
dependsOnMethods = {"createItem", "read"})
public void readItem(String testName) throws Exception {
// The only relevant ID may be the one used in update(), below.
// The only relevant ID may be the one used in update(), below.
- MultipartOutput multipart = createVocabularyItemInstance(knownResourceId, NON_EXISTENT_ID);
+ MultipartOutput multipart = createVocabularyItemInstance(
+ knownResourceId, NON_EXISTENT_ID, createRefName(NON_EXISTENT_ID));
ClientResponse<MultipartInput> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
int statusCode = res.getStatus();
}
private MultipartOutput createVocabularyInstance(String identifier) {
+ String displayName = "displayName-" + identifier;
+ String refName = createRefName(displayName);
+ String typeName = "vocabType-" + identifier;
return createVocabularyInstance(
- "displayName-" + identifier,
- "vocabType-" + identifier);
+ displayName, refName,typeName );
}
- private MultipartOutput createVocabularyInstance(String displayName, String vocabType) {
+ private MultipartOutput createVocabularyInstance(
+ String displayName, String refName, String vocabType) {
VocabulariesCommon vocabulary = new VocabulariesCommon();
vocabulary.setDisplayName(displayName);
+ if(refName!=null)
+ vocabulary.setRefName(refName);
vocabulary.setVocabType(vocabType);
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
}
private MultipartOutput createVocabularyItemInstance(String inVocabulary,
- String displayName) {
+ String displayName, String refName) {
VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
vocabularyItem.setInVocabulary(inVocabulary);
vocabularyItem.setDisplayName(displayName);
+ if(refName!=null)
+ vocabularyItem.setRefName(refName);
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(vocabularyItem,
MediaType.APPLICATION_XML_TYPE);
<!-- Vocabulary Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
</xs:sequence>
<!-- inVocabulary is the csid of the owning Vocabulary -->
<xs:element name="inVocabulary" type="xs:string" />
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="refName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
*/
package org.collectionspace.services.vocabulary;
+import java.util.List;
+import java.util.Map;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.context.RemoteServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.repository.DocumentFilter;
import org.collectionspace.services.common.repository.DocumentHandler;
import org.collectionspace.services.common.repository.DocumentNotFoundException;
import org.collectionspace.services.vocabulary.nuxeo.VocabularyHandlerFactory;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.util.HttpResponseCodes;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.client.NuxeoClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@GET
@Path("{csid}")
- public MultipartOutput getVocabulary(
- @PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
- logger.debug("getVocabulary with csid=" + csid);
- }
- if(csid == null || "".equals(csid)){
+ public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
+ String idValue = null;
+ if(csid == null){
logger.error("getVocabulary: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"get failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
+ if(logger.isDebugEnabled()){
+ logger.debug("getVocabulary with path(id)=" + csid);
+ }
MultipartOutput result = null;
try{
RemoteServiceContext ctx = createServiceContext(null);
DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).get(ctx, csid, handler);
+ getRepositoryClient(ctx).get(ctx, csid, handler);
result = ctx.getOutput();
}catch(DocumentNotFoundException dnfe){
if(logger.isDebugEnabled()){
try{
RemoteServiceContext ctx = createServiceContext(null);
DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).getAll(ctx, handler);
+ MultivaluedMap<String,String> queryParams = ui.getQueryParameters();
+ if(queryParams.size()>0) {
+ String nameQ = queryParams.getFirst("name");
+ if(nameQ!= null) {
+ DocumentFilter myFilter = new DocumentFilter(
+ "vocabularies_common:refName='"+nameQ+"'", 0, 0);
+ handler.setDocumentFilter(myFilter);
+ }
+ }
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
}catch(Exception e){
if(logger.isDebugEnabled()){
@PathParam("csid") String parentcsid,
@Context UriInfo ui) {
VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
+ RepositoryInstance repoSession = null;
+ NuxeoClient client = null;
try{
- // Note that we have to create the service context for the Items, not the main service
+ // Note that docType defaults to the ServiceName, so we're fine with that.
RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- // HACK This should be a search with the parentcsid. The
- // handler.getCommonPartList method will filter these for us,
- // which is really silly, but works for now.
- getRepositoryClient(ctx).getAll(ctx, handler);
+ /*
+ // Note that we replace the getAll() call with a basic search on the parent vocab
+ handler.prepare(Action.GET_ALL);
+ client = NuxeoConnector.getInstance().getClient();
+ repoSession = client.openRepository();
+ if (logger.isDebugEnabled()) {
+ logger.debug("getVocabularyItemList() repository root: " + repoSession.getRootDocument());
+ }
+ DocumentModelList docList =
+ repoSession.query("SELECT * FROM Vocabularyitem WHERE vocabularyitems_common:inVocabulary='"
+ +parentcsid+"'");
+ //set repoSession to handle the document
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(
+ docList);
+ handler.handle(Action.GET_ALL, wrapDoc);
+ handler.complete(Action.GET_ALL, wrapDoc);
+ */
+ DocumentFilter myFilter = new DocumentFilter(
+ "vocabularyitems_common:inVocabulary='"+parentcsid+"'", 0, 0);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
}catch(Exception e){
if(logger.isDebugEnabled()){
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
throw new WebApplicationException(response);
+ } finally {
+ if(repoSession != null) {
+ try {
+ // release session
+ client.releaseRepository(repoSession);
+ } catch (Exception e) {
+ logger.error("Could not close the repository session", e);
+ // no need to throw this service specific exception
+ }
+ }
}
return vocabularyItemObjectList;
}
Iterator<DocumentModel> iter = docList.iterator();
while(iter.hasNext()){
DocumentModel docModel = iter.next();
- String parentVocab = (String)docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
- VocabularyItemJAXBSchema.IN_VOCABULARY);
- if( !inVocabulary.equals(parentVocab))
- continue;
+ //String parentVocab = (String)docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
+ // VocabularyItemJAXBSchema.IN_VOCABULARY);
+ //if( !inVocabulary.equals(parentVocab))
+ // continue;
VocabularyitemListItem ilistItem = new VocabularyitemListItem();
ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
VocabularyItemJAXBSchema.DISPLAY_NAME));