private PoxPayloadOut synchronizeItem(
ServiceContext ctx,
String parentIdentifier,
- String itemIdentifier) throws Exception {
+ String itemIdentifier,
+ boolean syncHierarchicalRelationships) throws Exception {
PoxPayloadOut result = null;
AuthorityItemSpecifier specifier;
boolean neededSync = false;
AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
handler.setIsProposed(AuthorityServiceUtils.NOT_PROPOSED); // In case it was formally locally proposed, clear the proposed flag
handler.setIsSASItem(AuthorityServiceUtils.SAS_ITEM); // Since we're sync'ing, this is now a SAS controlled item
+ handler.setShouldSyncHierarchicalRelationships(syncHierarchicalRelationships);
// Create an authority item specifier
Specifier parentSpecifier = Specifier.getSpecifier(parent.CSID, "getAuthority", "GET");
Specifier itemSpecifier = Specifier.getSpecifier(itemIdentifier, "getAuthorityItem", "GET");
public PoxPayloadOut synchronizeItemWithExistingContext(
ServiceContext existingCtx,
String parentIdentifier,
- String itemIdentifier
+ String itemIdentifier,
+ boolean syncHierarchicalRelationships
) throws Exception {
PoxPayloadOut result = null;
if (existingCtx.getCurrentRepositorySession() != null) {
ctx.setCurrentRepositorySession(existingCtx.getCurrentRepositorySession());
}
- result = synchronizeItem(ctx, parentIdentifier, itemIdentifier);
+ result = synchronizeItem(ctx, parentIdentifier, itemIdentifier, syncHierarchicalRelationships);
return result;
}
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), null, resourceMap, uriInfo);
- payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier);
+ payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier, true);
if (payloadOut != null) {
neededSync = true;
}
//
// Makes a call to the SAS server for a authority item payload
//
- static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
+ static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType, boolean syncHierarchicalRelationships) throws Exception {
PoxPayloadIn result = null;
ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
AuthorityClient client = (AuthorityClient) parentCtx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
- Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
+ Response res = client.readNamedItemInNamedAuthority(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue(),
+ AuthorityClient.INCLUDE_DELETED_ITEMS, syncHierarchicalRelationships);
+
try {
int statusCode = res.getStatus();
//
//
try {
- PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier);
+ PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier, false);
if (theUpdate != null) {
result = 0; // means we needed to sync this item with SAS
logger.debug(String.format("Sync'd authority item parent='%s' id='%s with SAS. Updated payload is: \n%s",
//
// WARNING: THIS CODE IS NOT IMPLEMENTED YET
//
- return result;
+ if (result == -1) return result;
//
// Using the item refname (with no local CSID), create specifiers that we'll use to find the local versions
//
- /*
+
AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(itemRefName);
String parentIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.inAuthority.name);
String itemIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.name);
//
//
try {
- PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier);
+ PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier, true);
if (theUpdate != null) {
result = 0; // means we needed to sync this item with SAS
logger.debug(String.format("Sync'd authority item parent='%s' id='%s with SAS. Updated payload is: \n%s",
}
return result; // -1 = no sync needed/possible, 0 = sync'd, 1 = created new item
- */
+
}
protected String authorityItemCommonSchemaName;
private String authorityItemTermGroupXPathBase;
+ private boolean syncHierarchicalRelationships = false;
private boolean isProposed = false; // used by local authority to propose a new shared item. Allows local deployments to use new terms until they become official
private boolean isSAS = false; // used to indicate if the authority item originated as a SAS item
private boolean shouldUpdateRevNumber = true; // by default we should update the revision number -not true on synchronization with SAS
this.shouldUpdateRevNumber = flag;
}
+ //
+ // Getter and Setter for deciding if we need to synch hierarchical relationships
+ //
+ public boolean getShouldSyncHierarchicalRelationships() {
+ return this.syncHierarchicalRelationships;
+ }
+
+ public void setShouldSyncHierarchicalRelationships(boolean flag) {
+ this.syncHierarchicalRelationships = flag;
+ }
+
@Override
public void prepareSync() throws Exception {
this.setShouldUpdateRevNumber(AuthorityServiceUtils.DONT_UPDATE_REV); // Never update rev nums on sync operations
String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
String localParentCsid = authorityDocModel.getName();
//
- // Using the short IDs of the local authority and item, create URN specifiers to retrieve the SAS authority item
+ // Using the short IDs of the local authority and item, create URN specifiers and retrieve the SAS authority item
//
AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(SpecifierForm.URN_NAME, authorityShortId, itemShortId);
// Get the shared authority server's copy
public static final String TERM_DISPLAY_NAME = "termDisplayName";
public static final String VOCAB_DISPLAY_NAME = "displayName";
public static final String REF_NAME = "refName";
+
+ public static final Boolean INCLUDE_DELETED_ITEMS = true;
+ public static final Boolean INCLUDE_RELATIONS = true;
/*
* Basic CRUD operations
*/
public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId);
- public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted);
+ /**
+ * Read a named item in a named authority.
+ *
+ * @param authShortId
+ * @param itemShortId
+ * @param includeDeleted
+ * @param includeRelations
+ * @return
+ */
+ public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted, Boolean includeRelations);
/**
* Read item list, filtering by partial term match, or keywords. Only one of
implements AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P> {
private static final String INCLUDE_DELETE_TRUE = Boolean.TRUE.toString();
+ private static final String INCLUDE_RELATIONS_TRUE = Boolean.TRUE.toString();
+ private static final String INCLUDE_RELATIONS_FALSE = Boolean.FALSE.toString();
/*
* Basic CRUD proxied methods
*/
@Override
public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
- return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, INCLUDE_DELETE_TRUE);
+ return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, INCLUDE_DELETE_TRUE, INCLUDE_RELATIONS_FALSE);
}
@Override
- public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted) {
- return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, includeDeleted.toString());
+ public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted, Boolean includeRelations) {
+ return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, includeDeleted.toString(), includeRelations.toString());
}
/**
import javax.ws.rs.core.Response;
import org.collectionspace.services.client.workflow.WorkflowClient;
+import org.collectionspace.services.common.api.CommonAPI;
/*
* ILT = Item list type
@Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})")
Response readNamedItemInNamedAuthority(@PathParam("specifier") String specifier,
@PathParam("itemspecifier") String itemspecifier,
- @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState);
+ @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState,
+ @QueryParam(CommonAPI.showRelations_QP) String showRelations);
/*
* Item subresource List methods
public static String getVersionString(){
return COMMON_API;
}
- public static String AuthorityItemCSID_REPLACE="${itemCSID}";
+ public static final String AuthorityItemCSID_REPLACE="${itemCSID}";
- public static String showRelations_QP = "showRelations";
- public static String showSiblings_QP = "showSiblings";
- public static String showAllRelations_QP = "showAllRelations";
+ public static final String showRelations_QP = "showRelations";
+ public static final String showSiblings_QP = "showSiblings";
+ public static final String showAllRelations_QP = "showAllRelations";
public static final String GENERATE_BUNDLES = "core";
public static final String GENERATE_BINDINGS = "delta";
String objectType) throws CSWebApplicationException {
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
- if (parentCtx != null) { // If the parent context has an open repository session then use it
+ if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { // If the parent context has a non-null and open repository session then use it
ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession());
}
DocumentHandler handler = createDocumentHandler(ctx);