Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.testfabrik.webmate.javasdk.packagemgmt;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Optional;
Expand All @@ -15,6 +16,8 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -37,6 +40,8 @@ private static class PackageMgmtApiClient extends WebmateApiClient {

private final static UriTemplate getPackageTemplate = new UriTemplate("/package/packages/${packageId}");

private final static UriTemplate getPackagesForProjectTemplate = new UriTemplate("/projects/${projectId}/packages/full");

private final static UriTemplate deletePackageTemplate = new UriTemplate("/package/packages/${packageId}");


Expand Down Expand Up @@ -98,16 +103,26 @@ public Package getPackage(PackageId packageId) {
throw new WebmateApiClientException("Could not get package. Got no response");
}

Package aPackage;
return buildPackageFromResponse(r);
}

public Collection<Package> getPackagesForProject(ProjectId projectId) {
Optional<HttpResponse> r = sendGET(getPackagesForProjectTemplate, ImmutableMap.of("projectId", projectId.toString())).getOptHttpResponse();

if (!r.isPresent()) {
throw new WebmateApiClientException("Could not get packages for project. Got no response");
}

List<Package> packages;
try {
String packageJson = EntityUtils.toString(r.get().getEntity());
String packagesJson = EntityUtils.toString(r.get().getEntity());
ObjectMapper pMapper = JacksonMapper.getInstance();
pMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
aPackage = pMapper.readValue(packageJson, Package.class);
packages = pMapper.readValue(packagesJson, new TypeReference<List<Package>>() {});
} catch (IOException e) {
throw new WebmateApiClientException("Error reading Package data: " + e.getMessage(), e);
}
return aPackage;
return packages;
}

public Package waitForPackage(PackageId packageId) {
Expand Down Expand Up @@ -203,10 +218,20 @@ public Package updatePackage(PackageId packageId, BlobId blobId, String packageN
* @param packageId Id of the package
* @return Package information
*/
public Package getPackage(PackageId packageId){
public Package getPackage(PackageId packageId) {
return this.apiClient.getPackage(packageId);
}

/**
* Get all packages information for a given ProjectId.
*
* @param projectId Id of the project to get packages for
* @return List of Package information
*/
public Collection<Package> getPackagesForProject(ProjectId projectId) {
return this.apiClient.getPackagesForProject(projectId);
}

/**
* Delete a package with a given PackageId
*
Expand Down