<fileset dir="${basedir}/nuxeo-server/${nuxeo.release}/config"/>\r
<filterset>\r
<filter token="DB" value="${db}" />\r
- <filter token="DB_URL" value="jdbc:${db}://localhost:${db.port}/nuxeo${db.url.suffix}" />\r
+ <filter token="DB_URL" value="jdbc:${db}://localhost:${db.port}/nuxeo"/>\r
<filter token="XA_DATASOURCE" value="${db.xaDataSource}" />\r
<filter token="NUXEO_USER" value="${db.nuxeo.user}" />\r
<filter token="NUXEO_PW" value="${db.nuxeo.user.password}" />\r
File below this line have been ported. -->\r
<!-- ============================================= -->\r
\r
+<!-- \r
<run controlFile="./security.xml" testGroup="deleteBug" />\r
<run controlFile="objectexit/object-exit.xml" testGroup="makeone" />\r
<run controlFile="objectexit/object-exit.xml" testGroup="checkList" />\r
<run controlFile="objectexit/object-exit-display.xml" testGroup="refNameDisplayNameOnly" />\r
-<!-- \r
-->\r
\r
+<!--\r
<run controlFile="collectionobject/collectionobject-adv-search.xml" testGroup="advSearchCommonSchema" />\r
<run controlFile="collectionobject/collectionobject-adv-search.xml" testGroup="advSearchExtensionSchema" />\r
<run controlFile="acquisitions/acquisitions.xml" testGroup="makeone" />\r
<run controlFile="acquisitions/acquisitions.xml" testGroup="testList" />\r
<run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
-<!--\r
-->\r
\r
<!-- No - this test is broken\r
<run controlFile="relation/relation.xml" testGroup="r2only" />\r
-->\r
\r
+<!-- \r
<run controlFile="person/person.xml" testGroup="postPerson" />\r
<run controlFile="person/person.xml" testGroup="updatePerson" />\r
+ --> \r
<run controlFile="person/person.xml" testGroup="PersonAddRelsDeleteRels" />\r
\r
+<!-- \r
<run controlFile="location/location-hierarchy.xml" testGroup="HierarchicLocation" />\r
<run controlFile="organization/organization-hierarchy.xml" testGroup="HierarchicOrganization" />\r
\r
<run controlFile="authrefs/authrefsSimple.xml" testGroup="AuthRefsSimple" />\r
<run controlFile="authrefs/authrefsComplex.xml" testGroup="AuthRefsComplex" />\r
<run controlFile="imports/imports.xml" testGroup="importsTestGroup" />\r
- \r
+ -->\r
+ \r
</xmlReplayMaster>\r
\r
import org.collectionspace.services.workflow.WorkflowCommon;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.UriBuilder;
import javax.ws.rs.core.UriInfo;
-import java.util.ArrayList;
import java.util.List;
-import org.collectionspace.services.client.*;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
/**
*
* @throws Exception the exception
*/
- protected DocumentHandler createItemDocumentHandler(
+ protected DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> createItemDocumentHandler(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
String inAuthority, String parentShortIdentifier)
throws Exception {
} else {
parentShortIdentifier = parentSpec.value;
String whereClause = buildWhereForAuthByName(parentSpec.value);
- ServiceContext ctx = createServiceContext(getServiceName(), queryParams);
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getServiceName(), queryParams);
parentcsid = getRepositoryClient(ctx).findDocCSID(null, ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
}
result.CSID = parentcsid;
return result;
}
- public String lookupItemCSID(String itemspecifier, String parentcsid, String method, String op, ServiceContext ctx)
+ public String lookupItemCSID(String itemspecifier, String parentcsid, String method, String op, ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)
throws DocumentException {
String itemcsid;
Specifier itemSpec = getSpecifier(itemspecifier, method, op);
}
String whereClause = buildWhereForAuthByName(item.getParentShortIdentifier());
// Ensure we have the right context.
- ServiceContext ctx = createServiceContext(item.inAuthority.resource);
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(item.inAuthority.resource);
// HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here!
RepositoryJavaClientImpl client = (RepositoryJavaClientImpl)getRepositoryClient(ctx);
try {
PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input);
- DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(resourceClass);
path.path("" + csid);
PoxPayloadOut result = null;
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
- DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
Specifier spec = getSpecifier(specifier, "getAuthority", "GET");
if (spec.form == SpecifierForm.CSID) {
try {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
- DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
DocumentFilter myFilter = handler.getDocumentFilter();
// Need to make the default sort order for authority items
// be on the displayName field
myFilter.setWhereClause(authorityCommonSchemaName + ":refName='" + nameQ + "'");
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
- return (AbstractCommonList) handler.getCommonPartList();
+ return handler.getCommonPartList();
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.GET_FAILED);
}
PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
Specifier spec = getSpecifier(specifier, "updateAuthority", "UPDATE");
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate);
- DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
String csid;
if (spec.form == SpecifierForm.CSID) {
csid = spec.value;
try {
ensureCSID(csid, ServiceMessages.DELETE_FAILED, "Authority.csid");
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
- DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).delete(ctx, csid, handler);
return Response.status(HttpResponseCodes.SC_OK).build();
} catch (Exception e) {
@PathParam("csid") String specifier, String xmlPayload) {
try {
PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
- ServiceContext ctx = createServiceContext(getItemServiceName(), input);
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), input);
ctx.setResourceMap(resourceMap);
ctx.setUriInfo(ui); //Laramie
// Note: must have the parentShortId, to do the create.
CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(specifier, "createAuthorityItem", "CREATE_ITEM", null);
- DocumentHandler handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(resourceClass);
path.path(parent.CSID + "/items/" + itemcsid);
// Create a service context and document handler for the parent resource.
ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(getItemServiceName());
- DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> parentDocHandler = this.createDocumentHandler(parentCtx);
ctx.setProperty(WorkflowClient.PARENT_DOCHANDLER, parentDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method
// When looking for the document, we need to use the parent's workspace name -not the "workflow" workspace name
String parentcsid = lookupParentCSID(parentspecifier, "getAuthorityItem(parent)", "GET_ITEM", queryParams);
RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
- ctx = (RemoteServiceContext) createServiceContext(getItemServiceName(), queryParams);
+ ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(getItemServiceName(), queryParams);
ctx.setJaxRsContext(jaxRsContext);
ctx.setUriInfo(ui); //ARG! must pass this or subsequent calls will not have a ui.
// We omit the parentShortId, only needed when doing a create...
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, null);
Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItem(item)", "GET_ITEM");
if (itemSpec.form == SpecifierForm.CSID) {
// For the wildcard case, parentcsid is null, but docHandler will deal with this.
// We omit the parentShortId, only needed when doing a create...
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, null);
DocumentFilter myFilter = handler.getDocumentFilter();
// Need to make the default sort order for authority items
+ " and ORDER BY clause: " + myFilter.getOrderByClause());
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
- return (AbstractCommonList) handler.getCommonPartList();
+ return handler.getCommonPartList();
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.LIST_FAILED);
}
ctx = createServiceContext(getItemServiceName(), queryParams);
// We omit the parentShortId, only needed when doing a create...
- DocumentModelHandler handler =
- (DocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null);
+ DocumentModelHandler<?, AbstractCommonList> handler =
+ (DocumentModelHandler<?, AbstractCommonList>)createItemDocumentHandler(ctx, parentcsid, null);
String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS", ctx);
String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx);
// We omit the parentShortId, only needed when doing a create...
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, null);
ctx.setUriInfo(ui);
getRepositoryClient(ctx).update(ctx, itemcsid, handler);
result = ctx.getOutput();
// }
// try {
// Note that we have to create the service context for the Items, not the main service
- ServiceContext ctx = createServiceContext(getItemServiceName());
- DocumentHandler handler = createDocumentHandler(ctx);
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName());
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).delete(ctx, itemcsid, handler);
return Response.status(HttpResponseCodes.SC_OK).build();
} catch (Exception e) {
// All items in dive can look at their child uri's to get uri. So we calculate the very first one. We could also do a GET and look at the common part uri field, but why...?
String calledUri = ui.getPath();
String uri = "/" + calledUri.substring(0, (calledUri.length() - ("/" + hierarchy).length()));
- ServiceContext ctx = createServiceContext(getItemServiceName());
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName());
ctx.setUriInfo(ui);
String direction = ui.getQueryParameters().getFirst(Hierarchy.directionQP);
if (Tools.notBlank(direction) && Hierarchy.direction_parents.equals(direction)) {
package org.collectionspace.services.common.vocabulary;
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.ServiceContext;
* @param uri informational, optional - if not known, pass an empty String.
* @return String of XML document, including xml processing instruction, root node is "<hierarchy>".
*/
- public static String dive(ServiceContext ctx, String itemcsid, String uri) {
+ public static String dive(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String itemcsid, String uri) {
String result = dive(ctx, itemcsid, uri, true);
result = "<?xml version='1.0' ?><hierarchy>"+result+"</hierarchy>";
try {
result = XmlTools.prettyPrint(result);
} catch (Exception e){
+ // Do nothing
}
return result;
}
- private static String dive(ServiceContext ctx, String itemcsid, String uri, boolean lookupFirstName) {
- MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters();
+ private static String dive(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String itemcsid, String uri, boolean lookupFirstName) {
+ MultivaluedMap<String, String> queryParams = ctx.getUriInfo().getQueryParameters();
//Run getList() once as sent to get childListOuter:
queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value());
queryParams.putSingle(IRelationsManager.SUBJECT_QP, null);
queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null);
queryParams.putSingle(IRelationsManager.OBJECT_QP, itemcsid);
queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null);
- RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context.
+
+ RelationResource relationResource = new RelationResource();
+ RelationsCommonList childListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context.
List<RelationsCommonList.RelationListItem> childList = childListOuter.getRelationListItem();
StringBuffer sb = new StringBuffer();
} else {
sb.append("<uri>" + uri + "</uri>\r\n");
}
+
sb.append("<csid>" + itemcsid + "</csid>\r\n");
sb.append("<children>\r\n");
+
for (RelationsCommonList.RelationListItem item : childList) {
RelationsDocListItem parent = item.getObject();
RelationsDocListItem child = item.getSubject();
return sb.toString();
}
- public static String surface(ServiceContext ctx, String itemcsid, String uri) {
+ public static String surface(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String itemcsid, String uri) {
String result = surface(ctx, itemcsid, uri, true).resultBuffer.toString();
result = "<?xml version='1.0' ?><hierarchy direction='"+direction_parents+"'>"+result+"</hierarchy>";
try {
result = XmlTools.prettyPrint(result);
} catch (Exception e){
+ // Do nothing
}
return result;
}
+
private static class SurfaceResultStruct {
public StringBuffer resultBuffer;
public boolean noParents = false;
}
- private static SurfaceResultStruct surface(ServiceContext ctx, String itemcsid, String uri, boolean first) {
- MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters();
+
+ private static SurfaceResultStruct surface(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String itemcsid, String uri, boolean first) {
+ MultivaluedMap<String, String> queryParams = ctx.getUriInfo().getQueryParameters();
//Run getList() once as sent to get parentListOuter:
queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value());
queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemcsid);
queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null);
queryParams.putSingle(IRelationsManager.OBJECT_QP, null);
queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null);
- RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context.
+
+ RelationResource relationResource = new RelationResource();
+ RelationsCommonList parentListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context.
List<RelationsCommonList.RelationListItem> parentList = parentListOuter.getRelationListItem();
StringBuffer sbOuter = new StringBuffer();
if (parentList.size()==0){
resultStruct.noParents = true;
}
+
for (RelationsCommonList.RelationListItem item : parentList) {
resultStruct.noParents = false;
RelationsDocListItem parent = item.getObject();
return resultStruct;
}
-
}
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
try {
- repoSession = nuxeoRepoClient.getRepositorySession();
+ repoSession = nuxeoRepoClient.getRepositorySession(ctx);
DocumentWrapper<DocumentModel> wrapDoc = nuxeoRepoClient.getDocFromCsid(ctx, repoSession, authCSID);
DocumentModel docModel = wrapDoc.getWrappedObject();
shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
} finally {
if (repoSession != null) {
- nuxeoRepoClient.releaseRepositorySession(repoSession);
+ nuxeoRepoClient.releaseRepositorySession(ctx, repoSession);
}
}
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.RelationClient;
+
import org.collectionspace.services.common.ResourceBase;
import org.collectionspace.services.common.api.CommonAPI;
import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
+
import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.config.service.ObjectPartType;
-import org.collectionspace.services.jaxb.AbstractCommonList;
-import org.collectionspace.services.nuxeo.client.java.CommonList; //FIXME: REM - 5/15/2012 - CommonList should be moved out of this package and into a more "common" package
+
import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+
import org.collectionspace.services.relation.RelationResource;
import org.collectionspace.services.relation.RelationsCommon;
import org.collectionspace.services.relation.RelationsCommonList;
import org.collectionspace.services.relation.RelationsDocListItem;
import org.collectionspace.services.relation.RelationshipType;
+
import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
-import org.nuxeo.ecm.core.api.DocumentModelList;
-import org.nuxeo.ecm.core.api.model.Property;
import org.nuxeo.ecm.core.api.model.PropertyException;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.ArrayList;
RepositoryInstance repoSession = null;
boolean releaseRepoSession = false;
- try {
+ try {
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
repoSession = this.getRepositorySession();
if (repoSession == null) {
- repoSession = repoClient.getRepositorySession();
+ repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
DocumentFilter myFilter = getDocumentFilter();
}
throw new DocumentException(e);
} finally {
+ // If we got/aquired a new seesion then we're responsible for releasing it.
if (releaseRepoSession && repoSession != null) {
- repoClient.releaseRepositorySession(repoSession);
+ repoClient.releaseRepositorySession(ctx, repoSession);
}
}
} catch (Exception e) {
logger.debug("Caught exception ", e);
}
throw new DocumentException(e);
- }
+ }
+
return authRefDocList;
}
DocumentModel docModel = wrapDoc.getWrappedObject();
String itemRefName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
- ServiceContext ctx = getServiceContext();
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
//Do magic replacement of ${itemCSID} and fix URI's.
fixupInboundListItems(ctx, inboundList, docModel, itemCSID);
String HAS_BROADER = RelationshipType.HAS_BROADER.value();
UriInfo uriInfo = ctx.getUriInfo();
- MultivaluedMap queryParams = uriInfo.getQueryParameters();
+ MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
if (fUpdate) {
//Run getList() once as sent to get childListOuter:
queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null);
queryParams.putSingle(IRelationsManager.OBJECT_QP, itemCSID);
queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null);
- RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context.
+
+ RelationResource relationResource = new RelationResource();
+ RelationsCommonList childListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context.
//Now run getList() again, leaving predicate, swapping subject and object, to get parentListOuter.
queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate);
queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemCSID);
queryParams.putSingle(IRelationsManager.OBJECT_QP, null);
- RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo());
+ RelationsCommonList parentListOuter = relationResource.getList(ctx);
childList = childListOuter.getRelationListItem();
}
}
-
for (RelationsCommonList.RelationListItem inboundItem : inboundList) {
// Note that the relations may specify the other (non-item) bit with a refName, not a CSID,
// and so the CSID for those may be null
return relationsCommonListBody;
}
- private void ensureChildHasNoOtherParents(ServiceContext ctx, MultivaluedMap queryParams, String childCSID) {
+ private void ensureChildHasNoOtherParents(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ MultivaluedMap<String, String> queryParams, String childCSID) {
logger.trace("ensureChildHasNoOtherParents for: " + childCSID );
queryParams.putSingle(IRelationsManager.SUBJECT_QP, childCSID);
queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value());
queryParams.putSingle(IRelationsManager.OBJECT_QP, null); //null means ANY
- RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo());
+
+ RelationResource relationResource = new RelationResource();
+ RelationsCommonList parentListOuter = relationResource.getList(ctx);
List<RelationsCommonList.RelationListItem> parentList = parentListOuter.getRelationListItem();
//logger.warn("ensureChildHasNoOtherParents preparing to delete relations on "+childCSID+"\'s parent list: \r\n"+dumpList(parentList, "duplicate parent list"));
deleteRelations(parentList, ctx, "parentList-delete");
return sb.toString();
}
private final static String CR = "\r\n";
- private final static String T = " ";
private String dumpList(List<RelationsCommonList.RelationListItem> list, String label) {
StringBuilder sb = new StringBuilder();
}
// this method calls the RelationResource to have it create the relations and persist them.
- private void createRelations(List<RelationsCommonList.RelationListItem> inboundList, ServiceContext ctx) throws Exception {
+ private void createRelations(List<RelationsCommonList.RelationListItem> inboundList,
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) throws Exception {
for (RelationsCommonList.RelationListItem item : inboundList) {
RelationsCommon rc = new RelationsCommon();
//rc.setCsid(item.getCsid());
PayloadOutputPart outputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMONPART_NAME, rc);
payloadOut.addPart(outputPart);
RelationResource relationResource = new RelationResource();
- Object res = relationResource.create(ctx.getResourceMap(),
+ Response res = relationResource.create(ctx, ctx.getResourceMap(),
ctx.getUriInfo(), payloadOut.toXML()); //NOTE ui recycled from above to pass in unknown query params.
}
}
- private void deleteRelations(List<RelationsCommonList.RelationListItem> list, ServiceContext ctx, String listName) {
+ private void deleteRelations(List<RelationsCommonList.RelationListItem> list,
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ String listName) {
try {
for (RelationsCommonList.RelationListItem item : list) {
RelationResource relationResource = new RelationResource();
itemToString(sb, "==== TO DELETE: ", item);
logger.trace(sb.toString());
}
- Object res = relationResource.delete(item.getCsid());
+ Response res = relationResource.deleteWithParentCtx(ctx, item.getCsid());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Status of authority item deleteRelations method call was: " + res.getStatus());
+ }
}
} catch (Throwable t) {
String msg = "Unable to deleteRelations: " + Tools.errorToString(t, true);
//================= TODO: move this to common, refactoring this and CollectionObjectResource.java
public RelationsCommonList getRelations(String subjectCSID, String objectCSID, String predicate) throws Exception {
- ServiceContext ctx = getServiceContext();
- MultivaluedMap queryParams = ctx.getQueryParams();
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
+ MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate);
queryParams.putSingle(IRelationsManager.SUBJECT_QP, subjectCSID);
queryParams.putSingle(IRelationsManager.OBJECT_QP, objectCSID);
RelationResource relationResource = new RelationResource(); //is this still acting like a singleton as it should be?
- RelationsCommonList relationsCommonList = relationResource.getList(ctx.getUriInfo());
+ RelationsCommonList relationsCommonList = relationResource.getList(ctx);
return relationsCommonList;
}
//============================= END TODO refactor ==========================
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
repoSession = this.getRepositorySession();
if (repoSession == null) {
- repoSession = repoClient.getRepositorySession();
+ repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
throw new DocumentException(e);
} finally {
if (releaseRepoSession && repoSession != null) {
- repoClient.releaseRepositorySession(repoSession);
+ repoClient.releaseRepositorySession(ctx, repoSession);
}
}
className = className.trim();
import java.util.Iterator;\r
import java.util.List;\r
\r
-import javax.ws.rs.Consumes;\r
import javax.ws.rs.GET;\r
import javax.ws.rs.PUT;\r
import javax.ws.rs.Path;\r
import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.WebApplicationException;\r
-import javax.ws.rs.core.Response;\r
\r
import org.collectionspace.services.client.PayloadOutputPart;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
import org.collectionspace.services.client.workflow.WorkflowClient;\r
-import org.collectionspace.services.common.api.Tools;\r
import org.collectionspace.services.common.context.MultipartServiceContext;\r
import org.collectionspace.services.common.context.MultipartServiceContextFactory;\r
import org.collectionspace.services.common.context.ServiceContext;\r
import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;\r
import org.collectionspace.services.lifecycle.Lifecycle;\r
import org.collectionspace.services.lifecycle.TransitionDef;\r
-import org.collectionspace.services.lifecycle.TransitionDefList;\r
import org.collectionspace.services.workflow.WorkflowCommon;\r
import org.dom4j.DocumentException;\r
-import org.jboss.resteasy.client.ClientResponse;\r
\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
import org.jboss.resteasy.util.HttpResponseCodes;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
+import org.nuxeo.ecm.core.api.DocumentModelList;\r
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
\r
import javax.ws.rs.*;\r
/**\r
* $LastChangedRevision: $\r
* $LastChangedDate: $\r
- * Author: laramie\r
+ * Author: Laramie Crocker\r
*/\r
public abstract class ResourceBase\r
extends AbstractMultiPartCollectionSpaceResourceImpl {\r
//======================= CREATE ====================================================\r
\r
@POST\r
- public Response create(@Context ResourceMap resourceMap, @Context UriInfo ui,\r
+ public Response create(@Context ResourceMap resourceMap,\r
+ @Context UriInfo ui,\r
String xmlPayload) {\r
+ return this.create(null, resourceMap, ui, xmlPayload);\r
+ }\r
+ \r
+ public Response create(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx,\r
+ @Context ResourceMap resourceMap,\r
+ @Context UriInfo ui,\r
+ String xmlPayload) {\r
+ Response result = null;\r
+ \r
try {\r
PoxPayloadIn input = new PoxPayloadIn(xmlPayload);\r
- //System.out.println("\r\n\r\n==============================\r\nxmlPayload:\r\n"+xmlPayload);\r
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input);\r
ctx.setResourceMap(resourceMap);\r
- return create(input, ctx);\r
+ if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {\r
+ ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists\r
+ } \r
+ result = create(input, ctx);\r
} catch (Exception e) {\r
throw bigReThrow(e, ServiceMessages.CREATE_FAILED);\r
}\r
- }\r
-\r
+ \r
+ return result;\r
+ } \r
+ \r
protected Response create(PoxPayloadIn input, ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {\r
try {\r
- DocumentHandler handler = createDocumentHandler(ctx);\r
+ DocumentHandler<PoxPayloadIn, PoxPayloadOut, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);\r
UriBuilder path = UriBuilder.fromResource(this.getClass());\r
return create(input, ctx, handler, path); //==> CALL implementation method, which subclasses may override.\r
} catch (Exception e) {\r
/** Subclasses may override this overload, which gets called from @see #create(MultipartInput) */\r
protected Response create(PoxPayloadIn input,\r
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
- DocumentHandler handler,\r
+ DocumentHandler<PoxPayloadIn, PoxPayloadOut, DocumentModel, DocumentModelList> handler,\r
UriBuilder path)\r
throws Exception {\r
String csid = getRepositoryClient(ctx).create(ctx, handler);\r
ensureCSID(csid, DELETE);\r
try {\r
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();\r
- return delete(csid, ctx); //==> CALL implementation method, which subclasses may override.\r
+ return delete(ctx, csid); //==> CALL implementation method, which subclasses may override.\r
} catch (Exception e) {\r
throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid);\r
}\r
\r
/** subclasses may override this method, which is called from #delete(String)\r
* which handles setup of ServiceContext, and does Exception handling. */\r
- protected Response delete(String csid, ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)\r
+ protected Response delete(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String csid)\r
throws Exception {\r
- DocumentHandler handler = createDocumentHandler(ctx);\r
+ DocumentHandler<PoxPayloadIn, PoxPayloadOut, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);\r
getRepositoryClient(ctx).delete(ctx, csid, handler);\r
return Response.status(HttpResponseCodes.SC_OK).build();\r
}\r
+ \r
+ public Response deleteWithParentCtx(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx,\r
+ String csid)\r
+ throws Exception {\r
+ ensureCSID(csid, DELETE);\r
+ try {\r
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();\r
+ if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {\r
+ ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // reuse the repo session if one exists\r
+ }\r
+ return delete(ctx, csid); //==> CALL implementation method, which subclasses may override.\r
+ } catch (Exception e) {\r
+ throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid);\r
+ }\r
+ } \r
\r
//======================= GET ====================================================\r
@GET\r
}\r
return list;\r
}\r
-\r
+ \r
protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {\r
try {\r
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);\r
private DocumentHandler docHandler = null;
/** security context */
private SecurityContext securityContext;
-
+ /** The sessions JAX-RS URI information */
private UriInfo uriInfo;
+ /** The current repository session */
+ private Object currentRepositorySession;
+ /** A reference count for the current repository session */
+ private int currentRepoSesssionRefCount = 0;
/**
* Instantiates a new abstract service context impl.
this.uriInfo = ui;
}
- @Override
- public UriInfo getUriInfo(){
- return this.uriInfo;
- }
+ @Override
+ public UriInfo getUriInfo() {
+ return this.uriInfo;
+ }
+
+ /*
+ * We expect the 'currentRepositorySession' member to be set only once per instance. Also, we expect only one open repository session
+ * per HTTP request. We'll log an error if we see more than one attempt to set a service context's current repo session.
+ * (non-Javadoc)
+ * @see org.collectionspace.services.common.context.ServiceContext#setCurrentRepositorySession(java.lang.Object)
+ */
+ @Override
+ public void setCurrentRepositorySession(Object repoSession) throws Exception {
+ if (repoSession == null) {
+ String errMsg = "Setting a service context's repository session to null is not allowed.";
+ logger.error(errMsg);
+ throw new Exception(errMsg);
+ } else if (currentRepositorySession != null && currentRepositorySession != repoSession) {
+ String errMsg = "The current service context's repository session was replaced. This may cause unexpected behavior and/or data loss.";
+ logger.error(errMsg);
+ throw new Exception(errMsg);
+ }
+
+ currentRepositorySession = repoSession;
+ this.currentRepoSesssionRefCount++;
+ }
+
+ @Override
+ public void clearCurrentRepositorySession() {
+ if (this.currentRepoSesssionRefCount > 0) {
+ currentRepoSesssionRefCount--;
+ }
+
+ if (currentRepoSesssionRefCount == 0) {
+ this.currentRepositorySession = null;
+ }
+ }
+
+ @Override
+ public Object getCurrentRepositorySession() {
+ // TODO Auto-generated method stub
+ return currentRepositorySession;
+ }
}
@Override
public ServiceContext getLocalContext(String localContextClassName) throws Exception {
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
- Class ctxClass = cloader.loadClass(localContextClassName);
+ Class<?> ctxClass = cloader.loadClass(localContextClassName);
if (!ServiceContext.class.isAssignableFrom(ctxClass)) {
throw new IllegalArgumentException("getLocalContext requires "
+ " implementation of " + ServiceContext.class.getName());
Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
return ctx;
- }
+ }
}
/** Used to qualify document types **/
public static final String TENANT_SUFFIX = "Tenant";
+ /*
+ * Sets the current/open repository session
+ */
+ public void setCurrentRepositorySession(Object repoSession) throws Exception;
+
+ /*
+ * Decrements the context's repo session ref count and nulls it if the count becomes 0.
+ */
+ public void clearCurrentRepositorySession();
+
+ /*
+ * If a current repository session exists, returns it.
+ */
+ public Object getCurrentRepositorySession();
+
/**
* getSecurityContext is contains security info. for the service layer
*/
.getDigestAlgorithm(); // Need some way on initializing the\r
// FileManager with a call.\r
\r
- logger.debug("Start --> Calling Nuxeo to create an image blob.");\r
+ logger.debug("Start --> Calling Nuxeo to create an image blob."); // See Nuxeo's DefaultPictureAdapter class for details\r
DocumentModel documentModel = getFileManagerService()\r
.createDocumentFromBlob(nuxeoSession, fileBlob,\r
blobLocation.getPathAsString(), true,\r
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
RepositoryInstance repoSession = this.getRepositorySession();
if (repoSession == null) {
- repoSession = repoClient.getRepositorySession();
+ repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
}
} finally {
if (releaseRepoSession == true) {
- repoClient.releaseRepositorySession(repoSession);
+ repoClient.releaseRepositorySession(ctx, repoSession);
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.CREATE);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);
DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);
String wspacePath = wspaceDoc.getPathAsString();
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.GET);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
DocumentModel docModel = null;
try {
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
try {
handler.prepare(Action.GET);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentModelList docList = null;
// force limit to 1, and ignore totalSize
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
try {
// Open a new repository session
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
wrapDoc = getDoc(repoSession, ctx, csid);
} catch (IllegalArgumentException iae) {
throw iae;
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
DocumentWrapper<DocumentModel> wrapDoc = null;
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
wrapDoc = findDoc(repoSession, ctx, whereClause);
} catch (Exception e) {
throw new DocumentException("Unable to create a Nuxeo repository session.", e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
String csid = null;
boolean releaseSession = false;
try {
- if(repoSession== null) {
- repoSession = this.getRepositorySession();
+ if (repoSession == null) {
+ repoSession = this.getRepositorySession(ctx);
releaseSession = true;
}
DocumentWrapper<DocumentModel> wrapDoc = findDoc(repoSession, ctx, whereClause);
throw new DocumentException(e);
} finally {
if(releaseSession && (repoSession != null)) {
- this.releaseRepositorySession(repoSession);
+ this.releaseRepositorySession(ctx, repoSession);
}
}
return csid;
DocumentWrapper<DocumentModelList> wrapDoc = null;
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause,
pageSize, pageNum, computeTotal);
} catch (IllegalArgumentException iae) {
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.GET_ALL);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentModelList docModelList = new DocumentModelListImpl();
//FIXME: Should be using NuxeoUtils.createPathRef for security reasons
for (String csid : csidList) {
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.GET_ALL);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentRef wsDocRef = new IdRef(nuxeoWspaceId);
DocumentModelList docList = repoSession.getChildren(wsDocRef);
//set reposession to handle the document
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
DocumentWrapper<DocumentModel> result = null;
RepositoryInstance repoSession = null;
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
result = getDocFromCsid(ctx, repoSession, csid);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.GET_ALL);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx); //Need a refcount here for the repository session?
DocumentModelList docList = null;
String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.UPDATE);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentRef docRef = NuxeoUtils.createPathRef(ctx, csid);
DocumentModel doc = null;
try {
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
boolean fSaveSession)
throws ClientException, DocumentException {
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentModel[] docModelArray = new DocumentModel[docList.size()];
repoSession.saveDocuments(docList.toArray(docModelArray));
if (fSaveSession) {
RepositoryInstance repoSession = null;
try {
handler.prepare(Action.DELETE);
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(ctx);
DocumentWrapper<DocumentModel> wrapDoc = null;
try {
DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(ctx, repoSession);
}
}
}
//
// First create the top-level domain directory
//
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(null);
DocumentRef parentDocRef = new PathRef("/");
DocumentModel parentDoc = repoSession.getDocument(parentDocRef);
DocumentModel domainDoc = repoSession.createDocumentModel(parentDoc.getPathAsString(),
throw e;
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(null, repoSession);
}
}
if (domainName != null && !domainName.isEmpty()) {
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(null);
DocumentRef docRef = new PathRef(
"/" + domainName);
DocumentModel domain = repoSession.getDocument(docRef);
return null;
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(null, repoSession);
}
}
}
RepositoryInstance repoSession = null;
String workspaceId = null;
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(null);
DocumentModel parentDoc = getWorkspacesRoot(repoSession, domainName);
DocumentModel doc = repoSession.createDocumentModel(parentDoc.getPathAsString(),
workspaceName, NuxeoUtils.WORKSPACE_DOCUMENT_TYPE);
throw e;
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(null, repoSession);
}
}
return workspaceId;
RepositoryInstance repoSession = null;
try {
- repoSession = getRepositorySession();
+ repoSession = getRepositorySession(null);
DocumentRef docRef = new PathRef(
"/" + tenantDomain
+ "/" + NuxeoUtils.Workspaces
throw new DocumentException(e);
} finally {
if (repoSession != null) {
- releaseRepositorySession(repoSession);
+ releaseRepositorySession(null, repoSession);
}
}
* @return the repository session
* @throws Exception the exception
*/
- public RepositoryInstance getRepositorySession() throws Exception {
- // FIXME: is it possible to reuse repository session?
- // Authentication failures happen while trying to reuse the session
+ public RepositoryInstance getRepositorySession(ServiceContext ctx) throws Exception {
+ RepositoryInstance repoSession = null;
+
Profiler profiler = new Profiler("getRepositorySession():", 2);
profiler.start();
-
- NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();
- RepositoryInstance repoSession = client.openRepository();
+
+ if (ctx != null) {
+ repoSession = (RepositoryInstance)ctx.getCurrentRepositorySession();
+ if (logger.isDebugEnabled() == true) {
+ if (repoSession != null) {
+ logger.warn("Reusing the current context's repository session.");
+ }
+ }
+ }
+
+ // If we couldn't find a repoSession from the service context then we need to create a new one
+ if (repoSession == null) {
+ NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();
+ repoSession = client.openRepository();
+ }
+
if (logger.isTraceEnabled()) {
logger.trace("Testing call to getRepository() repository root: " + repoSession.getRootDocument());
}
profiler.stop();
+
+ if (ctx != null) {
+ ctx.setCurrentRepositorySession(repoSession); // For reusing, save the repository session in the current service context
+ }
+
return repoSession;
}
*
* @param repoSession the repo session
*/
- public void releaseRepositorySession(RepositoryInstance repoSession) {
+ public void releaseRepositorySession(ServiceContext ctx, RepositoryInstance repoSession) {
try {
NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();
// release session
- client.releaseRepository(repoSession);
+ if (ctx != null) {
+ ctx.clearCurrentRepositorySession(); //clear the current context of the now closed repo session
+ if (ctx.getCurrentRepositorySession() == null) {
+ client.releaseRepository(repoSession); //release the repo session if the service context's ref count is zeo.
+ }
+ } else {
+ client.releaseRepository(repoSession); //repo session was acquired without a service context
+ }
} catch (Exception e) {
logger.error("Could not close the repository session", e);
// no need to throw this service specific exception
//
// Now that we've handled the related Blob record, delete the Media record
//
- return super.delete(csid, ctx);
+ return super.delete(ctx, csid);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid);
}
public class RelationResource extends ResourceBase {
public final static String serviceName = "relations";
final Logger logger = LoggerFactory.getLogger(RelationResource.class);
+
@Override
protected String getVersionString() {
final String lastChangeRevision = "$LastChangedRevision$";
public Class<RelationsCommon> getCommonPartClass() {
return RelationsCommon.class;
}
-
+
@Override
@GET
@Produces("application/xml")
- public RelationsCommonList getList(@Context UriInfo ui) {
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ public RelationsCommonList getList(@Context UriInfo uriInfo) {
+ return this.getList(null, uriInfo);
+ }
+
+ public RelationsCommonList getList(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx) {
+ return this.getList(parentCtx, parentCtx.getUriInfo());
+ }
+
+ private RelationsCommonList getList(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
+ if (parentCtx != null) {
+ uriInfo = parentCtx.getUriInfo(); //Override the input param and use the parent context's UriInfo
+ }
+ MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String subjectCsid = queryParams.getFirst(IRelationsManager.SUBJECT_QP);
String subjectType = queryParams.getFirst(IRelationsManager.SUBJECT_TYPE_QP);
String objectCsid = queryParams.getFirst(IRelationsManager.OBJECT_QP);
String objectType = queryParams.getFirst(IRelationsManager.OBJECT_TYPE_QP);
- return this.getRelationList(queryParams, subjectCsid, subjectType, predicate, objectCsid, objectType);
+ return this.getRelationList(parentCtx, queryParams, subjectCsid, subjectType, predicate, objectCsid, objectType);
}
- private RelationsCommonList getRelationList(MultivaluedMap<String, String> queryParams, String subjectCsid, String subjectType,
- String predicate, String objectCsid, String objectType) throws WebApplicationException {
+ private RelationsCommonList getRelationList(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx,
+ MultivaluedMap<String, String> queryParams,
+ String subjectCsid, String subjectType,
+ String predicate,
+ String objectCsid,
+ String objectType) throws WebApplicationException {
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
+ if (parentCtx != null) { // If the parent context has an open repository session then use it
+ ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession());
+ }
DocumentHandler handler = createDocumentHandler(ctx);
String relationClause = RelationsUtils.buildWhereClause(subjectCsid, subjectType, predicate, objectCsid, objectType);
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
repoSession = this.getRepositorySession();
if (repoSession == null) {
- repoSession = repoClient.getRepositorySession();
+ repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
throw new DocumentException(e);
} finally {
if (releaseRepoSession && repoSession != null) {
- repoClient.releaseRepositorySession(repoSession);
+ repoClient.releaseRepositorySession(ctx, repoSession);
}
}
return buildReportResponse(csid, params, reportFileName);
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
repoSession = this.getRepositorySession();
if (repoSession == null) {
- repoSession = repoClient.getRepositorySession();
+ repoSession = repoClient.getRepositorySession(ctx);
releaseRepoSession = true;
}
DocumentFilter myFilter = getDocumentFilter();
throw new DocumentException(e);
} finally {
if (releaseRepoSession && repoSession != null) {
- repoClient.releaseRepositorySession(repoSession);
+ repoClient.releaseRepositorySession(ctx, repoSession);
}
}
} catch (Exception e) {