From 4bf7560e3d58eb2361009a74a681a7d2ef72b004 Mon Sep 17 00:00:00 2001
From: James Bowes <jbowes@redhat.com>
Date: Sat, 20 Mar 2010 17:39:01 -0400
Subject: [PATCH] Don't use the CertificateDto for returning PEM string identity certs

---
 .../fedoraproject/candlepin/model/Consumer.java    |   17 -----------------
 .../model/ConsumerIdentityCertificate.java         |   15 +++++++++++++++
 .../candlepin/resource/ConsumerResource.java       |    6 ------
 3 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/Consumer.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/Consumer.java
index f07e38d..53021d4 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/Consumer.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/Consumer.java
@@ -33,11 +33,9 @@ import javax.persistence.Table;
 import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
-import org.fedoraproject.candlepin.dto.CertificateDto;
 import org.fedoraproject.candlepin.util.Util;
 import org.hibernate.annotations.ForeignKey;
 
@@ -79,11 +77,6 @@ public class Consumer implements Persisted {
     @Transient
     private ConsumerIdentityCertificate idCert;
     
-    // This is DTO'ish copy of the idCert so we can present PEM format strings.
-    // This never ends up in the DB.
-    @Transient
-    private CertificateDto identity;
-    
     @ManyToOne
     @JoinColumn(nullable = false)
     @ForeignKey(name = "fk_consumer_consumer_type")
@@ -184,7 +177,6 @@ public class Consumer implements Persisted {
         this.id = id;
     }
 
-    @XmlTransient
     public ConsumerIdentityCertificate getIdCert() {
         return idCert;
     }
@@ -375,13 +367,4 @@ public class Consumer implements Persisted {
         return uuid.hashCode();
     }
 
-    @XmlElement(name = "idCert")
-    public CertificateDto getIdentity() {
-        return identity;
-    }
-
-    public void setIdentity(CertificateDto identity) {
-        this.identity = identity;
-    }
-    
 }
diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerIdentityCertificate.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerIdentityCertificate.java
index 01c3ddf..34af28c 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerIdentityCertificate.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ConsumerIdentityCertificate.java
@@ -26,7 +26,9 @@ import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 
 /**
  * Represents certificate used to identify a consumer
@@ -61,6 +63,12 @@ public class ConsumerIdentityCertificate implements Persisted {
         this.serialNumber = serialNumber;
     }
 
+    @XmlElement(name = "key")
+    public String getKeyAsString() {
+        return new String(key);
+    }
+
+    @XmlTransient
     public byte[] getKey() {
         return key;
     }
@@ -69,6 +77,12 @@ public class ConsumerIdentityCertificate implements Persisted {
         this.key = key;
     }
 
+    @XmlElement(name = "pem")
+    public String getPemAsString() {
+        return new String(pem);
+    }
+
+    @XmlTransient
     public byte[] getPem() {
         return pem;
     }
@@ -77,6 +91,7 @@ public class ConsumerIdentityCertificate implements Persisted {
         this.pem = pem;
     }
 
+    @XmlTransient
     public Long getId() {
         // TODO Auto-generated method stub
         return id;
diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/resource/ConsumerResource.java b/proxy/src/main/java/org/fedoraproject/candlepin/resource/ConsumerResource.java
index a71017d..a2b0657 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/resource/ConsumerResource.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/resource/ConsumerResource.java
@@ -206,12 +206,6 @@ public class ConsumerResource {
             consumer.setIdCert(idCert);
             consumerCurator.merge(consumer);
 
-            CertificateDto certDto = new CertificateDto();
-            certDto.setSerial(idCert.getSerialNumber());
-            certDto.setKey(new String(idCert.getKey()));
-            certDto.setCert(new String(idCert.getPem()));
-            consumer.setIdentity(certDto);
-            
             return consumer;
         }
         catch (Exception e) {
-- 
1.6.6.1

