10
10
11
11
import org .w3c .dom .Document ;
12
12
import org .w3c .dom .Element ;
13
+ import org .w3c .dom .Node ;
13
14
import org .w3c .dom .NodeList ;
14
15
15
16
public class ARUUtil {
16
17
18
+ /**
19
+ * Return All WLS releases information
20
+ *
21
+ * @param userId userid for support account
22
+ * @param password password for support account
23
+ * @throws IOException when failed to access the aru api
24
+ */
17
25
18
- public void getAllWLSReleases (String userId , String password ) throws IOException {
19
- getAllReleases ("wls" , userId , password );
26
+ public static Document getAllWLSReleases (String userId , String password ) throws IOException {
27
+ return getAllReleases ("wls" , userId , password );
20
28
}
21
29
22
- public void getLatestWLSPatches (String release , String userId , String password ) throws IOException {
30
+ /**
31
+ * Return release number of a WLS release by version
32
+ *
33
+ * @param version wls version 12.2.1.3.0 etc ...
34
+ * @param userId user id for support account
35
+ * @param password password for support account
36
+ * @return release number or empty string if not found
37
+ * @throws IOException when failed to access the aru api
38
+ */
39
+ private static String getWLSReleaseNumber (String version , String userId , String password ) throws
40
+ IOException {
41
+ return getReleaseNumber ("wls" , version , userId , password );
42
+ }
43
+
44
+ /**
45
+ * Return release number of a FMW release by version
46
+ *
47
+ * @param version wls version 12.2.1.3.0 etc ...
48
+ * @param userId user id for support account
49
+ * @param password password for support account
50
+ * @return release number or empty string if not found
51
+ * @throws IOException when failed to access the aru api
52
+ */
53
+ private static String getFMWReleaseNumber (String version , String userId , String password ) throws
54
+ IOException {
55
+ return getReleaseNumber ("fmw" , version , userId , password );
56
+ }
57
+
58
+
59
+ /**
60
+ * Return All FMW releases information
61
+ *
62
+ * @param userId userid for support account
63
+ * @param password password for support account
64
+ * @throws IOException when failed to access the aru api
65
+ */
66
+ public static void getAllFMWReleases (String userId , String password ) throws IOException {
67
+ getAllReleases ("fmw" , userId , password );
68
+ }
69
+
70
+ /**
71
+ * Download the latest WLS patches(PSU) for the release
72
+ *
73
+ * @param release release number
74
+ * @param userId userid for support account
75
+ * @param password password for support account
76
+ * @throws IOException when failed to access the aru api
77
+ */
78
+ public static void getLatestWLSPatches (String release , String userId , String password ) throws IOException {
23
79
getLatestPSU ("wls" , release , userId , password );
24
80
}
25
81
26
- public void getPatches (String category , List <String > patches , String userId , String password ) throws IOException {
82
+ /**
83
+ * Download the latest FMW patches(PSU) for the release
84
+ *
85
+ * @param release release number
86
+ * @param userId userid for support account
87
+ * @param password password for support account
88
+ * @throws IOException when failed to access the aru api
89
+ */
90
+ public static void getLatestFMWPatches (String release , String userId , String password ) throws IOException {
91
+ getLatestPSU ("fmw" , release , userId , password );
92
+ }
93
+
94
+ /**
95
+ * Download a list of WLS patches
96
+ *
97
+ * @param patches A list of patches number
98
+ * @param userId userid for support account
99
+ * @param password password for support account
100
+ * @throws IOException when failed to access the aru api
101
+ */
102
+ public static void getWLSPatches (List <String > patches , String userId , String password ) throws
103
+ IOException {
27
104
for (String patch : patches )
28
105
getPatch ("wls" , patch , userId , password );
29
106
}
30
107
31
- public void validatePatches (List <String > patches , String category , String version ) {
108
+ /**
109
+ * Download a list of FMW patches
110
+ *
111
+ * @param patches A list of patches number
112
+ * @param userId userid for support account
113
+ * @param password password for support account
114
+ * @throws IOException when failed to access the aru api
115
+ */
116
+ public static void getFMWPatches (String category , List <String > patches , String userId , String password ) throws
117
+ IOException {
118
+ for (String patch : patches )
119
+ getPatch ("fmw" , patch , userId , password );
120
+ }
121
+
122
+ /**
123
+ *
124
+ * @param patches A list of patches number
125
+ * @param category
126
+ * @param version
127
+ * @param userId userid for support account
128
+ * @param password password for support account
129
+ * @throws IOException when failed to access the aru api
130
+ */
131
+
132
+ public static void validatePatches (List <String > patches , String category , String version , String userId , String
133
+ password ) throws IOException {
32
134
33
135
// TODO
34
136
@@ -52,7 +154,7 @@ public void validatePatches(List<String> patches, String category, String versio
52
154
53
155
}
54
156
55
- private Document getAllReleases (String category , String userId , String password ) throws IOException {
157
+ private static Document getAllReleases (String category , String userId , String password ) throws IOException {
56
158
57
159
//HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}'
58
160
// "https://updates.oracle.com/Orion/Services/metadata?table=aru_releases" -o allarus.xml)
@@ -64,23 +166,28 @@ private Document getAllReleases(String category, String userId, String password)
64
166
65
167
String expression ;
66
168
67
- if ("wls" .equalsIgnoreCase ("wls" )) {
169
+ if ("wls" .equalsIgnoreCase (category )) {
68
170
expression = "/results/release[starts-with(text(), 'Oracle WebLogic Server')]" ;
69
171
} else {
70
- expression = "" ;
172
+ expression = "/results/release[starts-with(text(), 'Fusion Middleware Upgrade')] " ;
71
173
}
72
174
NodeList nodeList = XPathUtil .applyXPathReturnNodeList (allReleases , expression );
73
175
74
176
DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
75
177
DocumentBuilder builder = dbf .newDocumentBuilder ();
76
178
Document doc = builder .newDocument ();
77
179
Element element = doc .createElement ("results" );
78
- doc .appendChild (element );
79
180
80
181
for (int i = 0 ; i < nodeList .getLength (); i ++) {
81
- element .appendChild (nodeList .item (0 ));
182
+ Node n = nodeList .item (i );
183
+ Node copyNode = doc .importNode (n , true );
184
+
185
+ if (n instanceof Element )
186
+ element .appendChild (copyNode );
82
187
}
83
188
189
+ doc .appendChild (element );
190
+ XPathUtil .prettyPrint (doc );
84
191
85
192
return doc ;
86
193
@@ -91,32 +198,44 @@ private Document getAllReleases(String category, String userId, String password)
91
198
92
199
}
93
200
94
- private void getLatestPSU (String category , String release , String userId , String password ) throws IOException {
201
+ private static void getLatestPSU (String category , String release , String userId , String password ) throws IOException {
95
202
96
- // HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
203
+ String xpath = "https://updates.oracle"
204
+ + ".com/Orion/Services/search?product=%s&release=%s" ;
205
+ String expression ;
206
+ if ("wls" .equalsIgnoreCase (category ))
207
+ expression = String .format (xpath , "15991" , release );
208
+ else
209
+ expression = String .format (xpath , "27638" , release );
97
210
98
-
99
- Document allPatches = HttpUtil .getXMLContent ("https://updates.oracle"
100
- + ".com/Orion/Services/search?product=15991&release=" + release , userId , password );
211
+ Document allPatches = HttpUtil .getXMLContent (expression , userId , password );
101
212
102
213
savepatch (allPatches , userId , password );
103
214
}
104
215
105
- private void getPatch (String category , String patchNumber , String userId , String password ) throws IOException {
216
+ private static void getPatch (String category , String patchNumber , String userId , String password ) throws
217
+ IOException {
106
218
107
219
// HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
108
220
221
+ String urlFormat = "https://updates.oracle"
222
+ + ".com/Orion/Services/search?product=%s&bug=%s" ;
223
+ String url ;
224
+
225
+ if ("wls" .equalsIgnoreCase (category ))
226
+ url = String .format (urlFormat , "15991" , patchNumber );
227
+ else
228
+ url = String .format (urlFormat , "27638" , patchNumber );
109
229
110
- Document allPatches = HttpUtil .getXMLContent ("https://updates.oracle"
111
- + ".com/Orion/Services/search?product=15991&bug=" + patchNumber , userId , password );
230
+ Document allPatches = HttpUtil .getXMLContent (url , userId , password );
112
231
113
232
savepatch (allPatches , userId , password );
114
233
115
234
116
235
117
236
}
118
237
119
- private void savepatch (Document allPatches , String userId , String password ) throws IOException {
238
+ private static void savepatch (Document allPatches , String userId , String password ) throws IOException {
120
239
try {
121
240
122
241
// TODO: needs to make sure there is one and some filtering if not sorting
@@ -144,6 +263,23 @@ private void savepatch(Document allPatches, String userId, String password) thro
144
263
145
264
}
146
265
266
+ private static String getReleaseNumber (String category , String version , String userId , String password ) throws
267
+ IOException {
268
+ Document allReleases = getAllReleases (category , userId , password );
269
+
270
+ String expression = String .format ("string(/results/release[@name = '%s']/@id)" , version );
271
+ try {
272
+ return XPathUtil .applyXPathReturnString (allReleases , expression );
273
+ } catch (XPathExpressionException xpe ) {
274
+ throw new IOException (xpe );
275
+ }
276
+
277
+
278
+ }
279
+
280
+ public static void main (String args []) throws Exception {
281
+ String release =
ARUUtil .
getWLSReleaseNumber (
"121.2.1.3.0" ,
"[email protected] " ,
"iJCPiUah7jdmLk1E" );
282
+ }
147
283
148
284
149
285
}
0 commit comments