final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;
final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;
final static String DEFAULT_SELECT_CLAUSE = "SELECT * FROM ";
+ final static String CSID_QUERY_PARAM = "csid";
//
* @return the string
*/
public String createWhereClauseForInvocableByMode(String schema, String mode);
+
+ /*
+ *
+ */
+ public String createWhereClauseFromCsid(String csid);
}
static public final String SUBJECT = "subjectCsid";
static public final String SUBJECT_REFNAME = "subjectRefName";
static public final String SUBJECT_QP = "sbj";
- static public final String SUBJECT_TYPE = "subjectType";
+// static public final String SUBJECT_TYPE = "subjectType";
static public final String SUBJECT_TYPE_QP = SUBJECT_QP + "Type";
/** The Constant PREDICATE. */
static public final String OBJECT = "objectCsid";
static public final String OBJECT_REFNAME = "objectRefName";
static public final String OBJECT_QP = "obj";
- static public final String OBJECT_TYPE = "objectType";
+// static public final String OBJECT_TYPE = "objectType";
static public final String OBJECT_TYPE_QP = OBJECT_QP + "Type";
}
import java.util.regex.PatternSyntaxException;
import org.collectionspace.services.common.config.PropertyItemUtils;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
import org.collectionspace.services.config.service.ObjectPartType;
import org.collectionspace.services.config.service.ServiceBindingType;
import org.collectionspace.services.config.service.ServiceObjectType;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
+
import java.lang.IndexOutOfBoundsException;
+
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.document.DocumentUtils;
import org.slf4j.Logger;
propName, value, onlyIfNotSet);
}
- public static String getMappedFieldInDoc( ServiceBindingType sb,
+ public static String getMappedFieldInDoc(ServiceBindingType sb,
String logicalFieldName, DocumentModel docModel ) {
// Now we have to get the number, which is configured as some field
// on each docType
}
private static ArrayList<String> commonProcedureServiceTypes = null;
+
+ /**
+ * Get the service name (service resource path) from the object name (Nuxeo document type)
+ * @param serviceName
+ * @param sb
+ * @return
+ */
+ public static String getServiceNameFromObjectName(TenantBindingConfigReaderImpl bindingReader, String tenantId, String docType) {
+ String result = null;
+
+ ServiceBindingType bindingType = bindingReader.getServiceBindingForDocType(tenantId, docType);
+ result = bindingType.getName().toLowerCase();
+
+ return result;
+ }
public static ArrayList<String> getCommonServiceTypes(boolean includeAuthorities) {
ArrayList<String> commonServiceTypes = new ArrayList<String>();
return queryManager.createWhereClauseFromAdvancedSearch(keywords);
}
+ static public String createWhereClauseFromCsid(String csid) {
+ return queryManager.createWhereClauseFromCsid(csid);
+ }
+
/**
* Creates the where clause for partial term match.
*
//import org.nuxeo.ecm.core.client.NuxeoClient;
+
+
import org.collectionspace.services.jaxb.InvocableJAXBSchema;
//import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;
//import org.collectionspace.services.nuxeo.client.java.NxConnect;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.common.invocable.InvocableUtils;
import org.collectionspace.services.common.storage.DatabaseProductType;
return filterClause.toString();
}
+ @Override
+ public String createWhereClauseFromCsid(String csid) {
+ String trimmed = (csid == null) ? "" : csid.trim();
+ if (trimmed.isEmpty()) {
+ throw new RuntimeException("No CSID specified.");
+ }
+
+ return NuxeoUtils.getByNameWhereClause(csid);
+ }
+
}
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.lifecycle.TransitionList;
import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException;
import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
+
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.nuxeo.ecm.core.NXCore;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
-import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.Blob;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentRef;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.NuxeoException;
import org.nuxeo.ecm.core.api.PathRef;
-import org.nuxeo.ecm.core.api.model.PropertyException;
+import org.nuxeo.ecm.core.api.PropertyException;
import org.nuxeo.ecm.core.io.DocumentPipe;
import org.nuxeo.ecm.core.io.DocumentReader;
import org.nuxeo.ecm.core.io.DocumentWriter;
} catch (Exception e) {
logger.error("Could not remove facet from DocumentModel instance: " + docModel.getId(), e);
}
-
+
return result;
}
bais = new ByteArrayInputStream(baos.toByteArray());
SAXReader saxReader = new SAXReader();
doc = saxReader.read(bais);
- } catch (ClientException ce) {
- throw new NuxeoDocumentException(ce);
- } catch (Exception e) {
+ } catch (org.dom4j.DocumentException ce) {
+ throw new DocumentException(ce);
+ } catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("Caught exception while processing document ", e);
}
*/
public static DocumentModel getWorkspaceModel(
CoreSessionInterface repoSession, String workspaceName)
- throws DocumentException, IOException, ClientException {
+ throws DocumentException, IOException {
DocumentModel result = null;
//FIXME: commented out as this does not work without tenant qualification
String workspaceUUID = null;
throws DocumentException {
DocumentModel result = null;
- try {
- DocumentRef documentRef = new IdRef(nuxeoId);
- result = repoSession.getDocument(documentRef);
- } catch (ClientException e) {
- throw new NuxeoDocumentException(e);
- }
-
+ DocumentRef documentRef = new IdRef(nuxeoId);
+ result = repoSession.getDocument(documentRef);
+
return result;
}
return result;
}
+ static public NuxeoBasedResource getDocumentResource(String csid) {
+ return null;
+ }
+
static public DocumentModel getDocFromSpecifier(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
CoreSessionInterface repoSession,
}
public static boolean documentExists(CoreSessionInterface repoSession,
- String csid) throws ClientException {
+ String csid) {
boolean result = false;
String statement = String.format(
public static String getTenantQualifiedDocType(QueryContext queryCtx, String docType) throws Exception {
String result = docType;
- try {
- String tenantQualifiedDocType = queryCtx.getTenantQualifiedDoctype();
- if (docTypeExists(tenantQualifiedDocType) == true) {
- result = tenantQualifiedDocType;
- }
- } catch (ClientException ce) {
- throw new NuxeoDocumentException(ce);
- }
+ String tenantQualifiedDocType = queryCtx.getTenantQualifiedDoctype();
+ if (docTypeExists(tenantQualifiedDocType) == true) {
+ result = tenantQualifiedDocType;
+ }
return result;
}
static private boolean docTypeExists(String docType) throws Exception {
boolean result = false;
- SchemaManager schemaManager = null;
- try {
- schemaManager = Framework.getService(org.nuxeo.ecm.core.schema.SchemaManager.class);
- } catch (ClientException ce) {
- throw new NuxeoDocumentException(ce);
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- logger.error("Could not get Nuxeo SchemaManager instance.", e1);
- throw e1;
- }
-
+ SchemaManager schemaManager = Framework.getService(org.nuxeo.ecm.core.schema.SchemaManager.class);
Set<String> docTypes = schemaManager.getDocumentTypeNamesExtending(docType);
if (docTypes != null && docTypes.contains(docType)) {
result = true;
}
-
+
return result;
}
* the DocumentModel.getPropertyValue method. This method catches that NPE and instead returns null.
*/
public static Object getProperyValue(DocumentModel docModel,
- String propertyName) throws ClientException, PropertyException {
+ String propertyName) {
Object result = null;
try {
import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.NuxeoBasedResource;
+import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.ServiceMessages;
import org.collectionspace.services.common.UriInfoWrapper;
import org.collectionspace.services.common.context.ServiceContextFactory;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.query.QueryManager;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm;
import org.collectionspace.services.config.service.ServiceBindingType;
import org.collectionspace.services.config.service.ServiceObjectType;
import org.collectionspace.services.nuxeo.client.java.CommonList;
+import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentFilter;
import org.collectionspace.services.servicegroup.nuxeo.ServiceGroupDocumentModelHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return result.getBytes();
}
-
@GET
@Path("{csid}/items")
- public AbstractCommonList getItems(
+ public AbstractCommonList getItemList(
@Context UriInfo uriInfo,
@PathParam("csid") String serviceGroupName) {
UriInfoWrapper ui = new UriInfoWrapper(uriInfo);
groupsList = new ArrayList<String>();
groupsList.add(serviceGroupName);
}
- // set up a keyword search
+
+ // check first for a csid query parameter
MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
- String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW);
- if (keywords != null && !keywords.isEmpty()) {
- String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
- if(Tools.isEmpty(whereClause)) {
+ String csid = queryParams.getFirst(IQueryManager.CSID_QUERY_PARAM);
+ if (csid != null && !csid.isEmpty()) {
+ String whereClause = QueryManager.createWhereClauseFromCsid(csid);
+ if (Tools.isEmpty(whereClause)) {
if (logger.isDebugEnabled()) {
- logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]");
+ logger.debug("The WHERE clause is empty for csid: ["+csid+"]");
}
} else {
DocumentFilter documentFilter = handler.getDocumentFilter();
logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
}
}
+ } else {
+ // check to see if we have to set up a keyword search
+ String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW);
+ if (keywords != null && !keywords.isEmpty()) {
+ String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ if(Tools.isEmpty(whereClause)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]");
+ }
+ } else {
+ DocumentFilter documentFilter = handler.getDocumentFilter();
+ documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ if (logger.isDebugEnabled()) {
+ logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+ }
+ }
+ }
}
- list = handler.getItemsForGroup(ctx, groupsList);
+
+ // make the query
+ list = handler.getItemListForGroup(ctx, groupsList);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName);
}
return list;
}
+ @GET
+ @Path("{csid}/items/{specifier}")
+ public byte[] getItem(
+ @Context ResourceMap resourceMap,
+ @Context UriInfo uriInfo,
+ @PathParam("csid") String serviceGroupName,
+ @PathParam("specifier") String specifier) {
+ UriInfoWrapper ui = new UriInfoWrapper(uriInfo);
+ ensureCSID(serviceGroupName, NuxeoBasedResource.READ);
+ PoxPayloadOut result = null;
+
+ try {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+ ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler)
+ createDocumentHandler(ctx);
+ ArrayList<String> groupsList = null;
+ if("common".equalsIgnoreCase(serviceGroupName)) {
+ groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES);
+ } else {
+ groupsList = new ArrayList<String>();
+ groupsList.add(serviceGroupName);
+ }
+
+ String whereClause = QueryManager.createWhereClauseFromCsid(specifier);
+ DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1);
+ handler.setDocumentFilter(myFilter);
+
+ result = handler.getItemForCsid(ctx, groupsList, specifier);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName);
+ }
+
+ return result.getBytes();
+ }
}
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.ServiceMessages;
protected static final String DOC_NUMBER_FIELD = "docNumber";
protected static final String DOC_NAME_FIELD = "docName";
- public AbstractCommonList getItemsForGroup(
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
- List<String> serviceGroupNames) throws Exception {
- CommonList commonList = new CommonList();
- AbstractCommonList list = (AbstractCommonList)commonList;
+ public PoxPayloadOut getItemForCsid(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ List<String> serviceGroupNames,
+ String csid) throws DocumentException {
+ PoxPayloadOut result = null;
CoreSessionInterface repoSession = null;
boolean releaseRepoSession = false;
repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
-
+ try {
+ Map<String, ServiceBindingType> queriedServiceBindings = new HashMap<String, ServiceBindingType>();
+ DocumentModelList docList = this.getDocListForGroup(ctx, serviceGroupNames, queriedServiceBindings,
+ repoSession, repoClient);
+ if (docList == null) { // found no authRef fields - nothing to process
+ //return list;
+ }
+ DocumentModel docModel = docList.get(0);
+ TenantBindingConfigReaderImpl bindingReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+ String serviceName = ServiceBindingUtils.getServiceNameFromObjectName(bindingReader, ctx.getTenantId(),
+ docModel.getDocumentType().getName());
+ NuxeoBasedResource resource = (NuxeoBasedResource) ctx.getResourceMap().get(serviceName);
+ resource.hashCode();
+
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (releaseRepoSession && repoSession != null) {
+ repoClient.releaseRepositorySession(ctx, repoSession);
+ }
+ }
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ }
+
+ return result;
+ }
+
+ private DocumentModelList getDocListForGroup(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ List<String> serviceGroupNames,
+ Map<String, ServiceBindingType> queriedServiceBindings,
+ CoreSessionInterface repoSession,
+ RepositoryClientImpl repoClient) throws Exception {
+
+ RepositoryClientImpl nuxeoRepoClient = (RepositoryClientImpl)repoClient;
+ // Get the service bindings for this tenant
+ TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+ // We need to get all the procedures, authorities, and objects.
+ List<ServiceBindingType> servicebindings =
+ tReader.getServiceBindingsByType(ctx.getTenantId(), serviceGroupNames);
+ if (servicebindings == null || servicebindings.isEmpty()) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ ServiceMessages.READ_FAILED +
+ ServiceMessages.resourceNotFoundMsg(implode(serviceGroupNames, ","))).type("text/plain").build();
+ throw new CSWebApplicationException(response);
+ }
+
+ servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings);
+ // Build the list of docTypes for allowed serviceBindings
+ ArrayList<String> docTypes = new ArrayList<String>();
+ for(ServiceBindingType binding:servicebindings) {
+ ServiceObjectType serviceObj = binding.getObject();
+ if(serviceObj!=null) {
+ String docType = serviceObj.getName();
+ docTypes.add(docType);
+ queriedServiceBindings.put(docType, binding);
+ }
+ }
+
+ // This should be type "Document" but CMIS is gagging on that right now.
+ ctx.getQueryParams().add(IQueryManager.SELECT_DOC_TYPE_FIELD, QueryManagerNuxeoImpl.COLLECTIONSPACE_DOCUMENT_TYPE);
+
+ // Now we have to issue the search
+ // The findDocs() method will build a QueryContext, which wants to see a docType for our context
+ ctx.setDocumentType(QueryManagerNuxeoImpl.NUXEO_DOCUMENT_TYPE);
+ DocumentWrapper<DocumentModelList> docListWrapper =
+ nuxeoRepoClient.findDocs(ctx, this, repoSession, docTypes );
+ // Now we gather the info for each document into the list and return
+ DocumentModelList docList = docListWrapper.getWrappedObject();
+
+ return docList;
+ }
+
+ public AbstractCommonList getItemListForGroup(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ List<String> serviceGroupNames) throws Exception {
+ CommonList commonList = new CommonList();
+ AbstractCommonList list = (AbstractCommonList)commonList;
+ CoreSessionInterface repoSession = null;
+ boolean releaseRepoSession = false;
+
+ try {
DocumentFilter myFilter = getDocumentFilter();
int pageSize = myFilter.getPageSize();
int pageNum = myFilter.getStartPage();
list.setPageNum(pageNum);
list.setPageSize(pageSize);
+
+ RepositoryClientImpl repoClient = (RepositoryClientImpl)this.getRepositoryClient(ctx);
+ repoSession = this.getRepositorySession();
+ if (repoSession == null) {
+ repoSession = repoClient.getRepositorySession(ctx);
+ releaseRepoSession = true;
+ }
try {
Map<String, ServiceBindingType> queriedServiceBindings = new HashMap<String, ServiceBindingType>();
- RepositoryClientImpl nuxeoRepoClient = (RepositoryClientImpl)repoClient;
- // Get the service bindings for this tenant
- TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
- // We need to get all the procedures, authorities, and objects.
- List<ServiceBindingType> servicebindings =
- tReader.getServiceBindingsByType(ctx.getTenantId(), serviceGroupNames);
- if (servicebindings == null || servicebindings.isEmpty()) {
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- ServiceMessages.READ_FAILED +
- ServiceMessages.resourceNotFoundMsg(implode(serviceGroupNames, ","))).type("text/plain").build();
- throw new CSWebApplicationException(response);
- }
-
- servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings);
- // Build the list of docTypes for allowed serviceBindings
- ArrayList<String> docTypes = new ArrayList<String>();
- for(ServiceBindingType binding:servicebindings) {
- ServiceObjectType serviceObj = binding.getObject();
- if(serviceObj!=null) {
- String docType = serviceObj.getName();
- docTypes.add(docType);
- queriedServiceBindings.put(docType, binding);
- }
- }
-
- // This should be type "Document" but CMIS is gagging on that right now.
- ctx.getQueryParams().add(IQueryManager.SELECT_DOC_TYPE_FIELD, QueryManagerNuxeoImpl.COLLECTIONSPACE_DOCUMENT_TYPE);
-
- // Now we have to issue the search
- // The findDocs() method will build a QueryContext, which wants to see a docType for our context
- ctx.setDocumentType(QueryManagerNuxeoImpl.NUXEO_DOCUMENT_TYPE);
- DocumentWrapper<DocumentModelList> docListWrapper =
- nuxeoRepoClient.findDocs(ctx, this, repoSession, docTypes );
- // Now we gather the info for each document into the list and return
- DocumentModelList docList = docListWrapper.getWrappedObject();
+ DocumentModelList docList = this.getDocListForGroup(ctx, serviceGroupNames, queriedServiceBindings,
+ repoSession, repoClient);
if (docList == null) { // found no authRef fields - nothing to process
return list;
}