java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml | 38 +++--
java/code/src/com/redhat/rhn/frontend/dto/PackageDto.java | 35 ++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java | 35 ++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java | 7
java/code/src/com/redhat/rhn/frontend/xmlrpc/packages/PackageHelper.java | 71 +++++++++-
5 files changed, 166 insertions(+), 20 deletions(-)
New commits:
commit c943e71d0160f9a622e70cf90b588d46a28aab23
Author: Justin Sherrill <jsherril(a)redhat.com>
Date: Thu Sep 2 12:57:12 2010 -0400
623447 - making errata.listPackages maintain api compatibility since it is to be backported to 5.3
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
index 985a2cd..0648804 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
@@ -1933,17 +1933,33 @@ select distinct p.evr_id as id
<mode name="package_dto_for_errata" class="com.redhat.rhn.frontend.dto.PackageDto">
<query params="eid">
- select P.id, PN.name, evr.version, evr.release, PA.label as arch_label, evr.epoch, C.checksum, CT.label as checksum_type,
- TO_CHAR(P.last_modified, 'YYYY-MM-DD HH24:MI:SS') AS last_modified
- from rhnPackage P
- inner join rhnErrataPackage EP on P.id = EP.package_id
- inner join rhnPackageEvr evr on P.evr_id = evr.id
- inner join rhnPackageName pn on P.name_id = PN.id
- inner join rhnPackageArch PA on PA.id = P.package_arch_id
- inner join rhnChecksum C on C.id = P.checksum_id
- inner join rhnChecksumType CT on CT.id = C.CHECKSUM_TYPE_ID
- where EP.errata_id = :eid
-
+ select P.id,
+ evr.epoch,
+ PN.name,
+ evr.version,
+ evr.release,
+ PA.label as arch_label,
+ P.build_host,
+ P.description,
+ C.checksum,
+ P.vendor,
+ P.summary,
+ P.cookie,
+ P.copyright,
+ P.path,
+ P.build_time,
+ P.package_size,
+ P.payload_size,
+ CT.label as checksum_type,
+ TO_CHAR(P.last_modified, 'YYYY-MM-DD HH24:MI:SS') AS last_modified
+ from rhnPackage P
+ inner join rhnErrataPackage EP on P.id = EP.package_id
+ inner join rhnPackageEvr evr on P.evr_id = evr.id
+ inner join rhnPackageName pn on P.name_id = PN.id
+ inner join rhnPackageArch PA on PA.id = P.package_arch_id
+ inner join rhnChecksum C on C.id = P.checksum_id
+ inner join rhnChecksumType CT on CT.id = C.CHECKSUM_TYPE_ID
+ where EP.errata_id = :eid
</query>
</mode>
diff --git a/java/code/src/com/redhat/rhn/frontend/dto/PackageDto.java b/java/code/src/com/redhat/rhn/frontend/dto/PackageDto.java
index 73d463d..c730c0b 100644
--- a/java/code/src/com/redhat/rhn/frontend/dto/PackageDto.java
+++ b/java/code/src/com/redhat/rhn/frontend/dto/PackageDto.java
@@ -54,6 +54,9 @@ public class PackageDto extends BaseDto {
private Blob primaryXml;
private Blob otherXml;
private Blob filelistXml;
+ private String cookie;
+ private String file;
+
// Pre-existing queries returning this as a string.
private String lastModified;
@@ -503,4 +506,36 @@ public class PackageDto extends BaseDto {
private String transformXml(Blob blobIn) {
return CompressionUtil.gzipDecompress(HibernateFactory.blobToByteArray(blobIn));
}
+
+
+ /**
+ * @return Returns the cookie.
+ */
+ public String getCookie() {
+ return cookie;
+ }
+
+
+ /**
+ * @param cookieIn The cookie to set.
+ */
+ public void setCookie(String cookieIn) {
+ cookie = cookieIn;
+ }
+
+
+ /**
+ * @return Returns the file.
+ */
+ public String getFile() {
+ return file;
+ }
+
+
+ /**
+ * @param fileIn The file to set.
+ */
+ public void setFile(String fileIn) {
+ file = fileIn;
+ }
}
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
index 3ae844e..d2dbd2f 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
@@ -44,6 +44,7 @@ import com.redhat.rhn.frontend.xmlrpc.MissingErrataAttributeException;
import com.redhat.rhn.frontend.xmlrpc.NoChannelsSelectedException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchChannelException;
import com.redhat.rhn.frontend.xmlrpc.PermissionCheckFailureException;
+import com.redhat.rhn.frontend.xmlrpc.packages.PackageHelper;
import com.redhat.rhn.manager.errata.ErrataManager;
import com.redhat.rhn.manager.errata.cache.ErrataCacheManager;
import com.redhat.rhn.manager.rhnpackage.PackageManager;
@@ -646,15 +647,43 @@ public class ErrataHandler extends BaseHandler {
* @xmlrpc.param #session_key()
* @xmlrpc.param #param("string", "advisoryName")
* @xmlrpc.returntype
- * $PackageDtoSerializer
+ * #array()
+ * #struct("package")
+ * #prop("int", "id")
+ * #prop("string", "name")
+ * #prop("string", "epoch")
+ * #prop("string", "version")
+ * #prop("string", "release")
+ * #prop("string", "arch_label")
+ * #prop_array("providing_channels", "string", "- Channel label
+ * providing this package.")
+ * #prop("string", "build_host")
+ * #prop("string", "description")
+ * #prop("string", "checksum")
+ * #prop("string", "vendor")
+ * #prop("string", "summary")
+ * #prop("string", "cookie")
+ * #prop("string", "license")
+ * #prop("string", "path")
+ * #prop("string", "build_date")
+ * #prop("string", "last_modified_date")
+ * #prop("string", "size")
+ * #prop("string", "payload_size")
+ * #struct_end()
+ * #array_end()
*/
- public List<PackageDto> listPackages(String sessionKey, String advisoryName)
+ public List<Map> listPackages(String sessionKey, String advisoryName)
throws FaultException {
// Get the logged in user
User loggedInUser = getLoggedInUser(sessionKey);
Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg());
- return PackageManager.listPackageDtosForErrata(errata);
+ List<Map> toRet = new ArrayList<Map>();
+ for (PackageDto dto : PackageManager.listPackageDtosForErrata(errata)) {
+ toRet.add(PackageHelper.packageToMap(dto, loggedInUser));
+ }
+ return toRet;
+
}
/**
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
index ffad0c0..ff03892 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
@@ -29,7 +29,6 @@ import com.redhat.rhn.domain.rhnpackage.PackageEvr;
import com.redhat.rhn.domain.rhnpackage.PackageEvrFactory;
import com.redhat.rhn.domain.rhnpackage.test.PackageTest;
import com.redhat.rhn.domain.user.User;
-import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.frontend.xmlrpc.InvalidAdvisoryReleaseException;
import com.redhat.rhn.frontend.xmlrpc.errata.ErrataHandler;
import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase;
@@ -250,14 +249,14 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
errata.addPackage(p);
ErrataManager.storeErrata(errata);
- List<PackageDto> pkgs = handler.listPackages(adminKey, errata.getAdvisory());
+ List<Map> pkgs = handler.listPackages(adminKey, errata.getAdvisory());
assertNotNull(pkgs);
assertEquals(errata.getPackages().size(), pkgs.size());
assertTrue(pkgs.size() > 0);
boolean found = false;
- for (PackageDto pkg : pkgs) {
- if (pkg.getId().equals(p.getId())) {
+ for (Map pkg : pkgs) {
+ if (pkg.get("id").equals(p.getId())) {
found = true;
}
}
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/packages/PackageHelper.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/packages/PackageHelper.java
index 26ad77d..25d3845 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/packages/PackageHelper.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/packages/PackageHelper.java
@@ -19,6 +19,7 @@ import com.redhat.rhn.common.translation.Translator;
import com.redhat.rhn.domain.rhnpackage.Package;
import com.redhat.rhn.domain.rhnpackage.PackageEvr;
import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.manager.rhnpackage.PackageManager;
import org.apache.commons.lang.StringUtils;
@@ -105,8 +106,6 @@ public class PackageHelper {
StringUtils.defaultString(pkg.getCookie()));
addEntry(pkgMap, "license",
StringUtils.defaultString(pkg.getCopyright()));
- addEntry(pkgMap, "file",
- StringUtils.defaultString(pkg.getFile()));
addEntry(pkgMap, "path",
StringUtils.defaultString(pkg.getPath()));
addEntry(pkgMap, "build_date",
@@ -123,6 +122,74 @@ public class PackageHelper {
return pkgMap;
}
+
+ /**
+ * Utility method to convert a package to a map.
+ * @param pkg The package to convert
+ * @param user The user requesting the package conversion (used in calculating the
+ * providing_channels attribute)
+ * @return Returns a map representation of a package
+ */
+ public static Map packageToMap(PackageDto pkg, User user) {
+
+ Map pkgMap = new HashMap();
+
+ // deal with the providing channels first
+ DataResult dr = PackageManager.providingChannels(user, pkg.getId());
+ List channelLabels = new ArrayList();
+ for (Iterator itr = dr.iterator(); itr.hasNext();) {
+ Map map = (Map) itr.next();
+ channelLabels.add(map.get("label"));
+ }
+ pkgMap.put("providing_channels", channelLabels);
+
+
+ addEntry(pkgMap, "name",
+ StringUtils.defaultString(pkg.getName()));
+
+ addEntry(pkgMap, "epoch", StringUtils.defaultString(pkg.getEpoch()));
+ addEntry(pkgMap, "version", StringUtils.defaultString(pkg.getVersion()));
+ addEntry(pkgMap, "release", StringUtils.defaultString(pkg.getRelease()));
+
+
+ addEntry(pkgMap, "arch_label", pkg.getArchLabel());
+
+ addEntry(pkgMap, "id", pkg.getId());
+ addEntry(pkgMap, "build_host",
+ StringUtils.defaultString(pkg.getBuildHost()));
+ addEntry(pkgMap, "description",
+ StringUtils.defaultString(pkg.getDescription()));
+ addEntry(pkgMap, "checksum",
+ StringUtils.defaultString(pkg.getChecksum()));
+ addEntry(pkgMap, "checksum_type",
+ StringUtils.defaultString(
+ pkg.getChecksumType()));
+ addEntry(pkgMap, "vendor",
+ StringUtils.defaultString(pkg.getVendor()));
+ addEntry(pkgMap, "summary",
+ StringUtils.defaultString(pkg.getSummary()));
+ addEntry(pkgMap, "cookie",
+ StringUtils.defaultString(pkg.getCookie()));
+ addEntry(pkgMap, "license",
+ StringUtils.defaultString(pkg.getCopyright()));
+ addEntry(pkgMap, "file",
+ StringUtils.defaultString(pkg.getFile()));
+ addEntry(pkgMap, "path",
+ StringUtils.defaultString(pkg.getPath()));
+ addEntry(pkgMap, "build_date",
+ Translator.date2String(pkg.getBuildTime()));
+ addEntry(pkgMap, "last_modified_date", pkg.getLastModified());
+
+ Long sz = pkg.getPackageSize();
+ addEntry(pkgMap, "size", (sz == null) ? "" : String.valueOf(sz));
+
+ sz = pkg.getPayloadSize();
+ addEntry(pkgMap, "payload_size", (sz == null) ? "" : String.valueOf(sz));
+
+ return pkgMap;
+ }
+
+
private static void addEntry(Map map, String key, Object value) {
map.put(key, value);
}