Skip to content

Commit 6f5c058

Browse files
committed
Add CacheDownloadUtil and fixed some xpath
Former-commit-id: 128f5c42fb01a8453edd8ba978a90bfbeec7c6d0
1 parent 209b149 commit 6f5c058

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.oracle.weblogicx.imagebuilder.builder.util;
22

3+
import java.io.File;
34
import java.io.IOException;
45
import java.util.List;
56

@@ -75,7 +76,7 @@ public static void getAllFMWReleases(String userId, String password) throws IOEx
7576
* @param password password for support account
7677
* @throws IOException when failed to access the aru api
7778
*/
78-
public static void getLatestWLSPatches(String release, String userId, String password) throws IOException {
79+
public static void getLatestWLSPSU(String release, String userId, String password) throws IOException {
7980
getLatestPSU("wls", release, userId, password);
8081
}
8182

@@ -87,7 +88,7 @@ public static void getLatestWLSPatches(String release, String userId, String pas
8788
* @param password password for support account
8889
* @throws IOException when failed to access the aru api
8990
*/
90-
public static void getLatestFMWPatches(String release, String userId, String password) throws IOException {
91+
public static void getLatestFMWPSU(String release, String userId, String password) throws IOException {
9192
getLatestPSU("fmw", release, userId, password);
9293
}
9394

@@ -210,7 +211,8 @@ private static void getLatestPSU(String category, String release, String userId
210211

211212
Document allPatches = HttpUtil.getXMLContent(expression, userId, password);
212213

213-
savepatch(allPatches, userId, password);
214+
//XPathUtil.prettyPrint(allPatches);
215+
savePatch(allPatches, userId, password);
214216
}
215217

216218
private static void getPatch(String category, String patchNumber, String userId, String password) throws
@@ -229,33 +231,38 @@ private static void getPatch(String category, String patchNumber, String userId,
229231

230232
Document allPatches = HttpUtil.getXMLContent(url, userId, password);
231233

232-
savepatch(allPatches, userId, password);
234+
savePatch(allPatches, userId, password);
233235

234236

235237

236238
}
237239

238-
private static void savepatch(Document allPatches, String userId, String password) throws IOException {
240+
private static void savePatch(Document allPatches, String userId, String password) throws IOException {
239241
try {
240242

241243
// TODO: needs to make sure there is one and some filtering if not sorting
242244

243245
String downLoadLink = XPathUtil.applyXPathReturnString(allPatches, "string"
244246
+ "(/results/patch[1]/files/file/download_url/text())");
245247

246-
String doloadHost = XPathUtil.applyXPathReturnString(allPatches, "string"
248+
String downLoadHost = XPathUtil.applyXPathReturnString(allPatches, "string"
247249
+ "(/results/patch[1]/files/file/download_url/@host)");
248250

249-
String bugname = XPathUtil.applyXPathReturnString(allPatches, "string"
250-
+ "(/results/patch[1]/name");
251+
String bugName = XPathUtil.applyXPathReturnString(allPatches, "/results/patch[1]/name");
251252

252-
// TODO find the download location
253253

254-
String fileName = bugname + ".zip";
254+
int index = downLoadLink.indexOf("patch_file=");
255255

256-
HttpUtil.downloadFile(doloadHost+downLoadLink, fileName, userId, password);
256+
if (index > 0) {
257+
String fileName = CacheDownLoadUtil.getDownloadRoot() + File.separator + downLoadLink.substring
258+
(index+"patch_file=".length());
257259

258-
// TODO need method to update the cache data table ?
260+
if (!CacheDownLoadUtil.existsInCache(bugName, fileName)) {
261+
HttpUtil.downloadFile(downLoadHost+downLoadLink, fileName, userId, password);
262+
}
263+
264+
CacheDownLoadUtil.updateTableOfContext(bugName, fileName);
265+
}
259266

260267
} catch (XPathExpressionException xpe) {
261268
throw new IOException(xpe);
@@ -278,7 +285,7 @@ private static String getReleaseNumber(String category, String version, String u
278285
}
279286

280287
public static void main(String args[]) throws Exception {
281-
String release = ARUUtil.getWLSReleaseNumber("121.2.1.3.0","[email protected]", "iJCPiUah7jdmLk1E");
288+
ARUUtil.getLatestWLSPSU("600000000073715","[email protected]", "iJCPiUah7jdmLk1E");
282289
}
283290

284291

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.util;
2+
3+
import java.io.File;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
8+
public class CacheDownLoadUtil {
9+
public static String getDownloadRoot() {
10+
return "/tmp";
11+
}
12+
13+
public static boolean existsInCache(String bugNumber, String fileName) {
14+
String fullPatchName = getDownloadRoot() + File.separator + fileName;
15+
Path path = Paths.get(fullPatchName);
16+
if (Files.exists(path))
17+
return true;
18+
else
19+
System.out.println("already downloaded");
20+
21+
return false;
22+
}
23+
24+
public static void updateTableOfContext(String bugNumber, String fileName) {}
25+
26+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public static Document getXMLContent(String url, String username, String passwor
7979
* Downlod a file from the url
8080
*
8181
* @param url url of the aru server
82-
* @param destination full path to save the file
82+
* @param fileName full path to save the file
8383
* @param username userid for support account
8484
* @param password password for support account
8585
* @throws IOException when it fails to access the url
8686
*/
8787

88-
public static void downloadFile(String url, String destination, String username, String password)
88+
public static void downloadFile(String url, String fileName, String username, String password)
8989
throws IOException {
9090
RequestConfig.Builder config = RequestConfig.custom();
9191
config.setCircularRedirectsAllowed(true);
@@ -103,7 +103,7 @@ public static void downloadFile(String url, String destination, String username,
103103
httpExecutor.use(cookieStore);
104104

105105
httpExecutor.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
106-
.saveContent(new File(destination));
106+
.saveContent(new File(fileName));
107107

108108
}
109109

@@ -117,7 +117,7 @@ public static void downloadFile(String url, String destination, String username,
117117
* @return
118118
* @throws IOException
119119
*/
120-
120+
121121
public static String checkConflicts(String url, String payload, String username, String password)
122122
throws IOException {
123123
RequestConfig.Builder config = RequestConfig.custom();

0 commit comments

Comments
 (0)