]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3739 Including completion of CSPACE-3863 and CSPACE-3862
authorLaramie Crocker <laramie@berkeley.edu>
Sat, 30 Apr 2011 05:32:20 +0000 (05:32 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Sat, 30 Apr 2011 05:32:20 +0000 (05:32 +0000)
20 files changed:
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/TreeWalkResults.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlCompareJdom.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java
services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java [new file with mode: 0644]
services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomTest.java
services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/object-exit.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/objectexit/res/oe35.res.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml [new file with mode: 0644]
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java

index 1604da1ea5eaf28cd8818e0b80a10110a6a971be..38b20a42e9e19c4e1855506aeea55fce7a5bb497 100755 (executable)
@@ -59,6 +59,10 @@ public class ServiceResult {
     public String failureReason = "";\r
     public Header[] responseHeaders = new Header[0];\r
     public List<Integer> expectedCodes = new ArrayList<Integer>();\r
+    public Map<String,String>  vars = new HashMap<String,String>();\r
+    public void addVars(Map<String,String> newVars){\r
+        vars.putAll(newVars);\r
+    }\r
     private Map<String, TreeWalkResults> partSummaries = new HashMap<String, TreeWalkResults>();\r
     public void addPartSummary(String label, TreeWalkResults list){\r
         partSummaries.put(label, list);\r
@@ -220,7 +224,7 @@ public class ServiceResult {
                 + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" )\r
                 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )\r
                 + "; gotExpected:"+gotExpectedResult()\r
-                +";result:"+result+";"\r
+                //+";result:"+result+";"\r
                 + ( partsSummary(true))\r
                 +"}"\r
                 + ( includePayloads && Tools.notBlank(requestPayload) ? LINE+"requestPayload:"+LINE+CRLF+requestPayload+LINE : "" )\r
@@ -294,4 +298,29 @@ public class ServiceResult {
             return "ERROR reading request value: "+e;\r
         }\r
     }\r
+\r
+    public String get(String what){\r
+        if ("CSID".equals(what)){\r
+            return CSID;\r
+        } else if ("location".equals(what)){\r
+            return location;\r
+        } else if ("testID".equals(what)){\r
+            return testID;\r
+        } else if ("testGroupID".equals(what)){\r
+            return testGroupID;\r
+        } else if ("fullURL".equals(what)){\r
+            return fullURL;\r
+        } else if ("deleteURL".equals(what)){\r
+            return deleteURL;\r
+        } else if ("responseCode".equals(what)){\r
+            return ""+responseCode;\r
+        } else if ("method".equals(what)){\r
+            return method;\r
+        }\r
+        if (vars.containsKey(what)){\r
+            return vars.get(what);\r
+        }\r
+        return "";\r
+    }\r
+\r
 }\r
index b7c10e8178022bd9111b68e6b46a066a971c42be..021dfe66ed666eb2216e6e2f2973e5c4fdb85209 100755 (executable)
@@ -26,6 +26,8 @@ package org.collectionspace.services.IntegrationTests.xmlreplay;
 import org.collectionspace.services.common.api.Tools;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.List;\r
 \r
 /**\r
  * User: laramie\r
@@ -33,6 +35,56 @@ import java.util.ArrayList;
  * $LastChangedDate:  $\r
  */\r
 public class TreeWalkResults extends ArrayList<TreeWalkResults.TreeWalkEntry> {\r
+      public String toString(String LEAD){\r
+          StringBuffer res = new StringBuffer();\r
+          for (TreeWalkResults.TreeWalkEntry entry: this) {\r
+              res.append(entry.toString(LEAD));\r
+          }\r
+          return  res.toString();\r
+      }\r
+\r
+    /** This cllass has two public Lists: you can construct your own to set the acceptable and unacceptable STATUS codes.\r
+     *   They are defaulted to R_ADDED being acceptable. */\r
+    public static class MatchSpec {\r
+        public static final TreeWalkEntry.STATUS[]  defaultAcceptableStatiArray = {TreeWalkEntry.STATUS.INFO,\r
+                                                                                         TreeWalkEntry.STATUS.MATCHED,\r
+                                                                                         TreeWalkEntry.STATUS.R_ADDED};\r
+\r
+        public static final TreeWalkEntry.STATUS[] defaultErrorStatiArray =           {TreeWalkEntry.STATUS.R_MISSING,\r
+                                                                                          TreeWalkEntry.STATUS.NESTED_ERROR,\r
+                                                                                          TreeWalkEntry.STATUS.TEXT_DIFFERENT,\r
+                                                                                          TreeWalkEntry.STATUS.DOC_ERROR};\r
+        public List<TreeWalkEntry.STATUS> errorStati;\r
+\r
+        public static MatchSpec createDefault(){\r
+            MatchSpec result = new MatchSpec();\r
+            result.errorStati = Arrays.asList(defaultErrorStatiArray);\r
+            return result;\r
+        }\r
+        public static MatchSpec create(TreeWalkEntry.STATUS[] statiArray){\r
+            MatchSpec result = new MatchSpec();\r
+            result.errorStati = Arrays.asList(statiArray);\r
+            return result;\r
+        }\r
+        public void removeErrorFromSpec(TreeWalkEntry.STATUS status){\r
+            ArrayList arrayList = new ArrayList(errorStati);\r
+            arrayList.remove(status);\r
+            errorStati = arrayList;\r
+        }\r
+        public String toString(){\r
+            StringBuffer buff = new StringBuffer("{");\r
+            int i = 0;\r
+            for (TreeWalkEntry.STATUS status : errorStati){\r
+                 if (i>0) buff.append(",");\r
+                String foo = status.toString();\r
+                buff.append(foo);\r
+                i++;\r
+            }\r
+            buff.append("}");\r
+            return buff.toString();\r
+        }\r
+\r
+    }\r
 \r
     public static class TreeWalkEntry {\r
         public String lpath = "";\r
@@ -43,24 +95,28 @@ public class TreeWalkResults extends ArrayList<TreeWalkResults.TreeWalkEntry> {
         public String actual = "";\r
         public String message = "";\r
         public String errmessage = "";\r
-        public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT};\r
+        public TreeWalkResults nested;\r
+        public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT, NESTED_ERROR};\r
         public STATUS status;\r
         public String toString(){\r
+            return toString("\r\n");\r
+        }\r
+        public String toString(String LEAD){\r
+            String INDENT = "    ";\r
             return\r
-                 "{"\r
+                 LEAD + "{"\r
                  +status.name()\r
                  +(Tools.notEmpty(lpath) ? ", L.path:"+lpath : "")\r
                  +(Tools.notEmpty(rpath) ? ", R.path:"+rpath : "")\r
                  +(Tools.notEmpty(message) ? ", message:"+message : "")\r
                  +(Tools.notEmpty(errmessage) ? ", errmessage:"+errmessage : "")\r
                  +", status:"+status\r
-                 +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ",\r\n    L.trimmed:"+ltextTrimmed : "")\r
-                 +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ",\r\n    R.trimmed:"+rtextTrimmed : "")\r
-                 +((status != STATUS.MATCHED) && Tools.notEmpty(expected) ? "\r\nEXPECTED:\r\n------------------\r\n"+expected.trim()+"\r\n------------------" : "")\r
-                 +((status != STATUS.MATCHED) && Tools.notEmpty(actual) ? "\r\nACTUAL:\r\n------------------\r\n"+actual.trim()+"\r\n------------------\r\n" : "")\r
-\r
+                 +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ","+LEAD+"    L.trimmed:"+ltextTrimmed : "")\r
+                 +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ","+LEAD+"    R.trimmed:"+rtextTrimmed : "")\r
+                 +((status != STATUS.MATCHED) && Tools.notEmpty(expected) ? LEAD+"EXPECTED:"+LEAD+"------------------"+LEAD+expected.trim()+LEAD+"------------------" : "")\r
+                 +((status != STATUS.MATCHED) && Tools.notEmpty(actual) ? LEAD+"ACTUAL:"+LEAD+"------------------"+LEAD+actual.trim()+LEAD+"------------------"+LEAD : "")\r
+                 +((status != STATUS.MATCHED) && (nested != null) ? LEAD+"NESTED:"+LEAD+"------------------"+LEAD+nested.toString(LEAD+INDENT)+LEAD+"------------------"+LEAD : "")\r
                  +"}";\r
