finished documentation for class FedoraDistribution and fixed formating
This commit is contained in:
parent
052ba40800
commit
6db7bc4b31
@ -17,23 +17,41 @@ import fr.packageviewer.LoggerManager;
|
|||||||
import fr.packageviewer.pack.Package;
|
import fr.packageviewer.pack.Package;
|
||||||
import fr.packageviewer.pack.SearchedPackage;
|
import fr.packageviewer.pack.SearchedPackage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class handles package requests for Fedora. All return objects in
|
||||||
|
* this class are wrapped by a CompletableFuture to ensure async workload.
|
||||||
|
*
|
||||||
|
* @author S.Djalim, R.Thomas
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
public class FedoraDistribution extends AsyncRequestsParser implements Distribution {
|
public class FedoraDistribution extends AsyncRequestsParser implements Distribution {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger object used to split debug output and the application output
|
||||||
|
*/
|
||||||
private static final Logger logger = LoggerManager.getLogger("FedoraDistribution");
|
private static final Logger logger = LoggerManager.getLogger("FedoraDistribution");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function return a package from Fedora metadata api in the form of a
|
||||||
|
* Pair Composed of a Package object, and a set of string containing the
|
||||||
|
* names of the dependecies of the package.
|
||||||
|
*
|
||||||
|
* @param packageName String, The package's exact name
|
||||||
|
* @return Pair of Package and Set of String
|
||||||
|
*/
|
||||||
protected CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
|
protected CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
|
||||||
// create a new http client
|
// create a new http client
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
// and create its url
|
// and create its url
|
||||||
String url = "https://mdapi.fedoraproject.org/rawhide/pkg/"+packageName+"";
|
String url = "https://mdapi.fedoraproject.org/rawhide/pkg/" + packageName + "";
|
||||||
HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();
|
HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();
|
||||||
|
|
||||||
CompletableFuture<Pair<Package, Set<String>>> futureResult = new CompletableFuture<>();
|
CompletableFuture<Pair<Package, Set<String>>> futureResult = new CompletableFuture<>();
|
||||||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result->{
|
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> {
|
||||||
|
|
||||||
String body = result.body();
|
String body = result.body();
|
||||||
|
|
||||||
if(body.contains("404: Not Found")) {
|
if (body.contains("404: Not Found")) {
|
||||||
futureResult.complete(null);
|
futureResult.complete(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -60,11 +78,9 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
json.getString("basename"),
|
json.getString("basename"),
|
||||||
json.getString("version"),
|
json.getString("version"),
|
||||||
json.getString("repo"),
|
json.getString("repo"),
|
||||||
json.getString("description")
|
json.getString("description")),
|
||||||
),
|
dependenciesNames));
|
||||||
dependenciesNames
|
}).exceptionally(error -> {
|
||||||
));
|
|
||||||
}).exceptionally(error->{
|
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
|
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
|
||||||
futureResult.complete(null);
|
futureResult.complete(null);
|
||||||
@ -74,6 +90,13 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
return futureResult;
|
return futureResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a package matching a pattern and return a list of packages and
|
||||||
|
* return a list of string matching this pattern.
|
||||||
|
*
|
||||||
|
* @param packageName String, the pattern to search in the repositories
|
||||||
|
* @return List of SearchedPackage objects
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<SearchedPackage>> searchPackage(String packageName) {
|
public CompletableFuture<List<SearchedPackage>> searchPackage(String packageName) {
|
||||||
|
|
||||||
@ -86,7 +109,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
|
|
||||||
CompletableFuture<List<SearchedPackage>> futureSearchedPackages = new CompletableFuture<>();
|
CompletableFuture<List<SearchedPackage>> futureSearchedPackages = new CompletableFuture<>();
|
||||||
|
|
||||||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result->{
|
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> {
|
||||||
JSONObject json = new JSONObject(result.body());
|
JSONObject json = new JSONObject(result.body());
|
||||||
|
|
||||||
List<SearchedPackage> searchedPackagesList = new ArrayList<>();
|
List<SearchedPackage> searchedPackagesList = new ArrayList<>();
|
||||||
@ -103,7 +126,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
searchResultJson.getString("description")));
|
searchResultJson.getString("description")));
|
||||||
}
|
}
|
||||||
futureSearchedPackages.complete(searchedPackagesList);
|
futureSearchedPackages.complete(searchedPackagesList);
|
||||||
}).exceptionally(error->{
|
}).exceptionally(error -> {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
futureSearchedPackages.complete(Collections.emptyList());
|
futureSearchedPackages.complete(Collections.emptyList());
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user