1
- // Copyright (c) 2019, 2021 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2019, 2022 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package com .oracle .weblogic .imagetool .aru ;
5
5
6
6
import java .io .IOException ;
7
- import javax .xml .parsers .ParserConfigurationException ;
8
7
import javax .xml .xpath .XPathExpressionException ;
9
8
10
9
import com .oracle .weblogic .imagetool .util .HttpUtil ;
11
10
import com .oracle .weblogic .imagetool .util .XPathUtil ;
12
11
import org .w3c .dom .Document ;
13
- import org .w3c .dom .Element ;
14
- import org .w3c .dom .Node ;
15
12
import org .w3c .dom .NodeList ;
16
13
17
14
/**
20
17
*/
21
18
public class AruHttpHelper {
22
19
private boolean success ;
23
- private Document results ;
24
- private String errorMessage ;
25
20
private final AruProduct product ;
26
21
private final String userId ;
27
22
private final String password ;
@@ -38,7 +33,6 @@ public class AruHttpHelper {
38
33
this .userId = userId ;
39
34
this .password = password ;
40
35
this .success = true ;
41
- this .results = null ;
42
36
}
43
37
44
38
/**
@@ -50,15 +44,6 @@ public class AruHttpHelper {
50
44
AruHttpHelper (String userId , String password ) {
51
45
this (null , userId , password );
52
46
}
53
-
54
- /**
55
- * Get the error errorMessage.
56
- *
57
- * @return the search error message
58
- */
59
- String errorMessage () {
60
- return errorMessage ;
61
- }
62
47
63
48
/**
64
49
* Returns true if no conflicts ; false if there is conflicts.
@@ -68,15 +53,6 @@ boolean success() {
68
53
return success ;
69
54
}
70
55
71
- /**
72
- * Get the result object from the search.
73
- *
74
- * @return dom document detailing about the conflicts
75
- */
76
- Document results () {
77
- return results ;
78
- }
79
-
80
56
/**
81
57
* Return the user for the ARU credentials.
82
58
*
@@ -114,123 +90,12 @@ AruHttpHelper execSearch(String url) throws IOException {
114
90
return this ;
115
91
}
116
92
117
- /**
118
- * Call ARU via the HTTPUtil methods and check the result for conflict messages about
119
- * patches not compatible.
120
- *
121
- * @param url to the ARU conflict patch numbers site.
122
- * @param payload XML string containing the patch number being validated
123
- * @return this instance of encapsulation of ARU search information
124
- * @throws IOException if the ARU request is not successful
125
- */
126
- AruHttpHelper execValidation (String url , String payload ) throws IOException {
127
- results = HttpUtil .postCheckConflictRequest (url , payload , userId , password );
128
- return this ;
129
- }
130
-
131
- /**
132
- * Check the resulting document from the execValidation for conflicts.
133
- *
134
- * @return this instance of the encapsulation of the validated results
135
- * @throws IOException if not able to parse the returned Document for conflict messages
136
- */
137
- AruHttpHelper validation () throws IOException {
138
- NodeList conflictSets ;
139
- try {
140
- conflictSets = XPathUtil .nodelist (results (),
141
- "/conflict_check/conflict_sets/set" );
142
- } catch (XPathExpressionException xee ) {
143
- throw new IOException (xee );
144
- }
145
- if (conflictSets .getLength () > 0 ) {
146
- try {
147
- success = false ;
148
- String expression = "/conflict_check/conflict_sets/set/merge_patches" ;
149
-
150
- NodeList nodeList = XPathUtil .nodelist (results (), expression );
151
-
152
- createResultDocument (nodeList );
153
-
154
- errorMessage = parsePatchValidationError ();
155
-
156
- } catch (XPathExpressionException xpe ) {
157
- throw new IOException (xpe );
158
- }
159
- return this ;
160
- }
161
- return this ;
162
- }
163
-
164
- /**
165
- * Create an XML document from an XML NodeList.
166
- * @param nodeList partial XML document
167
- * @return a Document based on the NodeList provided
168
- * @throws IOException if an XML parser exception occurs trying to build the document
169
- */
170
- AruHttpHelper createResultDocument (NodeList nodeList ) throws IOException {
171
- try {
172
- Document doc = HttpUtil .documentBuilder ().newDocument ();
173
- Element element = doc .createElement ("results" );
174
-
175
- for (int i = 0 ; i < nodeList .getLength (); i ++) {
176
- Node n = nodeList .item (i );
177
- Node copyNode = doc .importNode (n , true );
178
-
179
- if (n instanceof Element ) {
180
- element .appendChild (copyNode );
181
- }
182
- }
183
-
184
- doc .appendChild (element );
185
-
186
- results = doc ;
187
- } catch (ParserConfigurationException pce ) {
188
- throw new IOException (pce );
189
- }
190
- return this ;
191
- }
192
-
193
- /**
194
- * Parses the patch conflict check result and returns a string of patch conflicts grouped by each conflict.
195
- *
196
- * @return String
197
- */
198
- private String parsePatchValidationError () {
199
- StringBuilder stringBuilder = new StringBuilder ();
200
- Node conflictsResultNode = results ();
201
- if (conflictsResultNode != null ) {
202
- try {
203
- NodeList patchSets = XPathUtil .nodelist (conflictsResultNode , "//merge_patches" );
204
- stringBuilder .append ("patch conflicts detected: " );
205
- for (int i = 0 ; i < patchSets .getLength (); i ++) {
206
- stringBuilder .append ("[" );
207
- NodeList bugNumbers = XPathUtil .nodelist (patchSets .item (i ), "patch/bug/number"
208
- + "/text()" );
209
- for (int j = 0 ; j < bugNumbers .getLength (); j ++) {
210
- stringBuilder .append (bugNumbers .item (j ).getNodeValue ());
211
- stringBuilder .append ("," );
212
- }
213
- if (bugNumbers .getLength () > 0 ) {
214
- stringBuilder .deleteCharAt (stringBuilder .length () - 1 );
215
- }
216
- stringBuilder .append ("]" );
217
- }
218
- } catch (XPathExpressionException e ) {
219
- return "Exception occurred in parsePatchValidationError: " + e .getMessage ();
220
- }
221
- }
222
- return stringBuilder .toString ();
223
- }
224
-
225
93
private void searchResult (Document result ) throws IOException {
226
94
success = true ;
227
95
try {
228
96
NodeList nodeList = XPathUtil .nodelist (result , "/results/error" );
229
97
if (nodeList .getLength () > 0 ) {
230
98
success = false ;
231
- errorMessage = XPathUtil .string (result , "/results/error/message" );
232
- } else {
233
- results = result ;
234
99
}
235
100
} catch (XPathExpressionException xpe ) {
236
101
throw new IOException (xpe );
0 commit comments