-\r
         }\r
     }\r
 \r
@@ -127,6 +183,15 @@ public class TreeWalkResults extends ArrayList<TreeWalkResults.TreeWalkEntry> {
         return true;\r
     }\r
 \r
+    public boolean treesMatch(MatchSpec matchSpec) {\r
+        for (TreeWalkEntry entry : this) {\r
+            if (matchSpec.errorStati.contains(entry.status)) {\r
+                return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
     public int countFor(TreeWalkEntry.STATUS status){\r
         int count = 0;\r
         for (TreeWalkEntry entry : this){\r
index b747cf3cfea0a89aeb55aee0a9a5012bf1d3a9df..fd49f9358a50990f62c30cf81f077ba2aee5f798 100755 (executable)
@@ -60,7 +60,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
         return doc;\r
     }\r
 \r
-    public static TreeWalkResults compareParts(String expectedContent, String leftID, String actualPartContent, String rightID, String startElement){\r
+    public static TreeWalkResults compareParts(String expectedContent, String leftID, String actualPartContent, String rightID, String startElement, TreeWalkResults.MatchSpec matchSpec){\r
         TreeWalkResults list = new TreeWalkResults();\r
         try {\r
 \r
@@ -85,7 +85,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
             } else {\r
                 Document expected = getDocumentFromContent(expectedContent);\r
                 Document actual = getDocumentFromContent(actualPartContent);\r
-                treeWalk(expected, actual, list, startElement);\r
+                treeWalk(expected, actual, list, startElement, matchSpec);\r
             }\r
         } catch (Throwable t){\r
             String msg = "ERROR in XmlReplay.compareParts(): "+t;\r
@@ -135,7 +135,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
 \r
     xpath.addNamespace("x", d.getRootElement().getNamespaceUri());\r
     */\r
-    public static boolean treeWalk(Document left, Document right, TreeWalkResults list, String startElement) throws Exception {\r
+    public static boolean treeWalk(Document left, Document right, TreeWalkResults list, String startElement, TreeWalkResults.MatchSpec matchSpec) throws Exception {\r
         Element leftElement = left.getRootElement();\r
         Element rightElement = right.getRootElement();\r
         if (Tools.notBlank(startElement)) {\r
@@ -149,11 +149,11 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
                 rightElement = (Element)rtest;\r
             }\r
         }\r
-        boolean res = treeWalk(leftElement, rightElement, "/", list);\r
+        boolean res = treeWalk(leftElement, rightElement, "/", list, matchSpec);\r
         return res;\r
     }\r
 \r
-    public static boolean treeWalk(Element left, Element right, String parentPath, TreeWalkResults msgList) throws Exception {\r
+    public static boolean treeWalk(Element left, Element right, String parentPath, TreeWalkResults msgList, TreeWalkResults.MatchSpec matchSpec) throws Exception {\r
         String SPACE = "     ";\r
         if (left == null && right == null){\r
             return true;\r
@@ -191,7 +191,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
                 //System.out.println("-----------------doRepeating------"+leftChildPath);\r
                 foundRepeatingList.add(leftChildPath);\r
                 boolean repeatingIdentical =\r
-                    doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList, namespace) ; //todo: deal with foundRightMap in this repeating field block.\r
+                    doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList, namespace, matchSpec) ; //todo: deal with foundRightMap in this repeating field block.\r
                 if ( ! repeatingIdentical ){\r
                     //System.out.println("\r\n\r\n\r\n*****************************\r\nOne repeating field failed: "+msgList);\r
                     return false;\r
@@ -223,7 +223,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
                     msgList.add(entry);\r
                 }\r
                 //============ DIVE !! =====================================================\r
-                result = result && treeWalk( leftChild, rightChild, leftChildPath, msgList);\r
+                result = result && treeWalk( leftChild, rightChild, leftChildPath, msgList, matchSpec);\r
             }\r
         }\r
         for (Object r : right.getChildren()){\r
@@ -253,7 +253,14 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
         return outputter.outputString(el);\r
     }\r
 \r
-    public static boolean doRepeatingFieldComparison(List leftList, String leftChildPath, String leftChildName, Element left, Element right, TreeWalkResults msgList, Namespace namespace)\r
+    public static boolean doRepeatingFieldComparison(List leftList,\r
+                                                                                     String leftChildPath,\r
+                                                                                     String leftChildName,\r
+                                                                                     Element left,\r
+                                                                                     Element right,\r
+                                                                                     TreeWalkResults msgList,\r
+                                                                                     Namespace namespace,\r
+                                                                                     TreeWalkResults.MatchSpec matchSpec)\r
     throws Exception {\r
         //todo: deal with foundRightMap in this repeating field block.\r
         List rightList = select(right, leftChildName, namespace);\r
@@ -274,7 +281,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
             twe.status = TreeWalkEntry.STATUS.R_ADDED;\r
             twe.message = "Repeating field count not matched. Field: "+leftChildPath+" Left: "+leftList.size()+" Right: "+rightList.size();\r
             msgList.add(twe);\r
-            return false;\r
+            //LC 20110429 return false;\r
         }\r
 \r
         for (Object le : leftList){\r
@@ -285,18 +292,28 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
                 Element rightEl = (Element)re;\r
                 //pl("right", rightEl);\r
                 TreeWalkResults msgListInner = new TreeWalkResults();\r
-                treeWalk(leftEl, rightEl, leftChildPath, msgListInner);\r
-                if (msgListInner.isStrictMatch()){\r
+                //========== DIVE !!! =======================\r
+                treeWalk(leftEl, rightEl, leftChildPath, msgListInner, matchSpec);\r
+                //========================================\r
+\r
+                if (msgListInner.treesMatch(matchSpec)){   //if (msgListInner.isStrictMatch()){\r
                     found = true;\r
                     TreeWalkEntry twe = new TreeWalkEntry();\r
                     twe.lpath = leftChildPath;\r
                     twe.status = TreeWalkEntry.STATUS.MATCHED;\r
                     msgList.add(twe);\r
-                    //System.out.println("===========================\r\nfound match for "+leftEl+"\r\n===========================\r\n");\r
                     rightList.remove(re); //found it, don't need to inspect this element again.  Since we are breaking from loop, removing element won't mess up iterator--we get a new one on the next loop.\r
                     break;\r
+                } else {\r
+                    TreeWalkEntry twe = new TreeWalkEntry();\r
+                    twe.lpath = leftChildPath;\r
+                    twe.status = TreeWalkEntry.STATUS.NESTED_ERROR;\r
+                    twe.nested = msgListInner;\r
+                    msgList.add(twe);\r
+                    //String line = "\r\n\r\n*********************************\r\n";\r
+                    //System.out.println(line+"TreeWalkResults: from walking rightEl: "+rightEl+" leftEl: "+leftEl + " msgListInner:"+ msgListInner+line);\r
                 }\r
-            }\r
+            }  // END for(rightList)\r
             if ( ! found){\r
                 TreeWalkEntry twe = new TreeWalkEntry();\r
                 twe.lpath = leftChildPath;\r
@@ -305,7 +322,7 @@ private static final String DEFAULT_SAX_DRIVER_CLASS = "org.apache.xerces.parser
                 msgList.add(twe);\r
                 return false;\r
             }\r
-        }\r
+        }  // END for(leftLlist)\r
         return true;\r
     }\r
 \r
index 32eba083c843413d36bb5c49857b53c26cd2ba51..463cf043707a56da88a663e56351b594a121ceaf 100755 (executable)
@@ -379,12 +379,14 @@ public class XmlReplay {
             if (Tools.notBlank(partLabel))\r
             startElement = "/document/*[local-name()='"+partLabel+"']";\r
         }\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
         TreeWalkResults list =\r
             XmlCompareJdom.compareParts(expectedPartContent,\r
                                         leftID,\r
                                         serviceResult.result,\r
                                         rightID,\r
-                                        startElement);\r
+                                        startElement,\r
+                                        matchSpec);\r
         serviceResult.addPartSummary(label, list);\r
         return OK;\r
     }\r
