]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
db4706fc52ca40e7894fe2fd65b5b523672f4841
[tmp/jakarta-migration.git] /
1 /**\r
2  * This document is a part of the source code and related artifacts\r
3  * for CollectionSpace, an open source collections management system\r
4  * for museums and related institutions:\r
5  *\r
6  * http://www.collectionspace.org\r
7  * http://wiki.collectionspace.org\r
8  *\r
9  * Copyright (c) 2009 Regents of the University of California\r
10  *\r
11  * Licensed under the Educational Community License (ECL), Version 2.0.\r
12  * You may not use this file except in compliance with this License.\r
13  *\r
14  * You may obtain a copy of the ECL 2.0 License at\r
15  * https://source.collectionspace.org/collection-space/LICENSE.txt\r
16  *\r
17  *  Unless required by applicable law or agreed to in writing, software\r
18  *  distributed under the License is distributed on an "AS IS" BASIS,\r
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
20  *  See the License for the specific language governing permissions and\r
21  *  limitations under the License.\r
22  */\r
23 \r
24 package org.collectionspace.services.IntegrationTests.xmlreplay;\r
25 \r
26 import org.collectionspace.services.common.Tools;\r
27 \r
28 import java.util.ArrayList;\r
29 \r
30 /**\r
31  * User: laramie\r
32  * $LastChangedRevision:  $\r
33  * $LastChangedDate:  $\r
34  */\r
35 public class TreeWalkResults extends ArrayList<TreeWalkResults.TreeWalkEntry> {\r
36 \r
37     public static class TreeWalkEntry {\r
38         public String lpath = "";\r
39         public String rpath = "";\r
40         public String ltextTrimmed = "";\r
41         public String rtextTrimmed = "";\r
42         public String message = "";\r
43         public String errmessage = "";\r
44         public static enum STATUS {INFO, MATCHED, R_MISSING, R_ADDED, DOC_ERROR, TEXT_DIFFERENT};\r
45         public STATUS status;\r
46         public String toString(){\r
47             return\r
48                  "{"\r
49                  +status.name()\r
50                  +(Tools.notEmpty(lpath) ? ", L.path:"+lpath : "")\r
51                  +(Tools.notEmpty(rpath) ? ", R.path:"+rpath : "")\r
52                  +(Tools.notEmpty(message) ? ", message:"+message : "")\r
53                  +((status != STATUS.MATCHED) && Tools.notEmpty(ltextTrimmed) ? ",\r\n    L.trimmed:"+ltextTrimmed : "")\r
54                  +((status != STATUS.MATCHED) && Tools.notEmpty(rtextTrimmed) ? ",\r\n    R.trimmed:"+rtextTrimmed : "")\r
55                  +"}";\r
56 \r
57         }\r
58     }\r
59 \r
60     public boolean hasDocErrors(){\r
61         for (TreeWalkEntry entry : this){\r
62             if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){\r
63                 return true;\r
64             }\r
65         }\r
66         return false;\r
67     }\r
68 \r
69     public String getErrorMessages(){\r
70         StringBuffer buf = new StringBuffer();\r
71         boolean first = true;\r
72         for (TreeWalkEntry entry : this){\r
73             if ( Tools.notEmpty(entry.errmessage)){\r
74                 if (first) {\r
75                     buf.append(",errors:");\r
76                 } else {\r
77                     buf.append(',');\r
78                 }\r
79                 buf.append('\''+entry.errmessage+"\'");\r
80                 first = false;\r
81             }\r
82         }\r
83         return buf.toString();\r
84     }\r
85 \r
86 \r
87 \r
88     public boolean isStrictMatch(){\r
89         for (TreeWalkEntry entry : this){\r
90             if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR){\r
91                 return false;\r
92             }\r
93             if ( !(   entry.status == TreeWalkEntry.STATUS.MATCHED\r
94                    || entry.status == TreeWalkEntry.STATUS.INFO)){\r
95                 return false;\r
96             }\r
97         }\r
98         return true;\r
99     }\r
100     public int getMismatchCount(){\r
101         int c = 0;\r
102         for (TreeWalkEntry entry : this){\r
103             if ( entry.status == TreeWalkEntry.STATUS.DOC_ERROR\r
104                 || entry.status != TreeWalkEntry.STATUS.MATCHED\r
105                 || entry.status != TreeWalkEntry.STATUS.INFO){\r
106                 c++;\r
107             }\r
108         }\r
109         return c;\r
110     }\r
111     /** For our purposes, trees match if they have the same element tree structure - no checking is done for text node changes. */\r
112     public boolean treesMatch(){\r
113         for (TreeWalkEntry entry : this){\r
114             if (entry.status == TreeWalkEntry.STATUS.DOC_ERROR\r
115                 || entry.status == TreeWalkEntry.STATUS.R_MISSING\r
116                 || entry.status == TreeWalkEntry.STATUS.R_ADDED  ){\r
117                 return false;\r
118             }\r
119         }\r
120         return true;\r
121     }\r
122 \r
123     public int countFor(TreeWalkEntry.STATUS status){\r
124         int count = 0;\r
125         for (TreeWalkEntry entry : this){\r
126             if (entry.status.equals(status)){\r
127                 count++;\r
128             }\r
129         }\r
130         return count;\r
131     }\r
132 \r
133     public String miniSummary(){\r
134         //MATCHED, INFO, R_MISSING, R_ADDED, TEXT_DIFFERENT};\r
135         StringBuffer buf = new StringBuffer();\r
136         buf.append("{");\r
137         boolean nextline = false;\r
138         for (TreeWalkEntry.STATUS st : TreeWalkEntry.STATUS.values()){\r
139             if (nextline) buf.append(',');\r
140             buf.append(st.name()+':'+countFor(st));\r
141             nextline = true;\r
142         }\r
143         buf.append(getErrorMessages());\r
144         buf.append("}");\r
145         return buf.toString();\r
146     }\r
147 \r
148     public String fullSummary(){\r
149         StringBuffer buf = new StringBuffer();\r
150         for (TreeWalkResults.TreeWalkEntry entry : this){\r
151             buf.append(entry.toString()).append("\r\n");\r
152         }\r
153         return buf.toString();\r
154     }\r
155 \r
156 \r
157     public String leftID;\r
158     public String rightID;\r
159 }