]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-568: Fixed issue when deleting term from a very long list.
authorRichard Millet <remillet@gmail.com>
Fri, 22 Mar 2019 21:57:26 +0000 (14:57 -0700)
committerRichard Millet <remillet@gmail.com>
Tue, 14 May 2019 18:52:41 +0000 (11:52 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/deleteItemFromSecondPage-vocab.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/responses/deleteItemFromPagesOfItems.res.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/vocabulary.xml
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/deleteItemFromSecondPage-vocab.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/deleteItemFromSecondPage-vocab.xml
new file mode 100644 (file)
index 0000000..dc09444
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="vocabularies">
+    <ns3:vocabularies_common xmlns:ns3="http://collectionspace.org/services/vocabulary" xmlns:ns2="http://collectionspace.org/services/jaxb">
+        <displayName>Updated createDeleteItemFromPagesOfItems Vocabulary</displayName>
+        <shortIdentifier>createDeleteItemFromPagesOfItems</shortIdentifier>
+        <description>This is an updated test vocabulary created in the createDeleteItemFromPagesOfItems XMLReplay test group</description>
+        <source>Some updated mythical book posted with item terms in createDeleteItemFromPagesOfItems test group</source>
+    </ns3:vocabularies_common>
+    <ns2:abstract-common-list xmlns:ns2="http://collectionspace.org/services/jaxb">
+        <list-item>
+            <order>1</order>
+            <displayName>createItem101</displayName>
+            <shortIdentifier>createItem101</shortIdentifier>
+        </list-item>
+        <list-item>
+            <order>2</order>
+            <displayName>createItem201</displayName>
+            <shortIdentifier>createItem201</shortIdentifier>
+        </list-item>
+    </ns2:abstract-common-list>
+</document>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/responses/deleteItemFromPagesOfItems.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/DeleteItemFromPagesOfItems/responses/deleteItemFromPagesOfItems.res.xml
new file mode 100644 (file)
index 0000000..29e330f
--- /dev/null
@@ -0,0 +1,49 @@
+<document name="vocabularies">
+    <ns2:vocabularies_common xmlns:ns2="http://collectionspace.org/services/vocabulary" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+        <shortIdentifier>createDeleteItemFromPagesOfItems</shortIdentifier>
+        <csid>${csid}</csid>
+        <displayName>Updated createDeleteItemFromPagesOfItems Vocabulary</displayName>
+        <description>
+            This is an updated test vocabulary created in the createDeleteItemFromPagesOfItems XMLReplay test group
+        </description>
+        <source>
+            Some updated mythical book posted with item terms in createDeleteItemFromPagesOfItems test group
+        </source>
+        <refName>
+            urn:cspace:testsci.collectionspace.org:vocabularies:name(createDeleteItemFromPagesOfItems)'createDeleteItemFromPagesOfItems Vocabulary'
+        </refName>
+        <vocabType>enum</vocabType>
+    </ns2:vocabularies_common>
+    <ns2:abstract-common-list xmlns:ns2="http://collectionspace.org/services/jaxb">
+        <pageNum>0</pageNum>
+        <itemsInPage>2</itemsInPage>
+        <totalItems>2</totalItems>
+        <fieldsReturned>
+            csid|uri|refName|updatedAt|workflowState|rev|sourcePage|sas|proposed|referenced|deprecated|termStatus|description|source|order|displayName|shortIdentifier
+        </fieldsReturned>
+        <list-item>
+            <refName>
+                urn:cspace:testsci.collectionspace.org:vocabularies:name(createDeleteItemFromPagesOfItems):item:name(createItem101)'createItem101'
+            </refName>
+            <workflowState>project</workflowState>
+            <rev>1</rev>
+            <sas>false</sas>
+            <proposed>true</proposed>
+            <order>1</order>
+            <displayName>createItem101</displayName>
+            <shortIdentifier>createItem101</shortIdentifier>
+        </list-item>
+        <list-item>
+            <refName>
+                urn:cspace:testsci.collectionspace.org:vocabularies:name(createDeleteItemFromPagesOfItems):item:name(createItem201)'createItem201'
+            </refName>
+            <workflowState>project</workflowState>
+            <rev>1</rev>
+            <sas>false</sas>
+            <proposed>true</proposed>
+            <order>2</order>
+            <displayName>createItem201</displayName>
+            <shortIdentifier>createItem201</shortIdentifier>
+        </list-item>
+    </ns2:abstract-common-list>
+</document>
\ No newline at end of file
index 63a870bdb4452bc15a3cd426e4a29a652a262e1e..399bdebed092762e4f5442877d4f60943fee87a3 100644 (file)
@@ -5,6 +5,57 @@
                <auth ID="admin@core.collectionspace.org">YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I=</auth>
            <auth ID="admin@testsci.collectionspace.org">YWRtaW5AdGVzdHNjaS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I=</auth>
        </auths>
+
+    <!--
+        Test deleting a vocabulary item from a list with multiple pages of items.
+    -->
+    <testGroup ID="DeleteItemFromPagesOfItems" autoDeletePOSTS="true" authForCleanup="admin@testsci.collectionspace.org">
+        <test ID="createDeleteItemFromPagesOfItems" auth="admin@testsci.collectionspace.org">
+            <method>POST</method>
+            <uri>/cspace-services/vocabularies/</uri>
+            <filename>vocabulary/vocab-Template.xml</filename>
+        </test>
+        <test ID="createItem101">
+            <method>POST</method>
+            <uri>/cspace-services/vocabularies/${createDeleteItemFromPagesOfItems.CSID}/items/</uri>
+            <filename>vocabulary/vocab-Item-template.xml</filename>
+            <vars>
+                <var ID="order">1</var>
+            </vars>
+        </test>
+        <test ID="createItem201">
+            <method>POST</method>
+            <uri>/cspace-services/vocabularies/${createDeleteItemFromPagesOfItems.CSID}/items/</uri>
+            <filename>vocabulary/vocab-Item-template.xml</filename>
+            <vars>
+                <var ID="order">2</var>
+            </vars>
+        </test>
+        <test ID="createItem301">
+            <method>POST</method>
+            <uri>/cspace-services/vocabularies/${createDeleteItemFromPagesOfItems.CSID}/items/</uri>
+            <filename>vocabulary/vocab-Item-template.xml</filename>
+            <vars>
+                <var ID="order">3</var>
+            </vars>
+        </test>
+        <test ID="deleteItemFromSecondPage" auth="admin@testsci.collectionspace.org">
+            <method>PUT</method>
+            <uri>/cspace-services/vocabularies/${createDeleteItemFromPagesOfItems.CSID}?omittedItemAction=delete&amp;pgSz=2</uri>
+            <filename>vocabulary/DeleteItemFromPagesOfItems/deleteItemFromSecondPage-vocab.xml</filename>
+        </test>
+        <test ID="xgetUpdatedVocabItems">
+            <method>GET</method>
+            <uri>/cspace-services/vocabularies/${createDeleteItemFromPagesOfItems.CSID}?showItems=true</uri>
+            <response>
+                <vars>
+                    <var ID="csid">${createDeleteItemFromPagesOfItems.CSID}</var>
+                </vars>
+                <expected level="ADDOK" />
+                <filename>vocabulary/DeleteItemFromPagesOfItems/responses/deleteItemFromPagesOfItems.res.xml</filename>
+            </response>            
+        </test>
+    </testGroup>
     
     <!--
         Test adding to a vocabulary's terms with an entirely new set of terms.
index b1c03814145af4cf9bd22b9fcade2f03d424e7c1..72c4c89aa0c63d5de4110397f62d586b6597dc76 100644 (file)
@@ -58,6 +58,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
+import java.util.ArrayList;
 import java.util.Base64;
 import java.util.HashSet;
 import java.util.Set;
@@ -250,14 +251,26 @@ public class VocabularyResource extends
                // Next, delete the items that were omitted from the incoming payload
                //
                if (shouldDeleteOmittedItems(uriInfo) == true) {
-                       String omittedItemAction = getOmittedItemAction(uriInfo);
-                       AbstractCommonList abstractCommonList = this.getAuthorityItemList(existingCtx, parentIdentifier, uriInfo);
-                       if (abstractCommonList != null && !Tools.isEmpty(abstractCommonList.getListItem())) {
-                               if (omittedItemAction.equalsIgnoreCase(VocabularyClient.DELETE_OMITTED_ITEMS)) {
-                                       deleteAuthorityItems(existingCtx, abstractCommonList, shortIdsInPayload, parentIdentifier);
-                               } else {
-                                       sotfDeleteAuthorityItems(existingCtx, abstractCommonList, shortIdsInPayload, parentIdentifier);
+                       UriInfo uriInfoCopy = new UriInfoWrapper(uriInfo);
+                       String omittedItemAction = getOmittedItemAction(uriInfoCopy);
+                       long itemsProcessed = 0;
+                       long currentPage = 0;
+                       while (true) {
+                               AbstractCommonList abstractCommonList = this.getAuthorityItemList(existingCtx, parentIdentifier, uriInfoCopy);
+                               if (abstractCommonList != null && !Tools.isEmpty(abstractCommonList.getListItem())) {
+                                       if (omittedItemAction.equalsIgnoreCase(VocabularyClient.DELETE_OMITTED_ITEMS)) {
+                                               deleteAuthorityItems(existingCtx, abstractCommonList, shortIdsInPayload, parentIdentifier);
+                                       } else {
+                                               sotfDeleteAuthorityItems(existingCtx, abstractCommonList, shortIdsInPayload, parentIdentifier);
+                                       }
                                }
+                               itemsProcessed = itemsProcessed + abstractCommonList.getItemsInPage();
+                               if (itemsProcessed >= abstractCommonList.getTotalItems()) {
+                                       break;
+                               }
+                               ArrayList<String> pageNum = new ArrayList<String>();
+                               pageNum.add(Long.toString(++currentPage));
+                               uriInfoCopy.getQueryParameters().put(IClientQueryParams.START_PAGE_PARAM, pageNum);
                        }
                }
        }