@@ -541,12 +543,16 @@ public class XmlReplay {
                         } else if (isPUT) {\r
                             uri = fromTestID(uri, testNode, serviceResultsMap);\r
                         }\r
+                        //vars only make sense in two contexts: POST/PUT, because you are submitting another file with internal expressions,\r
+                        // and in <response> nodes. For GET, DELETE, there is no payload, so all the URLs with potential expressions are right there in the testNode.\r
                         Map<String,String> vars = null;\r
                         if (parts.varsList.size()>0){\r
                             vars = parts.varsList.get(0);\r
                         }\r
                         serviceResult = XmlReplayTransport.doPOST_PUTFromXML(parts.responseFilename, vars, protoHostPort, uri, method, XmlReplayTransport.APPLICATION_XML, evalStruct, authForTest, testIDLabel);\r
-\r
+                        if (vars!=null) {\r
+                            serviceResult.addVars(vars);\r
+                        }\r
                         results.add(serviceResult);\r
                         //if (isPOST){\r
                             serviceResultsMap.put(testID, serviceResult);      //PUTs do not return a Location, so don't add PUTs to serviceResultsMap.\r
index e9b4ca6456a9718f598096b93fd12eed538cbb3b..641e2cbd79e044c17ca4f6da68d42a51a9e99231 100755 (executable)
@@ -69,109 +69,126 @@ public class XmlReplayTest {
     public static XmlReplay createXmlReplayUsingIntegrationTestsModule(String relToServicesRoot) throws Exception {\r
         String thisDir = Tools.glue(relToServicesRoot, "/", "IntegrationTests");\r
         String pwd = (new File(thisDir)).getCanonicalPath();\r
-        System.out.println("createXmlReplayUsingIntegrationTestsModule.pwd: "+pwd);\r
+        //System.out.println("createXmlReplayUsingIntegrationTestsModule.pwd: "+pwd);\r
         XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE);\r
-        System.out.println("XmlReplay: "+replay);\r
+        //System.out.println("XmlReplay: "+replay);\r
         return replay;\r
     }\r
 \r
     public static void logTest(ServiceResult sresult, String testname){\r
-        ResultSummary summary = resultSummary(sresult);\r
+        ResultSummary summary = resultSummary(sresult, HTML);\r
         org.testng.Reporter.log(summary.table);\r
-        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'.");\r
+        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'. "+summary.errorTests);\r
     }\r
 \r
     public static void logTest(List<ServiceResult> list, String testname){\r
-        ResultSummary summary = resultSummary(list);\r
+        ResultSummary summary = resultSummary(list, HTML);\r
         org.testng.Reporter.log(summary.table);\r
-        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'.");\r
+        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'. "+summary.errorTests);\r
     }\r
 \r
     public static void logTestForGroup(List<List<ServiceResult>> list, String testname){\r
-        ResultSummary summary = resultSummaryForGroup(list);\r
+        ResultSummary summary = resultSummaryForGroup(list, HTML);\r
         org.testng.Reporter.log(summary.table);\r
-        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'.");\r
+        ResultSummary textSummary = resultSummaryForGroup(list, TEXT);\r
+        System.out.println("SUMMARY: \r\n"+textSummary.table);\r
+        Assert.assertEquals(summary.oks, summary.total, "Expected all "+summary.total+ " XmlReplay tests to pass.  See Output from test '"+testname+"'. "+summary.errorTests);\r
     }\r
 \r
 \r
     //============== HELPERS AND FORMATTING =====================================================\r
+    public static class FORMAT {\r
+        private static final String TBLSTART = "";\r
+        private static final String ROWSTART = "\r\n       ";\r
+        private static final String ROWSTARTRED = "\r\n    ** ";\r
+        private static final String SEP = "  |  ";\r
+        private static final String ROWEND = "";\r
+        private static final String ROWENDRED = "";\r
+        private static final String TBLEND = "";\r
 \r
-    private static final String TBLSTART = "<table border='1'>";\r
-    private static final String ROWSTART = "<tr><td bgcolor='white'>";\r
-    private static final String ROWSTARTRED = "<tr><td bgcolor='red'><b>";\r
-    private static final String SEP = "</td><td>";\r
-    private static final String ROWEND = "</td></tr>";\r
-    private static final String ROWENDRED = "</b></td></tr>";\r
-    private static final String TBLEND = "</table>";\r
+    }\r
+    public static final FORMAT TEXT = new FORMAT();\r
+    public static class HTML_FORMAT extends FORMAT {\r
+        private static final String TBLSTART = "<table border='1'>";\r
+        private static final String ROWSTART = "<tr><td bgcolor='white'>";\r
+        private static final String ROWSTARTRED = "<tr><td bgcolor='red'><b>";\r
+        private static final String SEP = "</td><td>";\r
+        private static final String ROWEND = "</td></tr>";\r
+        private static final String ROWENDRED = "</b></td></tr>";\r
+        private static final String TBLEND = "</table>";\r
+    }\r
+    public static final FORMAT HTML = new HTML_FORMAT();\r
 \r
     public static class ResultSummary {\r
         public long oks = 0;\r
         public long total = 0;\r
         public String table = "";\r
         public List<String> groups = new ArrayList<String>();\r
+        public List<String> errorTests = new ArrayList<String>();\r
     }\r
 \r
-    public static ResultSummary resultSummaryForGroup(List<List<ServiceResult>> list){\r
+    public static ResultSummary resultSummaryForGroup(List<List<ServiceResult>> list, FORMAT format){\r
         ResultSummary summary = new ResultSummary();\r
         summary.oks = 0;\r
         summary.total = 0;\r
         StringBuffer buff = new StringBuffer();\r
-        buff.append(TBLSTART);\r
+        buff.append(format.TBLSTART);\r
         for (List<ServiceResult> serviceResults : list){\r
             String groupID = "";\r
             if (serviceResults.size()>0){\r
                 groupID = serviceResults.get(0).testGroupID;\r
                 summary.groups.add(groupID);\r
             }\r
-            buff.append(ROWSTART+"XmlReplay testGroup "+groupID+ROWEND);\r
+            buff.append(format.ROWSTART+"XmlReplay testGroup "+groupID+format.ROWEND);\r
             for (ServiceResult serviceResult : serviceResults){\r
                 summary.total++;\r
                 if (serviceResult.gotExpectedResult()){\r
                     summary.oks++;\r
-                    buff.append(ROWSTART+serviceResult.minimal()+ROWEND);\r
+                    buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND);\r
                 } else {\r
-                    buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED);\r
+                    buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED);\r
+                    summary.errorTests.add(serviceResult.testGroupID+':'+serviceResult.testID+':'+serviceResult.fullURL);\r
                 }\r
             }\r
         }\r
-        buff.append(TBLEND);\r
+        buff.append(format.TBLEND);\r
         summary.table = buff.toString();\r
         return summary;\r
     }\r
 \r
-    public static ResultSummary resultSummary(List<ServiceResult> serviceResults){\r
+    public static ResultSummary resultSummary(List<ServiceResult> serviceResults,  FORMAT format){\r
         ResultSummary summary = new ResultSummary();\r
         summary.oks = 0;\r
         summary.total = 0;\r
         StringBuffer buff = new StringBuffer();\r
-        buff.append(TBLSTART);\r
+        buff.append(format.TBLSTART);\r
         for (ServiceResult serviceResult : serviceResults){\r
             summary.total++;\r
             if (serviceResult.gotExpectedResult()){\r
                 summary.oks++;\r
-                buff.append(ROWSTART+serviceResult.minimal()+ROWEND);\r
+                buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND);\r
             } else {\r
-                buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED);\r
+                buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED);\r
             }\r
         }\r
