Skip to content

Commit f5c4887

Browse files
committed
wrap search result in an object
Former-commit-id: 1a0edceb57a9caab379feb2790f993121f71d410
1 parent d8e7417 commit f5c4887

File tree

3 files changed

+109
-14
lines changed

3 files changed

+109
-14
lines changed

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public static String getLatestPSUFor(String category, String version, String use
105105
* @return Document listing of all patches (full details)
106106
* @throws IOException when failed
107107
*/
108-
public static Document getAllPSUFor(String category, String version, String userId, String password) throws IOException {
108+
public static SearchResult getAllPSUFor(String category, String version, String userId, String password) throws
109+
IOException {
109110
String releaseNumber = getReleaseNumber(category, version, userId, password);
110111
return getAllPSU(category, releaseNumber, userId, password);
111112
}
@@ -221,7 +222,7 @@ public static ValidationResult validatePatches(List<String> patches, String cate
221222
* @return dom document detail about the patch
222223
* @throws IOException when something goes wrong
223224
*/
224-
public static Document getPatchDetail(String category, String version, String bugNumber, String userId, String
225+
public static SearchResult getPatchDetail(String category, String version, String bugNumber, String userId, String
225226
password)
226227
throws
227228
IOException {
@@ -233,7 +234,26 @@ public static Document getPatchDetail(String category, String version, String bu
233234
else
234235
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, bugNumber, releaseNumber);
235236

236-
return HttpUtil.getXMLContent(url, userId, password);
237+
return getSearchResult(HttpUtil.getXMLContent(url, userId, password));
238+
}
239+
240+
private static SearchResult getSearchResult(Document result) throws IOException {
241+
SearchResult returnResult = new SearchResult();
242+
returnResult.setSuccess(true);
243+
244+
try {
245+
NodeList nodeList = XPathUtil.applyXPathReturnNodeList(result, "/results/error");
246+
if (nodeList.getLength() > 0 ) {
247+
returnResult.setSuccess(false);
248+
returnResult.setErrorMessage(XPathUtil.applyXPathReturnString(result, "/results/error/message"));
249+
} else {
250+
returnResult.setResults(result);
251+
}
252+
} catch (XPathExpressionException xpe ) {
253+
throw new IOException(xpe);
254+
}
255+
256+
return returnResult;
237257

238258
}
239259

@@ -280,26 +300,27 @@ private static Document getAllReleases(String category, String userId, String p
280300
private static String getLatestPSU(String category, String release, String userId, String password) throws
281301
IOException {
282302

283-
String expression;
303+
String url;
284304
if ("wls".equalsIgnoreCase(category))
285-
expression = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
305+
url = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
286306
else
287-
expression = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
307+
url = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
288308

289-
Document allPatches = HttpUtil.getXMLContent(expression, userId, password);
309+
Document allPatches = HttpUtil.getXMLContent(url, userId, password);
290310
return savePatch(allPatches, userId, password);
291311
}
292312

293-
private static Document getAllPSU(String category, String release, String userId, String password) throws
313+
private static SearchResult getAllPSU(String category, String release, String userId, String password) throws
294314
IOException {
295315

296-
String expression;
316+
String url;
297317
if ("wls".equalsIgnoreCase(category))
298-
expression = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
318+
url = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
299319
else
300-
expression = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
320+
url = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
321+
322+
return getSearchResult(HttpUtil.getXMLContent(url, userId, password));
301323

302-
return HttpUtil.getXMLContent(expression, userId, password);
303324
}
304325

305326
private static String getPatch(String category, String version, String bugNumber, String userId, String password)
@@ -386,7 +407,6 @@ public static boolean checkCredentials(String username, String password) {
386407
}
387408
return true;
388409
}
389-
390-
410+
391411
}
392412

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.util;
2+
3+
import org.w3c.dom.Document;
4+
5+
public class SearchResult {
6+
private boolean success;
7+
private Document results;
8+
private String errorMessage;
9+
10+
/**
11+
* Get the error errorMessage
12+
*
13+
* @return
14+
*/
15+
public String getErrorMessage() {
16+
return errorMessage;
17+
}
18+
19+
/**
20+
* Set the error errorMessage
21+
*
22+
* @param errorMessage
23+
*/
24+
public void setErrorMessage(String errorMessage) {
25+
this.errorMessage = errorMessage;
26+
}
27+
28+
/**
29+
*
30+
* @return true if no conflicts ; false if there is conflicts
31+
*
32+
*/
33+
public boolean isSuccess() {
34+
return success;
35+
}
36+
37+
public void setSuccess(boolean success) {
38+
this.success = success;
39+
}
40+
41+
/**
42+
*
43+
* @return dom document detailing about the conflicts
44+
*/
45+
public Document getResults() {
46+
return results;
47+
}
48+
49+
public void setResults(Document results) {
50+
this.results = results;
51+
}
52+
53+
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ public class ValidationResult {
1010
private boolean success;
1111
private Document results;
1212

13+
private String errorMessage;
14+
15+
/**
16+
* Get the error errorMessage
17+
*
18+
* @return
19+
*/
20+
public String getErrorMessage() {
21+
return errorMessage;
22+
}
23+
24+
/**
25+
* Set the error errorMessage
26+
*
27+
* @param errorMessage
28+
*/
29+
public void setErrorMessage(String errorMessage) {
30+
this.errorMessage = errorMessage;
31+
}
32+
33+
34+
1335
/**
1436
*
1537
* @return true if no conflicts ; false if there is conflicts

0 commit comments

Comments
 (0)