refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
// Now update the document model with the refname value
String refNameStr = refname.toString();
- docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
+ docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr); // REM - This field is deprecated now that the refName is part of the collection_space core schema
} catch (Exception e) {
logger.error(e.getMessage(), e);
/** The Constant SUBJECT. */
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_QP = SUBJECT_QP + "Type";
/** The Constant OBJECT. */
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_QP = OBJECT_QP + "Type";
import java.util.Map;\r
import javax.ws.rs.*;\r
import javax.ws.rs.core.*;\r
+\r
import org.collectionspace.services.client.IClientQueryParams;\r
import org.collectionspace.services.client.IQueryManager;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
+\r
import org.collectionspace.services.common.api.RefName;\r
import org.collectionspace.services.common.api.Tools;\r
import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
import org.collectionspace.services.common.document.DocumentFilter;\r
import org.collectionspace.services.common.document.DocumentHandler;\r
import org.collectionspace.services.common.document.DocumentNotFoundException;\r
-import org.collectionspace.services.common.document.DocumentWrapper;\r
import org.collectionspace.services.common.query.QueryManager;\r
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;\r
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;\r
+\r
import org.collectionspace.services.config.ClientType;\r
import org.collectionspace.services.config.service.DocHandlerParams;\r
import org.collectionspace.services.config.service.ListResultField;\r
import org.collectionspace.services.config.service.ServiceBindingType;\r
+\r
import org.collectionspace.services.jaxb.AbstractCommonList;\r
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;\r
-import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
import org.jboss.resteasy.util.HttpResponseCodes;\r
+\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
+++ /dev/null
-/** \r
- * IRelationsManager.java\r
- *\r
- * {Purpose of This Class}\r
- *\r
- * {Other Notes Relating to This Class (Optional)}\r
- *\r
- * $LastChangedBy: $\r
- * $LastChangedRevision: $\r
- * $LastChangedDate: $\r
- *\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 (c) 2009 {Contributing Institution}\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
- * https://source.collectionspace.org/collection-space/LICENSE.txt\r
- */\r
-package org.collectionspace.services.common.relation;\r
-\r
-import java.util.List;\r
-\r
-import org.collectionspace.services.common.document.DocumentException;\r
-import org.collectionspace.services.relation.RelationsCommon;\r
-import org.nuxeo.ecm.core.api.DocumentModel;\r
-\r
-/**\r
- * The Interface IRelationsManager.\r
- */\r
-public interface IRelationsManager {\r
-\r
- /**\r
- * Gets the relationships for the entity corresponding to the CSID=csid.\r
- * The csid refers to either the subject *OR* the object.\r
- *\r
- * @param nuxeoRepoSession the nuxeo repo session\r
- * @param csid the csid\r
- *\r
- * @return the relationships\r
- *\r
- * @throws DocumentException the document exception\r
- */\r
- public List<RelationsCommon> getRelationships(Object nuxeoRepoSession, String csid)\r
- throws DocumentException;\r
-\r
- /**\r
- * Gets the relationships.\r
- *\r
- * @param repoSession the repo session\r
- * @param subjectCsid the subject csid\r
- * @param relationType the relation type\r
- * @param objectCsid the object csid\r
- *\r
- * @return the relationships\r
- *\r
- * @throws DocumentException the document exception\r
- */\r
- public List<RelationsCommon> getRelationships(Object repoSession,\r
- String subjectCsid,\r
- String relationType,\r
- String objectCsid)\r
- throws DocumentException;\r
-\r
- /**\r
- * Creates the relationship.\r
- *\r
- * @param repoSession the repo session\r
- * @param subjectCsid the subject csid\r
- * @param predicate the predicate\r
- * @param objectCsid the object csid\r
- *\r
- * @return the relation\r
- *\r
- * @throws DocumentException the document exception\r
- */\r
- public RelationsCommon createRelationship(Object repoSession, String subjectCsid,\r
- String predicate, String objectCsid) throws DocumentException;\r
-\r
- /**\r
- * Gets the q property name.\r
- *\r
- * @param propertyName the property name\r
- *\r
- * @return the q property name\r
- */\r
- public String getQPropertyName(String propertyName);\r
-\r
- /**\r
- * Checks if is query match.\r
- *\r
- * @param documentModel the document model\r
- * @param subjectCsid the subject csid\r
- * @param predicate the predicate\r
- * @param objectCsid the object csid\r
- *\r
- * @return true, if is query match\r
- *\r
- * @throws DocumentException the document exception\r
- */\r
- public boolean isQueryMatch(DocumentModel documentModel,\r
- String subjectCsid,\r
- String predicate,\r
- String objectCsid) throws DocumentException;\r
-}\r
*/\r
package org.collectionspace.services.common.relation;\r
\r
+import org.collectionspace.services.client.IRelationsManager;\r
+\r
/**\r
* The Interface RelationJAXBSchema.\r
*/\r
final static String RELATIONSHIP_TYPE_DISPLAYNAME = "predicateDisplayName";\r
\r
final static String SUBJECT_URI = "subjectUri";\r
- final static String SUBJECT_CSID = "subjectCsid";\r
- final static String SUBJECT_REFNAME = "subjectRefName";\r
+ final static String SUBJECT_CSID = IRelationsManager.SUBJECT;\r
+ final static String SUBJECT_REFNAME = IRelationsManager.SUBJECT_REFNAME;\r
final static String SUBJECT_DOCTYPE = "subjectDocumentType";\r
\r
final static String OBJECT_URI = "objectUri";\r
- final static String OBJECT_CSID = "objectCsid";\r
- final static String OBJECT_REFNAME = "objectRefName";\r
+ final static String OBJECT_CSID = IRelationsManager.OBJECT;\r
+ final static String OBJECT_REFNAME = IRelationsManager.OBJECT_REFNAME;\r
final static String OBJECT_DOCTYPE = "objectDocumentType";\r
\r
}\r
--- /dev/null
+package org.collectionspace.services.common.relation;
+
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.api.Tools;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.query.QueryContext;
+import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+
+public class RelationUtils {
+
+ private static void updateRefNamesInRelations(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,
+ RepositoryInstance repoSession,
+ String targetField,
+ String oldRefName,
+ String newRefName) {
+
+ DocumentFilter filter = new DocumentFilter();
+ String oldOrderBy = filter.getOrderByClause();
+ if (Tools.isEmpty(oldOrderBy) == true){
+ filter.setOrderByClause(DocumentFilter.ORDER_BY_LAST_UPDATED);
+ }
+ QueryContext queryContext = new QueryContext(ctx, handler);
+
+ RepositoryInstance repoSession = null;
+
+ DocumentModelList docList = null;
+ String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ docList = repoSession.query(query);
+ }
+
+
+}
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import org.collectionspace.services.client.IRelationsManager;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
import org.collectionspace.services.common.ServiceMain;\r
this.property = prop;\r
}\r
}\r
+ \r
private static final Logger logger = LoggerFactory.getLogger(RefNameServiceUtils.class);\r
private static ArrayList<String> refNameServiceTypes = null;\r
\r
+ \r
+ public static void updateRefNamesInRelations(\r
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
+ RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,\r
+ RepositoryInstance repoSession,\r
+ String oldRefName,\r
+ String newRefName) {\r
+ //\r
+ // First, look for and update all the places where the refName is the "subject" of the relationship\r
+ //\r
+ updateRefNamesInRelations(ctx, repoClient, repoSession, IRelationsManager.SUBJECT_REFNAME, oldRefName, newRefName);\r
+ \r
+ //\r
+ // Next, look for and update all the places where the refName is the "object" of the relationship\r
+ //\r
+ updateRefNamesInRelations(ctx, repoClient, repoSession, IRelationsManager.OBJECT_REFNAME, oldRefName, newRefName);\r
+ \r
+ }\r
+ \r
public static List<AuthRefConfigInfo> getConfiguredAuthorityRefs(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {\r
List<String> authRefFields =\r
((AbstractServiceContextImpl) ctx).getAllPartsPropertyValues(\r
}\r
return refNameServiceTypes;\r
}\r
+ \r
// Seems like a good value - no real data to set this well.\r
// Note: can set this value lower during debugging; e.g. to 3 - ADR 2012-07-10\r
private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100;\r
if (!(repoClient instanceof RepositoryJavaClientImpl)) {\r
throw new InternalError("updateAuthorityRefDocs() called with unknown repoClient type!");\r
}\r
- try { // REM - How can we deal with transaction and timeout issues here.\r
+ try { // REM - How can we deal with transaction and timeout issues here?\r
final int pageSize = N_OBJS_TO_UPDATE_PER_LOOP;\r
DocumentModelList docList;\r
boolean morePages = true;\r
if (hasRefNameUpdate() == true) {
// We have work to do.
if (logger.isDebugEnabled()) {
- String eol = System.getProperty("line.separator");
- logger.debug("Need to find and update references to Item." + eol
- + " Old refName" + oldRefNameOnUpdate + eol
+ final String EOL = System.getProperty("line.separator");
+ logger.debug("Need to find and update references to Item." + EOL
+ + " Old refName" + oldRefNameOnUpdate + EOL
+ " New refName" + newRefNameOnUpdate);
}
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
- RepositoryClient repoClient = getRepositoryClient(ctx);
- String refNameProp = getRefPropName();
-
- int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, this.getRepositorySession(),
- oldRefNameOnUpdate, newRefNameOnUpdate, refNameProp);
+ RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient = getRepositoryClient(ctx);
+
+ RepositoryInstance repoSession = this.getRepositorySession();
+ RefNameServiceUtils.updateRefNamesInRelations(ctx, repoClient, repoSession,
+ oldRefNameOnUpdate, newRefNameOnUpdate);
+
+ int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, repoSession,
+ oldRefNameOnUpdate, newRefNameOnUpdate, getRefPropName());
+
+ // Finished so log a message.
if (logger.isDebugEnabled()) {
logger.debug("Updated " + nUpdated + " instances of oldRefName to newRefName");
}