-        buff.append(TBLEND);\r
+        buff.append(format.TBLEND);\r
         summary.table = buff.toString();\r
         return summary;\r
     }\r
 \r
-    public static ResultSummary resultSummary(ServiceResult serviceResult){\r
+    public static ResultSummary resultSummary(ServiceResult serviceResult, FORMAT format){\r
         ResultSummary summary = new ResultSummary();\r
         summary.oks = 0;\r
         summary.total = 1;\r
         StringBuffer buff = new StringBuffer();\r
-        buff.append(TBLSTART);\r
+        buff.append(format.TBLSTART);\r
         if (serviceResult.gotExpectedResult()){\r
             summary.oks = 1;\r
-            buff.append(ROWSTART+serviceResult.minimal()+ROWEND);\r
+            buff.append(format.ROWSTART+serviceResult.minimal()+format.ROWEND);\r
         } else {\r
-            buff.append(ROWSTARTRED+serviceResult.minimal()+ROWENDRED);\r
+            buff.append(format.ROWSTARTRED+serviceResult.minimal()+format.ROWENDRED);\r
         }\r
-        buff.append(TBLEND);\r
+        buff.append(format.TBLEND);\r
         summary.table = buff.toString();\r
         return summary;\r
     }\r
diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlCompareJdomRepeatingTest.java
new file mode 100644 (file)
index 0000000..634b96f
--- /dev/null
@@ -0,0 +1,102 @@
+/**\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 Regents of the University of California\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
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package org.collectionspace.services.IntegrationTests.test;\r
+\r
+import org.collectionspace.services.IntegrationTests.xmlreplay.TreeWalkResults;\r
+import org.collectionspace.services.IntegrationTests.xmlreplay.XmlCompareJdom;\r
+import org.collectionspace.services.common.api.FileTools;\r
+import org.collectionspace.services.common.api.Tools;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * User: laramie\r
+ * $LastChangedRevision:  $\r
+ * $LastChangedDate:  $\r
+ */\r
+public class XmlCompareJdomRepeatingTest {\r
+\r
+    private static String getDirectory(){\r
+        String dataDir = "src/test/resources/test-data/xmlreplay/XmlCompareJdom";   // this dir lives under service/IntegrationTests\r
+        String pwd = ".";\r
+        try {\r
+            pwd = (new File(".")).getCanonicalPath();\r
+        } catch (Exception e){\r
+            System.err.println("Error trying to find current working directory: "+e);\r
+        }\r
+        String thisDir = Tools.glue(pwd, "/", dataDir);\r
+        return thisDir;\r
+    }\r
+\r
+    private void testBanner(String msg){\r
+        String BANNER ="-------------------------------------------------------";\r
+        String R = "\r\n";\r
+        System.out.println(BANNER\r
+                                     + R +" TEST CLASS: "+this.getClass().getName()\r
+                                     + R +" TEST NAME: "+msg\r
+                                     + R +" TEST DATA DIR: "+getDirectory()\r
+                                     + R\r
+                                     +BANNER);\r
+    }\r
+\r
+    @Test\r
+    public void testLeftAndRightSame(){\r
+        testBanner("testLeftAndRightSame");\r
+        String dir = getDirectory();\r
+        String expectedPartContent = FileTools.readFile(dir, "1-left.xml");\r
+        String fromServerContent = FileTools.readFile(dir, "1-right.xml");\r
+        String startPath = "/document/*[local-name()='relations-common-list']";\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
+        TreeWalkResults results =\r
+            XmlCompareJdom.compareParts(expectedPartContent,\r
+                                        "expected",\r
+                                        fromServerContent,\r
+                                        "from-server",\r
+                                        startPath,\r
+                                        matchSpec);\r
+        XmlCompareJdomTest.assertTreeWalkResults(results,1,0,0,false, matchSpec);\r
+                                   // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
+    }\r
+\r
+    @Test\r
+    public void testLeftAndRightSameNoStartElement(){\r
+        testBanner("testLeftAndRightSameNoStartElement");\r
+        String dir = getDirectory();\r
+         String expectedPartContent = FileTools.readFile(dir, "2-left.xml");\r
+        String fromServerContent = FileTools.readFile(dir, "2-right.xml");\r
+        String startPath = "/document";\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
+        TreeWalkResults results =\r
+            XmlCompareJdom.compareParts(expectedPartContent,\r
+                                        "expected",\r
+                                        fromServerContent,\r
+                                        "from-server",\r
+                                        startPath,\r
+                                        matchSpec);\r
+        XmlCompareJdomTest.assertTreeWalkResults(results,0,0,0,true,matchSpec);\r
+                                   // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
+    }\r
+\r
+\r
+}\r
index dbc9c018d31c50ecab08709d22217a7db8320d06..93cb2343031843d6f5b991243e1b3364321c59b4 100755 (executable)
@@ -39,53 +39,54 @@ public class XmlCompareJdomTest {
         String BANNER ="-------------------------------------------------------";\r
         System.out.println(BANNER+"\r\n"+this.getClass().getName()+"\r\n"+msg+"\r\n"+BANNER);\r
     }\r
-    private void printTreeWalkResults(TreeWalkResults list){\r
+    public static void printTreeWalkResults(TreeWalkResults list){\r
         for (TreeWalkResults.TreeWalkEntry entry : list){\r
             System.out.println(entry.toString());\r
         }\r
     }\r
 \r
-    private void assertTreeWalkResults(TreeWalkResults results,\r
-                                       int addedRight,\r
-                                       int missingRight,\r
-                                       int textMismatches,\r
-                                       boolean strictMatch,\r
-                                       boolean treesMatch){\r
-        System.out.println("assertTreeWalkResults: ");\r
+    static void assertTrue(boolean stmt, String msg, TreeWalkResults results){\r
+        if (!stmt){\r
+            System.out.println("=====> Assertion Failed: "+msg);\r
+            printTreeWalkResults(results);\r
+        }\r
+        Assert.assertTrue(stmt, msg);\r
+    }\r
+    static void assertEquals(Object o1, Object o2, String msg, TreeWalkResults results){\r
+        if ( ! o1.equals(o2)) {\r
+            System.out.println("=====> Assertion Equals Failed: "+" o1: {"+o1+"} o2: {"+o2+"}"+"\r\n        "+msg);\r
+            printTreeWalkResults(results);\r
+        }\r
+       Assert.assertEquals(o1, o2, msg);\r
+    }\r
 \r
+    public  static void assertTreeWalkResults(TreeWalkResults results,\r
+                                                                      int addedRight,\r
+                                                                      int missingRight,\r
+                                                                      int textMismatches,\r
+                                                                      boolean strictMatch,\r
+                                                                      TreeWalkResults.MatchSpec matchSpec){\r
         int addedr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_ADDED);\r
         int missingr = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING);\r
         int tdiff = results.countFor(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT);\r
         int badCount = results.getMismatchCount();\r
         boolean strict = results.isStrictMatch();\r
-        boolean treeOK = results.treesMatch();\r
+        boolean treeOK = results.treesMatch(matchSpec);\r
 \r
-        String expected = "    expected: addedRight:"+addedRight+",missingRight:"+missingRight+",textMismatches:"+textMismatches\r
-                              +",strictMatch:"+strictMatch+",treesMatch:"+treesMatch;\r
-\r
-        String actual   = "    actual:   addedRight:"+addedr+",missingRight:"+missingr+",textMismatches:"+tdiff\r
-                              +",strictMatch:"+strict+",treesMatch:"+treeOK;\r
+        String expected = "\r\n        expected: addedRight:"+addedRight+",missingRight:"+missingRight+",textMismatches:"+textMismatches\r
+                              +",strictMatch:"+strictMatch+",matchSpec:"+matchSpec;\r
 \r
+        String actual   = "\r\n        actual:   addedRight:"+addedr+",missingRight:"+missingr+",textMismatches:"+tdiff\r
+                              +",strictMatch:"+strict+",matchSpec:"+matchSpec;\r
         String exp_act = expected +"\r\n"+actual+"\r\n";\r
-        System.out.print(exp_act);\r
-\r
-        printTreeWalkResults(results);\r
-\r
-\r
         boolean done = false;\r
         try {\r
-            Assert.assertEquals(addedr, addedRight, "assertTreeWalkResults:R_ADDED mismatch."+exp_act);\r
-\r
-            Assert.assertEquals(missingr, missingRight, "assertTreeWalkResults:R_MISSING mismatch."+exp_act);\r
-\r
-            Assert.assertEquals(tdiff, textMismatches, "assertTreeWalkResults:TEXT_DIFFERENT mismatch."+exp_act);\r
-\r
-\r
-            Assert.assertTrue((strict==strictMatch), "assertTreeWalkResults:strictMatch mismatch."+exp_act);\r
-\r
-            Assert.assertTrue((treeOK==treesMatch), "assertTreeWalkResults:treesMatch mismatch."+exp_act);\r
-\r
-            System.out.println("SUCCESS: assertTreeWalkResults done.\r\n");\r
+           assertEquals(addedr, addedRight, "assertTreeWalkResults:R_ADDED mismatch." + exp_act, results);\r
+            assertEquals(missingr, missingRight, "assertTreeWalkResults:R_MISSING mismatch." + exp_act, results);\r
+            assertEquals(tdiff, textMismatches, "assertTreeWalkResults:TEXT_DIFFERENT mismatch." + exp_act, results);\r
+            assertTrue((strict == strictMatch), "assertTreeWalkResults:strictMatch mismatch." + exp_act, results);\r
+            assertTrue((treeOK), "assertTreeWalkResults:treesMatch("+matchSpec+") returned false."+exp_act, results);\r
+            //System.out.println("SUCCESS: assertTreeWalkResults done.\r\n");\r
             done = true;\r
         } finally {\r
             if (!done) System.out.println("FAILURE: assertTreeWalkResults failed an assertion. See surefire report.\r\n");\r
@@ -95,26 +96,31 @@ public class XmlCompareJdomTest {
     @Test\r
     public void testXmlCompareJdom(){\r
         testBanner("testXmlCompareJdom");\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
         TreeWalkResults results =\r
                     XmlCompareJdom.compareParts(expectedPartContent,\r
                                         "expected",\r
                                         partFromServer,\r
                                         "from-server",\r
-                                        exPARTNAME);\r
-        assertTreeWalkResults(results,0,0,0,true,true);\r
+                                        exPARTNAME,\r
+                                        matchSpec);\r
+        assertTreeWalkResults(results,0,0,0,true,matchSpec);\r
                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
     }\r
 \r
     @Test\r
     public void testTextContentDifferent(){\r
         testBanner("testTextContentDifferent");\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
+        matchSpec.removeErrorFromSpec(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT);\r
         TreeWalkResults results =\r
             XmlCompareJdom.compareParts(expectedPartContent,\r
                                         "expected",\r
                                         srvHEAD+srvEN2+srvDEPOSITOR+srvFOOT,\r
                                         "from-server",\r
-                                        exPARTNAME);\r
-        assertTreeWalkResults(results,0,0,1,false,true);\r
+                                        exPARTNAME,\r
+                                        matchSpec);\r
+        assertTreeWalkResults(results,0,0,1,false,matchSpec);\r
                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
     }\r
 \r
@@ -122,13 +128,15 @@ public class XmlCompareJdomTest {
     @Test\r
     public void testAddedR(){\r
         testBanner("testAddedR");\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
         TreeWalkResults results =\r
             XmlCompareJdom.compareParts(expectedPartContent,\r
                                         "expected",\r
                                         srvHEAD+srvEN+exNEWTREE+srvDEPOSITOR+exNEW+srvFOOT,\r
                                         "from-server",\r
-                                        exPARTNAME);\r
-        assertTreeWalkResults(results,2,0,0,false,false);\r
+                                        exPARTNAME,\r
+                                        matchSpec);\r
+        assertTreeWalkResults(results,2,0,0,false,matchSpec);\r
                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
 \r
     }\r
@@ -136,26 +144,32 @@ public class XmlCompareJdomTest {
     @Test\r
     public void testAddedL(){\r
         testBanner("testAddedL");\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
+        matchSpec.removeErrorFromSpec(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING);\r
+\r
         TreeWalkResults results =\r
             XmlCompareJdom.compareParts(exHEAD + exEN_WCH + exNEWTREE + exDEP  + exNEW + exFOOT,\r
                                     "expected",\r
                                     partFromServer,\r
                                     "from-server",\r
-                                    exPARTNAME);\r
-        assertTreeWalkResults(results,0,3,0,false,false);\r
+                                    exPARTNAME,\r
+                                    matchSpec);\r
+        assertTreeWalkResults(results,0,3,0,false,matchSpec);\r
                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
     }\r
 \r
     @Test\r
     public void testChildrenReordered(){\r
         testBanner("testChildrenReordered");\r
+        TreeWalkResults.MatchSpec matchSpec = TreeWalkResults.MatchSpec.createDefault();\r
         TreeWalkResults results =\r
             XmlCompareJdom.compareParts(exHEAD  + exDEP + exEN + exFOOT,\r
                                     "expected",\r
                                     partFromServer,\r
                                     "from-server",\r
-                                    exPARTNAME);\r
-        assertTreeWalkResults(results,0,0,0,true,true);\r
+                                    exPARTNAME,\r
+                                    matchSpec);\r
+        assertTreeWalkResults(results,0,0,0,true,matchSpec);\r
                                    // addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
     }\r
 \r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-left.xml
new file mode 100644 (file)
index 0000000..f400b9d
--- /dev/null
@@ -0,0 +1,37 @@
+<document name="persons">
+  <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <shortIdentifier>johnWayneActorChild</shortIdentifier>
+  </ns2:persons_common>
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <itemsInPage>2</itemsInPage>
+    <totalItems>2</totalItems>
+    <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>
+    <relation-list-item>
+      <subjectCsid>1deda741-3b08-41ca-9681</subjectCsid>
+      <predicate>hasBroader</predicate>
+      <objectCsid>d19bf94c-53c3-4295-8e5c</objectCsid>
+      <subject>
+        <csid>1deda741-3b08-41ca-9681</csid>
+        <number>johnWayneActorChild2</number>
+      </subject>
+      <object>
+        <csid>d19bf94c-53c3-4295-8e5c</csid>
+        <number>johnWayneActor</number>
+      </object>
+    </relation-list-item>
+    <relation-list-item>
+      <subjectCsid>6e951b58-2087-4eea-a6b1</subjectCsid>
+      <predicate>hasBroader</predicate>
+      <objectCsid>d19bf94c-53c3-4295-8e5c</objectCsid>
+      <subject>
+        <csid>6e951b58-2087-4eea-a6b1</csid>
+        <number>johnWayneActorChild3</number>
+      </subject>
+      <object>
+        <csid>d19bf94c-53c3-4295-8e5c</csid>
+        <number>johnWayneActor</number>
+      </object>
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/1-right.xml
new file mode 100644 (file)
index 0000000..e69e2f2
--- /dev/null
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="persons">
+  <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <surName>Wayne</surName>
+    <birthPlace>Winterset, Iowa</birthPlace>
+    <deathDate>June 11, 1979</deathDate>
+    <nationalities />
+    <shortIdentifier>johnWayneActorChild</shortIdentifier>
+    <shortDisplayName>JohnWayne</shortDisplayName>
+    <schoolsOrStyles />
+    <gender>male</gender>
+    <birthDate>May 26, 1907</birthDate>
+    <foreName>John</foreName>
+    <groups>
+      <group>Irish</group>
+      <group>Scottish</group>
+    </groups>
+    <occupations />
+    <bioNote>born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive
+    voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions.</bioNote>
+    <displayNameComputed>false</displayNameComputed>
+    <csid>28d949e9-794b-457a-93fe</csid>
+    <shortDisplayNameComputed>false</shortDisplayNameComputed>
+    <inAuthority>53ef7d20-4154-4ce9-952d</inAuthority>
+    <refName>urn:cspace:org.collectionspace.demo:personauthority:name(CSPACE3739PersonAuthority):person:name(johnWayneActorChild)'John Wayne'</refName>
+    <displayName>John Wayne</displayName>
+  </ns2:persons_common>
+  <ns2:collectionspace_core xmlns:ns2="http://collectionspace.org/collectionspace_core/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <tenantId>1</tenantId>
+    <updatedAt>2011-04-28T23:46:08Z</updatedAt>
+    <createdAt>2011-04-28T23:46:08Z</createdAt>
+  </ns2:collectionspace_core>
+  <ns2:account_permission xmlns:ns2="http://collectionspace.org/services/authorization">
+    <account>
+      <accountId>74bb3d58-a8cb-4367-86da-d48f8fa5aece</accountId>
+      <userId>admin@collectionspace.org</userId>
+    </account>
+    <permission>
+      <permRelationshipId>71</permRelationshipId>
+      <permissionId>c5509eda-9e3f-4cad-91ea-4efeedc650c4</permissionId>
+      <resourceName>persons</resourceName>
+      <actionGroup>CRUDL</actionGroup>
+    </permission>
+    <permission>
+      <permRelationshipId>70</permRelationshipId>
+      <permissionId>fcfec805-ee00-4888-8196-0389d30ca5fa</permissionId>
+      <resourceName>/personauthorities/*/items/*/workflow/</resourceName>
+      <actionGroup>CRUDL</actionGroup>
+    </permission>
+  </ns2:account_permission>
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <pageSize>40</pageSize>
+    <itemsInPage>2</itemsInPage>
+    <totalItems>2</totalItems>
+    <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>
+    <relation-list-item>
+      <uri>/relations/2f1bacd7-6fc6-41bf-a8d6</uri>
+      <csid>2f1bacd7-6fc6-41bf-a8d6</csid>
+      <subjectCsid>1deda741-3b08-41ca-9681</subjectCsid>
+      <relationshipType>hasBroader</relationshipType>
+      <predicate>hasBroader</predicate>
+      <objectCsid>d19bf94c-53c3-4295-8e5c</objectCsid>
+      <subject>
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/1deda741-3b08-41ca-9681</uri>
+        <csid>1deda741-3b08-41ca-9681</csid>
+        <service>Person</service>
+        <name>John Wayne</name>
+        <number>johnWayneActorChild2</number>
+        <documentType>Person</documentType>
+        <documentTypeFromModel>Person</documentTypeFromModel>
+      </subject>
+      <object>
+        <uri>/persons/53ef7d20-4154-4ce9-952d/items/d19bf94c-53c3-4295-8e5c</uri>
+        <csid>d19bf94c-53c3-4295-8e5c</csid>
+        <service>Person</service>
+        <name>John Wayne</name>
+        <number>johnWayneActor</number>
+        <documentType>Person</documentType>
+        <documentTypeFromModel>Person</documentTypeFromModel>
+      </object>
+    </relation-list-item>
+    <relation-list-item>
+      <uri>/relations/46aa804f-53e0-4c42-aa2b</uri>
+      <csid>46aa804f-53e0-4c42-aa2b</csid>
+      <subjectCsid>6e951b58-2087-4eea-a6b1</subjectCsid>
+      <relationshipType>hasBroader</relationshipType>
+      <predicate>hasBroader</predicate>
+      <objectCsid>d19bf94c-53c3-4295-8e5c</objectCsid>
+      <subject>
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1</uri>
+        <csid>6e951b58-2087-4eea-a6b1</csid>
+        <service>Person</service>
+        <name>John Wayne</name>
+        <number>johnWayneActorChild3</number>
+        <documentType>Person</documentType>
+        <documentTypeFromModel>Person</documentTypeFromModel>
+      </subject>
+      <object>
+        <uri>/persons/53ef7d20-4154-4ce9-952d/items/d19bf94c-53c3-4295-8e5c</uri>
+        <csid>d19bf94c-53c3-4295-8e5c</csid>
+        <service>Person</service>
+        <name>John Wayne</name>
+        <number>johnWayneActor</number>
+        <documentType>Person</documentType>
+        <documentTypeFromModel>Person</documentTypeFromModel>
+      </object>
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
+
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-left.xml
new file mode 100644 (file)
index 0000000..380a435
--- /dev/null
@@ -0,0 +1,26 @@
+<document name="persons">
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <itemsInPage>2</itemsInPage>
+    <totalItems>2</totalItems>
+    <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>
+    <relation-list-item ID="1">
+      <subjectCsid>AA</subjectCsid>
+      
+      <subject>
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1</uri>
+      </subject>
+      
+    </relation-list-item>
+    <relation-list-item ID="2">
+      <subjectCsid>BB</subjectCsid>
+      
+      <subject>
+        <!-- with this missing, with have a RIGHT_ADDED situation, so test with ADD_OK
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1</uri>
+        -->
+      </subject>
+      
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/2-right.xml
new file mode 100644 (file)
index 0000000..c574fa9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="persons">
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <itemsInPage>2</itemsInPage>
+    <totalItems>2</totalItems>
+    <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>
+    <relation-list-item ID="1R">
+      <subjectCsid>AA</subjectCsid>
+      
+      <subject>
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1</uri>
+      </subject>
+
+    </relation-list-item>
+    <relation-list-item ID="2R">
+      <subjectCsid>BB</subjectCsid>
+      
+      <subject>
+        <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/6e951b58-2087-4eea-a6b1</uri>
+      </subject>
+
+      
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
+
index 56e80ff96eebb51965542405512668b7952a611a..ea2cc929be3a5f9f7ecd38f4765e04c1992926e6 100644 (file)
@@ -12,7 +12,7 @@
     <protoHostPort>http://localhost:8180</protoHostPort>\r
     \r
     <!-- legal values for dumpServiceResult=[minimal,detailed,full,auto] -->\r
-    <dump payloads="false" dumpServiceResult="full" />\r
+    <dump payloads="false" dumpServiceResult="detailed" />\r
     \r
     <auths default="admin@collectionspace.org">\r
        <auth ID="admin@collectionspace.org">YWRtaW5AY29sbGVjdGlvbnNwYWNlLm9yZzpBZG1pbmlzdHJhdG9y</auth>\r
@@ -92,6 +92,7 @@
     <run controlFile="acquisitions/acquisitions.xml" testGroup="testList" />\r
     <run controlFile="loanout/loanout.xml" testGroup="makeone" />\r
     <run controlFile="objectexit/object-exit.xml" testGroup="checkList" />\r
+    <run controlFile="person/person.xml" testGroup="postPerson" />\r
     --> \r
     \r
         \r
index 1f2cb10447720958355e9c4c5ac077fc17e0b039..3ef6018f45447ac8bd8338d86180548aa5e3a849 100644 (file)
@@ -90,9 +90,9 @@
                 <expected level="ADDOK" />\r
                 <filename>objectexit/res/oe35.res.xml</filename>\r
                 <vars>\r
-                                       <var ID="CSID">${oe35.CSID}</var>\r
+                                       <var ID="targetCSID">${oe35.CSID}</var>\r
                                </vars>\r
-                               <!-- Look for one <objectexit-list-item> with the <exitNumber> that we \r
+                               <!-- Look for one <objectexit-list-item> with the <exitNumber> that      we \r
                                     set in the POST, and see if it is in the response\r
                                -->\r
                 <startElement>//objectexit-list-item[./exitNumber='checkList-1234']</startElement>\r
index 85d4af99b8d566be26a442102e9098be96e8f044..7062c6b391f3c4d5d0f9c8b3d953097baa0e1f0b 100644 (file)
@@ -7,7 +7,7 @@
   <fieldsReturned>exitNumber|currentOwner|uri|csid</fieldsReturned>
   <objectexit-list-item>
     <exitNumber>${exitNumber}</exitNumber>
-    <uri>/objectexit/${CSID}</uri>
-    <csid>${CSID}</csid>
+    <uri>/objectexit/${targetCSID}</uri>
+    <csid>${targetCSID}</csid>
   </objectexit-list-item>
 </ns3:objectexit-common-list>
index c48d38088127e4f225ef2c310dd3eaf2f7b93970..840bbc84ebf0014c9b0cb4bb84d2047c2c4a151a 100755 (executable)
             <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
         </test>\r
         \r
+        <test ID="GETPersonPUT_siblings">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${PersonChild.CSID}?showSiblings=true</uri>\r
+        </test>\r
+         \r
+        \r
            <test ID="PersonPUT_1p">\r
             <method>PUT</method>\r
             <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID}</uri>\r
             </vars>\r
         </test>\r
         \r
