3
3
package com .oracle .weblogicx .imagebuilder .builder .util ;
4
4
5
5
import java .io .File ;
6
+ import java .io .FileDescriptor ;
7
+ import java .io .FileInputStream ;
6
8
import java .io .IOException ;
9
+ import java .nio .file .Files ;
10
+ import java .nio .file .Paths ;
7
11
import java .util .ArrayList ;
8
12
import java .util .List ;
9
13
16
20
import org .apache .http .client .HttpResponseException ;
17
21
import org .w3c .dom .Document ;
18
22
import org .w3c .dom .Element ;
23
+ import org .w3c .dom .NamedNodeMap ;
19
24
import org .w3c .dom .Node ;
20
25
import org .w3c .dom .NodeList ;
21
26
24
29
import static com .oracle .weblogicx .imagebuilder .builder .api .meta .MetaDataResolver .CACHE_KEY_SEPARATOR ;
25
30
import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .CONFLICTCHECKER_URL ;
26
31
import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .FMW_PROD_ID ;
32
+ import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .GET_LSINVENTORY_URL ;
27
33
import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .LATEST_PSU_URL ;
28
34
import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .PATCH_SEARCH_URL ;
29
35
import static com .oracle .weblogicx .imagebuilder .builder .util .ARUConstants .REL_URL ;
@@ -158,6 +164,7 @@ public static List<String> getPatchesFor(String category, String version, List<S
158
164
159
165
/** Validate patches conflicts by passing a list of patches
160
166
*
167
+ * @param lsInventoryPath opatch lsinventory result path (null if non is passed)
161
168
* @param patches A list of patches number
162
169
* @param category wls or fmw
163
170
* @param version version of the prduct
@@ -167,18 +174,58 @@ public static List<String> getPatchesFor(String category, String version, List<S
167
174
* @throws IOException when failed to access the aru api
168
175
*/
169
176
170
- public static ValidationResult validatePatches (List <String > patches , String category , String version , String userId , String
171
- password ) throws IOException {
177
+ public static ValidationResult validatePatches (String lsInventoryPath , List <String > patches , String category ,
178
+ String version , String userId , String password ) throws IOException {
172
179
173
180
174
181
ValidationResult validationResult = new ValidationResult ();
175
182
validationResult .setSuccess (true );
176
183
validationResult .setResults (null );
177
184
178
- StringBuffer payload = new StringBuffer
179
- ("<conflict_check_request><platform>2000</platform><target_patch_list/>" );
180
185
String releaseNumber = getReleaseNumber (category , version , userId , password );
181
186
187
+ StringBuffer payload = new StringBuffer
188
+ ("<conflict_check_request><platform>2000</platform>" );
189
+
190
+ if (lsInventoryPath != null ) {
191
+ String inventoryContent = new String (Files .readAllBytes (Paths .get (lsInventoryPath )));
192
+ String upiPayload = "<inventory_upi_request><lsinventory_output>" + inventoryContent +
193
+ "</lsinventory_output></inventory_upi_request>" ;
194
+
195
+ // System.out.println(upiPayload);
196
+ Document upiResult = HttpUtil .postCheckConflictRequest (GET_LSINVENTORY_URL , upiPayload , userId ,
197
+ password );
198
+
199
+ XPathUtil .prettyPrint (upiResult );
200
+
201
+ try {
202
+ NodeList upi_list = XPathUtil .applyXPathReturnNodeList (upiResult ,
203
+ "/inventory_upi_response/upi" );
204
+ if (upi_list .getLength () > 0 ) {
205
+ payload .append ("<target_patch_list>" );
206
+
207
+ for ( int ii =0 ; ii < upi_list .getLength (); ii ++) {
208
+ Node upi = upi_list .item (ii );
209
+ NamedNodeMap m = upi .getAttributes ();
210
+ payload .append (String .format ("<installed_patch upi=\" %s\" />" ,
211
+ m .getNamedItem ("number" ).getNodeValue ()));
212
+
213
+ }
214
+ payload .append ("</target_patch_list>" );
215
+ }
216
+ else {
217
+ payload .append ("<target_patch_list/>" );
218
+ }
219
+ } catch (XPathExpressionException xpe ) {
220
+ throw new IOException (xpe );
221
+
222
+ }
223
+
224
+ } else {
225
+ payload .append ("<target_patch_list/>" );
226
+ }
227
+
228
+
182
229
for (String patch : patches ) {
183
230
payload .append (String .format ("<candidate_patch_list rel_id=\" %s\" >%s</conflict_check_request>" ,
184
231
releaseNumber , patch ));
@@ -429,5 +476,20 @@ public static boolean checkCredentials(String username, String password) {
429
476
return true ;
430
477
}
431
478
479
+ public static void main (String args []) throws Exception {
480
+
481
+ // public static ValidationResult validatePatches(String lsInventoryPath, List<String> patches, String category,
482
+ // String version, String userId, String password) throws IOException {
483
+
484
+ List <String > patches = new ArrayList <String >();
485
+ patches .add ("26261906" );
486
+
487
+ ARUUtil .validatePatches ("/home/johnny/Downloads//conflict-demo/myinv.txt" , null , null , null , "johnny"
488
+
489
+ "iJCPiUah7jdmLk1E" );
490
+ // ARUUtil.validatePatches(null, patches, null, null, "johnny"
491
+
492
+ // "iJCPiUah7jdmLk1E");
493
+ }
432
494
}
433
495
0 commit comments