Skip to content

Commit 42e4dcb

Browse files
committed
check in conflict checks for now
Former-commit-id: 3cb5525525af11c5f65f69a35997f6d99678722b
1 parent 5dd5142 commit 42e4dcb

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/ARUUtil.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static List<String> getPatchesFor(String category, String version, List<S
120120
}
121121
return results;
122122
}
123+
123124
/**
124125
*
125126
* @param patches A list of patches number
@@ -130,17 +131,30 @@ public static List<String> getPatchesFor(String category, String version, List<S
130131
* @throws IOException when failed to access the aru api
131132
*/
132133

133-
public static void validatePatches(List<String> patches, String category, String version, String userId, String
134+
public static boolean validatePatches(List<String> patches, String category, String version, String userId, String
134135
password) throws IOException {
135136

136-
// TODO
137+
StringBuffer payload = new StringBuffer
138+
("<conflict_check_request><platform>2000</platform><target_patch_list/>");
139+
String releaseNumber = getReleaseNumber(category, version, userId, password);
137140

138-
// find the release number first based on the version
139-
// build the xml
140-
//String payload = null;
141+
for (String patch : patches) {
142+
payload.append(String.format("<candidate_patch_list rel_id=\"%s\">%s</conflict_check_request>",
143+
releaseNumber, patch));
144+
}
145+
payload.append("</conflict_check_request>");
141146

142-
//HttpUtil.checkConflicts(CONFLICTCHECKER_URL, payload, userId, password);
147+
Document result = HttpUtil.checkConflicts(CONFLICTCHECKER_URL, payload.toString(), userId, password);
143148

149+
try {
150+
NodeList conflictSets = XPathUtil.applyXPathReturnNodeList(result, "/conflict_sets");
151+
if (conflictSets.getLength() == 0)
152+
return true;
153+
} catch (XPathExpressionException xpe) {
154+
throw new IOException(xpe);
155+
156+
}
157+
return false;
144158
}
145159

146160
private static Document getAllReleases(String category, String userId, String password) throws IOException {

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/HttpUtil.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static void downloadFile(String url, String fileName, UserSession userSes
163163
* @throws IOException
164164
*/
165165

166-
public static String checkConflicts(String url, String payload, String username, String password)
166+
public static Document checkConflicts(String url, String payload, String username, String password)
167167
throws IOException {
168168
RequestConfig.Builder config = RequestConfig.custom();
169169
config.setCircularRedirectsAllowed(true);
@@ -184,11 +184,25 @@ public static String checkConflicts(String url, String payload, String username,
184184
.addPart(FormBodyPartBuilder.create("request_xml", new StringBody(payload, ContentType.TEXT_PLAIN)).build())
185185
.build();
186186

187-
String response =
187+
String xmlString =
188188
httpExecutor.execute(Request.Post(url).connectTimeout(30000).socketTimeout(30000).body(entity))
189189
.returnContent().asString();
190190

191-
return response;
191+
try {
192+
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
193+
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
194+
InputSource is = new InputSource(new StringReader(xmlString));
195+
Document doc = docBuilder.parse(is);
196+
// XPathUtil.prettyPrint(doc);
197+
return doc;
198+
} catch (ParserConfigurationException ex) {
199+
throw new IllegalStateException(ex);
200+
} catch (SAXException ex) {
201+
throw new ClientProtocolException("Malformed XML document", ex);
202+
} catch (Exception g) {
203+
throw new IllegalStateException(g);
204+
}
205+
192206
}
193207

194208

0 commit comments

Comments
 (0)