+        <test ID="PersonChild3">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
+            <filename>person/persons_common.xml</filename>\r
+            <vars>\r
+               <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
+               <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+               <var ID="shortIdentifier">johnWayneActorChild3</var>\r
+            </vars>\r
+        </test>\r
+        \r
         <test ID="Person1">\r
             <method>POST</method>\r
             <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
                <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
                <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
                <var ID="shortIdentifier">johnWayneActor</var>\r
-               <var ID="CSID">${itemCSID}</var>\r
+               <!--var ID="targetCSID">${itemCSID}</var-->\r
                <var ID="parentCSID">${PersonParent.CSID}</var>\r
                <var ID="parentUri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonParent.CSID}</var>\r
                <var ID="childCSID">${PersonChild.CSID}</var>\r
                <var ID="childUri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild.CSID}</var>\r
                <var ID="child2CSID">${PersonChild2.CSID}</var>\r
                <var ID="child2Uri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild2.CSID}</var>\r
+               <var ID="child3CSID">${PersonChild3.CSID}</var>\r
+               <var ID="child3Uri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild3.CSID}</var>\r
             </vars>\r
         </test>\r
         \r
             <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
         </test>\r
         \r
+        <test ID="GETpostPerson_siblings">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${PersonChild.CSID}?showSiblings=true</uri>\r
+            <response>\r
+                               <expected level="ADDOK" />\r
+                               <filename>person/res/GETpostPerson_siblings.res.xml</filename>\r
+                               <vars>\r
+                                       <var ID="personCSID">${Person1.CSID}</var>\r
+                                       <var ID="childCSID">${PersonChild.CSID}</var>\r
+                                       <var ID="child2CSID">${PersonChild2.CSID}</var>\r
+                                       <var ID="child3CSID">${PersonChild3.CSID}</var>\r
+                               </vars>\r
+                               <startElement>/document/*[local-name()='relations-common-list']</startElement>\r
+                </response>\r
+               </test>\r
+        \r
+        <test ID="GETpostPerson_allRelations">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showAllRelations=true</uri>\r
+            <response>\r
+                               <expected level="ADDOK" />\r
+                               <filename>person/res/showAllRelations.res.xml</filename>\r
+                               <!-- NOTE: vars are referenced in showAllRelations.res.xml\r
+                                    from tests in this test group, e.g. \r
+                                    PersonParent.CSID :: ${PersonParent.CSID} \r
+                                    These vars are all in the expression context while this group is active,\r
+                                    because we hang onto all ServiceResult objects for the duration of the group,\r
+                                    and ServiceObjects keep their vars.\r
+                               -->\r
+                               <startElement>/document/*[local-name()='relations-common-list']</startElement>\r
+                        </response>\r
+                        \r
+               </test>\r
+               \r
+         <test ID="relationsGET">\r
+             <method>GET</method>\r
+             <uri>/cspace-services/relations/</uri>\r
+         </test>\r
+         \r
+         <test ID="relations_sbj">\r
+             <method>GET</method>\r
+             <uri>/cspace-services/relations?sbj=${PersonAuth1.CSID}</uri>\r
+         </test>\r
+         \r
+         <test ID="relations_obj">\r
+             <method>GET</method>\r
+             <uri>/cspace-services/relations?obj=${PersonAuth1.CSID}</uri>\r
+         </test>\r
+        \r
        </testGroup>\r
 </xmlReplay>\r
index b37fc2b5803c226dd590eea139745c0176c7a293..a76a9881e6d13253ddf9628385eaadbc0b4cac89 100755 (executable)
     <bioNote>born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive\r
     voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions.</bioNote>\r
   </ns2:persons_common>\r
-  \r
+  <!-- \r
+       WARNING: ${itemCSID} does NOT get expanded by XmlReplay. \r
+          It passes through and then the service deals with it.\r
+  -->\r
   <ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation" xmlns:ns2="http://collectionspace.org/services/jaxb">\r
     <pageNum>0</pageNum>\r
     <pageSize>40</pageSize>\r
@@ -48,7 +51,7 @@
                  <csid>${childCSID}</csid>\r
                  <uri>${childUri}</uri>\r
                  <documentType>Person</documentType>\r
-                 <name>John Wayne 2, the evil twin, child</name>\r
+                 <name>John Wayne 1, the evil twin, child</name>\r
                </subject>\r
                <object>\r
                  <csid>${itemCSID}</csid>\r
                  <name>John Wayne</name>\r
                </object>\r
        </relation-list-item>\r
+       <relation-list-item>\r
+               <predicate>hasBroader</predicate>\r
+               <subject>\r
+                 <uri>${child3Uri}</uri>\r
+                 <csid>${child3CSID}</csid>\r
+                 <documentType>Person</documentType>\r
+                 <name>John Wayne 3, the evil twin, child</name>\r
+               </subject>\r
+               <object>\r
+                 <csid>${itemCSID}</csid>\r
+                 <documentType>Person</documentType>\r
+                 <name>John Wayne</name>\r
+               </object>\r
+       </relation-list-item>\r
   </ns3:relations-common-list>\r
 </document>\r
 \r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/GETpostPerson_siblings.res.xml
new file mode 100644 (file)
index 0000000..bdb9434
--- /dev/null
@@ -0,0 +1,38 @@
+<document name="persons">
+  <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <shortIdentifier>johnWayneActorChild</shortIdentifier>
+  </ns2:persons_common>
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <itemsInPage>2</itemsInPage>
+    <totalItems>2</totalItems>
+    <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>
+    <relation-list-item>
+      <subjectCsid>${child2CSID}</subjectCsid>
+      <predicate>hasBroader</predicate>
+      <objectCsid>${personCSID}</objectCsid>
+      <subject>
+        <csid>${child2CSID}</csid>
+        <number>johnWayneActorChild2</number>
+      </subject>
+      <object>
+        <csid>${personCSID}</csid>
+        <number>johnWayneActor</number>
+      </object>
+    </relation-list-item>
+    <relation-list-item>
+      <subjectCsid>${child3CSID}</subjectCsid>
+      <predicate>hasBroader</predicate>
+      <objectCsid>${personCSID}</objectCsid>
+      <subject>
+        <csid>${child3CSID}</csid>
+        <number>johnWayneActorChild3</number>
+      </subject>
+      <object>
+        <csid>${personCSID}</csid>
+        <number>johnWayneActor</number>
+      </object>
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
+
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/showAllRelations.res.xml
new file mode 100644 (file)
index 0000000..3f05056
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="persons">  
+  <ns2:relations-common-list xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <totalItems>4</totalItems>
+    <!-- 
+    This file represents the expected response from test case
+       person.xml :: 
+    These are the vars that are available from the time Person1 is created.
+    Person1.CSID       ${Person1.CSID}
+    PersonParent.CSID  ${PersonParent.CSID}
+       PersonChild.CSID   ${PersonChild.CSID}
+       PersonChild2.CSID  ${PersonChild2.CSID}
+       PersonChild3.CSID  ${PersonChild3.CSID}
+       -->
+
+
+    <relation-list-item>
+      <subjectCsid>${Person1.CSID}</subjectCsid>
+      <objectCsid>${PersonParent.CSID}</objectCsid>
+      <predicate>hasBroader</predicate>
+      <subject>
+        <csid>${Person1.CSID}</csid>
+      </subject>
+      <object>
+        <csid>${PersonParent.CSID}</csid>
+      </object>
+    </relation-list-item>
+    
+    <relation-list-item>
+      <subjectCsid>${PersonChild.CSID}</subjectCsid>
+      <objectCsid>${Person1.CSID}</objectCsid>
+      <predicate>hasBroader</predicate>
+      <subject>
+        <csid>${PersonChild.CSID}</csid>
+      </subject>
+      <object>
+        <csid>${Person1.CSID}</csid>
+      </object>
+    </relation-list-item>
+    
+    <relation-list-item>
+      <subjectCsid>${PersonChild2.CSID}</subjectCsid>
+      <objectCsid>${Person1.CSID}</objectCsid>
+      <predicate>hasBroader</predicate>
+      
+      <subject>
+        <csid>${PersonChild2.CSID}</csid>
+      </subject>
+      <object>
+        <csid>${Person1.CSID}</csid>
+      </object>
+    </relation-list-item>
+    
+    <relation-list-item>
+      <subjectCsid>${PersonChild3.CSID}</subjectCsid>
+      <objectCsid>${Person1.CSID}</objectCsid>
+      <predicate>hasBroader</predicate>
+      <subject>
+        <csid>${PersonChild3.CSID}</csid>
+      </subject>
+      <object>
+        <csid>${Person1.CSID}</csid>
+      </object>
+    </relation-list-item>
+  </ns2:relations-common-list>
+</document>
index 50231e04de2e95abaeb2fb3ef93644a159477502..e4965263dc345c51ec271f096e426c27315013a3 100644 (file)
@@ -202,16 +202,52 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
        objectProps.remove(AuthorityItemJAXBSchema.CSID);
     }
 
-     @Override
-    public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
-            throws Exception {
+    @Override
+    public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
         MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
         super.extractAllParts(wrapDoc);
-         String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP);
-         if (!Tools.isTrue(showRelations)){
-             return;
-         }
-         String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject());
+
+        String showSiblings = ctx.getQueryParams().getFirst(CommonAPI.showSiblings_QP);
+        if (Tools.isTrue(showSiblings)) {
+            showSiblings(wrapDoc, ctx);
+            return;   // actual result is returned on ctx.addOutputPart();
+        }
+
+        String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP);
+        if (Tools.isTrue(showRelations)) {
+            showRelations(wrapDoc, ctx);
+            return;   // actual result is returned on ctx.addOutputPart();
+        }
+
+        String showAllRelations = ctx.getQueryParams().getFirst(CommonAPI.showAllRelations_QP);
+        if (Tools.isTrue(showAllRelations)) {
+            showAllRelations(wrapDoc, ctx);
+            return;   // actual result is returned on ctx.addOutputPart();
+        }
+    }
+
+    /** @return null on parent not found
+     */
+    protected String getParentCSID(String thisCSID) throws Exception {
+        String parentCSID = null;
+        try {
+            String predicate = RelationshipType.HAS_BROADER.value();
+            RelationsCommonList parentListOuter = getRelations(thisCSID, null, predicate);
+            List<RelationsCommonList.RelationListItem> parentList = parentListOuter.getRelationListItem();
+            if (parentList != null) {
+                RelationsCommonList.RelationListItem relationListItem = parentList.get(0);
+                parentCSID = relationListItem.getObjectCsid();
+            }
+            return parentCSID;
+        } catch (Exception e) {
+            logger.error("Could not find parent for this: "+thisCSID, e);
+            return null;
+        }
+    }
+
+    public void showRelations(DocumentWrapper<DocumentModel> wrapDoc,
+                                              MultipartServiceContext ctx)   throws Exception {
+        String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject());
 
          String predicate = RelationshipType.HAS_BROADER.value();
          RelationsCommonList parentListOuter = getRelations(thisCSID, null, predicate);
