4
4
5
5
import java .io .File ;
6
6
import java .io .IOException ;
7
+ import java .nio .file .Files ;
8
+ import java .nio .file .Paths ;
7
9
import java .util .ArrayList ;
8
10
import java .util .List ;
9
11
16
18
import org .apache .http .client .HttpResponseException ;
17
19
import org .w3c .dom .Document ;
18
20
import org .w3c .dom .Element ;
21
+ import org .w3c .dom .NamedNodeMap ;
19
22
import org .w3c .dom .Node ;
20
23
import org .w3c .dom .NodeList ;
21
24
24
27
import static com .oracle .weblogicx .imagebuilder .builder .api .meta .MetaDataResolver .CACHE_KEY_SEPARATOR ;
25
28
import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .CONFLICTCHECKER_URL ;
26
29
import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .FMW_PROD_ID ;
30
+ import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .GET_LSINVENTORY_URL ;
27
31
import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .LATEST_PSU_URL ;
28
32
import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .PATCH_SEARCH_URL ;
29
33
import static com .oracle .weblogicx .imagebuilder .builder .util .Constants .REL_URL ;
@@ -158,6 +162,7 @@ public static List<String> getPatchesFor(String category, String version, List<S
158
162
159
163
/** Validate patches conflicts by passing a list of patches
160
164
*
165
+ * @param lsInventoryPath opatch lsinventory result path (null if non is passed)
161
166
* @param patches A list of patches number
162
167
* @param category wls or fmw
163
168
* @param version version of the prduct
@@ -167,18 +172,55 @@ public static List<String> getPatchesFor(String category, String version, List<S
167
172
* @throws IOException when failed to access the aru api
168
173
*/
169
174
170
- public static ValidationResult validatePatches (List <String > patches , String category , String version , String userId , String
171
- password ) throws IOException {
175
+ public static ValidationResult validatePatches (String lsInventoryPath , List <String > patches , String category ,
176
+ String version , String userId , String password ) throws IOException {
172
177
173
178
174
179
ValidationResult validationResult = new ValidationResult ();
175
180
validationResult .setSuccess (true );
176
181
validationResult .setResults (null );
177
182
178
- StringBuffer payload = new StringBuffer
179
- ("<conflict_check_request><platform>2000</platform><target_patch_list/>" );
180
183
String releaseNumber = getReleaseNumber (category , version , userId , password );
181
184
185
+ StringBuffer payload = new StringBuffer
186
+ ("<conflict_check_request><platform>2000</platform>" );
187
+
188
+ if (lsInventoryPath != null ) {
189
+ String inventoryContent = new String (Files .readAllBytes (Paths .get (lsInventoryPath )));
190
+ String upiPayload = "<inventory_upi_request><lsinventory_output>" + inventoryContent +
191
+ "</lsinventory_output></inventory_upi_request>" ;
192
+
193
+ Document upiResult = HttpUtil .postCheckConflictRequest (GET_LSINVENTORY_URL , upiPayload , userId ,
194
+ password );
195
+
196
+ try {
197
+ NodeList upi_list = XPathUtil .applyXPathReturnNodeList (upiResult ,
198
+ "/inventory_upi_response/upi" );
199
+ if (upi_list .getLength () > 0 ) {
200
+ payload .append ("<target_patch_list>" );
201
+
202
+ for ( int ii =0 ; ii < upi_list .getLength (); ii ++) {
203
+ Node upi = upi_list .item (ii );
204
+ NamedNodeMap m = upi .getAttributes ();
205
+ payload .append (String .format ("<installed_patch upi=\" %s\" />" ,
206
+ m .getNamedItem ("number" ).getNodeValue ()));
207
+
208
+ }
209
+ payload .append ("</target_patch_list>" );
210
+ }
211
+ else {
212
+ payload .append ("<target_patch_list/>" );
213
+ }
214
+ } catch (XPathExpressionException xpe ) {
215
+ throw new IOException (xpe );
216
+
217
+ }
218
+
219
+ } else {
220
+ payload .append ("<target_patch_list/>" );
221
+ }
222
+
223
+
182
224
for (String patch : patches ) {
183
225
payload .append (String .format ("<candidate_patch_list rel_id=\" %s\" >%s</conflict_check_request>" ,
184
226
releaseNumber , patch ));
0 commit comments