]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5504: Adding code that will update relations_common table with updated/changed...
authorRichard Millet <remillet@berkeley.edu>
Wed, 19 Sep 2012 04:52:10 +0000 (21:52 -0700)
committerRichard Millet <remillet@berkeley.edu>
Wed, 19 Sep 2012 04:52:10 +0000 (21:52 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/IRelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java [deleted file]
services/common/src/main/java/org/collectionspace/services/common/relation/RelationJAXBSchema.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java

index 905a6794ee9746a2740b7255aa6c374872d14eea..4c0894de049bbc9d40bf99a763fa352910535f67 100644 (file)
@@ -140,7 +140,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                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);
index a4c73960b11b2aba9f8b6cb7fe3eb2791242a009..408198cca7958d451c991709b7bb463c353397cb 100644 (file)
@@ -20,6 +20,7 @@ public interface IRelationsManager {
                        
     /** 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";
@@ -30,6 +31,7 @@ public interface IRelationsManager {
     
     /** 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";
index d9e420e7b54c4bd624f735bf4ef6c63569f5b6df..7034abfd89092f1724d110ec38300d87955d7045 100644 (file)
@@ -28,10 +28,12 @@ import java.util.List;
 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
@@ -42,20 +44,22 @@ import org.collectionspace.services.common.context.ServiceContext;
 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
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java
deleted file mode 100644 (file)
index ed7e17b..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/**    \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
index c28d367c5544dc5bf196d9fc2938fdb9dbee8628..2237211d097ed7e5dbd222cb10f7bd4fddad7b51 100644 (file)
@@ -26,6 +26,8 @@
  */\r
 package org.collectionspace.services.common.relation;\r
 \r
+import org.collectionspace.services.client.IRelationsManager;\r
+\r
 /**\r
  * The Interface RelationJAXBSchema.\r
  */\r
@@ -46,13 +48,13 @@ public interface RelationJAXBSchema {
        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
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java
new file mode 100644 (file)
index 0000000..b19a685
--- /dev/null
@@ -0,0 +1,39 @@
+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);
+    }
+       
+
+}
index afc573659dfdba6f8d809484c64e6626547a2e9b..3b004d7da1cc49c58b60910aff05f8afdf4736de 100644 (file)
@@ -39,6 +39,7 @@ import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 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
@@ -204,9 +205,29 @@ public class RefNameServiceUtils {
             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
@@ -355,6 +376,7 @@ public class RefNameServiceUtils {
         }\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
@@ -379,7 +401,7 @@ public class RefNameServiceUtils {
         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
index 013c9daa20d717ca787efc59d69ea5d497bafd9a..5a19e398d7cbd90feb48811a172b05ea1fa9b7c3 100644 (file)
@@ -1394,17 +1394,22 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         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");
             }