@@ -236,6 +272,62 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
         ctx.addOutputPart(relationsPart);
     }
 
+    public void showSiblings(DocumentWrapper<DocumentModel> wrapDoc,
+                                              MultipartServiceContext ctx)   throws Exception {
+        String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject());
+         String parentCSID = getParentCSID(thisCSID);
+        if (parentCSID == null){
+            logger.warn("~~~~~\r\n~~~~ Could not find parent for this: "+thisCSID);
+            return;
+        }
+
+         String predicate = RelationshipType.HAS_BROADER.value();
+         RelationsCommonList siblingListOuter = getRelations(null, parentCSID, predicate);
+         List<RelationsCommonList.RelationListItem> siblingList = siblingListOuter.getRelationListItem();
+
+        List<RelationsCommonList.RelationListItem> toRemoveList = newList();
+
+
+        RelationsCommonList.RelationListItem item = null;
+        for (RelationsCommonList.RelationListItem sibling : siblingList) {
+            if (thisCSID.equals(sibling.getSubjectCsid())){
+                toRemoveList.add(sibling);   //IS_A copy of the main item, i.e. I have a parent that is my parent, so I'm in the list from the above query.
+            }
+        }
+        //rather than create an immutable iterator, I'm just putting the items to remove on a separate list, then looping over that list and removing.
+        for (RelationsCommonList.RelationListItem self : toRemoveList) {
+            removeFromList(siblingList, self);
+        }
+
+        long siblingSize = siblingList.size();
+        siblingListOuter.setTotalItems(siblingSize);
+        siblingListOuter.setItemsInPage(siblingSize);
+
+        PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME,siblingListOuter);
+        ctx.addOutputPart(relationsPart);
+    }
+
+    public void showAllRelations(DocumentWrapper<DocumentModel> wrapDoc, MultipartServiceContext ctx)   throws Exception {
+        String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject());
+
+        RelationsCommonList subjectListOuter = getRelations(thisCSID, null, null);   //  nulls are wildcards:  predicate=*, and object=*
+        List<RelationsCommonList.RelationListItem> subjectList = subjectListOuter.getRelationListItem();
+
+        RelationsCommonList objectListOuter = getRelations(null, thisCSID, null);   //  nulls are wildcards:  subject=*, and predicate=*
+        List<RelationsCommonList.RelationListItem> objectList = objectListOuter.getRelationListItem();
+
+        //  MERGE LISTS:
+        subjectList.addAll(objectList);
+
+        //now subjectList actually has records BOTH where thisCSID is subject and object.
+        long relatedSize = subjectList.size();
+        subjectListOuter.setTotalItems(relatedSize);
+        subjectListOuter.setItemsInPage(relatedSize);
+
+        PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME,subjectListOuter);
+        ctx.addOutputPart(relationsPart);
+    }
+
     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
         super.fillAllParts(wrapDoc, action);
         ServiceContext ctx = getServiceContext();
index d08232e0b5882c590d2356cd9d3bff6d517cdc6a..b64d98db119c4b761b6be425379107f86a73883c 100755 (executable)
@@ -11,6 +11,9 @@ public class CommonAPI {
         return COMMON_API;\r
     }\r
     public static String AuthorityItemCSID_REPLACE="${itemCSID}";\r
+\r
     public static String showRelations_QP = "showRelations";\r
+    public static String showSiblings_QP = "showSiblings";\r
+    public static String showAllRelations_QP = "showAllRelations";\r
 }\r
 \r