Coverage Report - org.kuali.maven.plugins.dnsme.mojo.DeleteRecordMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
DeleteRecordMojo
0%
0/26
0%
0/4
2
 
 1  
 package org.kuali.maven.plugins.dnsme.mojo;
 2  
 
 3  
 import org.apache.maven.plugin.MojoExecutionException;
 4  
 import org.apache.maven.plugin.MojoFailureException;
 5  
 import org.kuali.maven.plugins.dnsme.DNSMEClient;
 6  
 import org.kuali.maven.plugins.dnsme.beans.Domain;
 7  
 import org.kuali.maven.plugins.dnsme.beans.Record;
 8  
 
 9  
 /**
 10  
  * Delete a dns record from a domain managed by a DNSME account. Must provide either a name or an id
 11  
  *
 12  
  * @author Jeff Caddel
 13  
  * @goal deleterecord
 14  
  */
 15  0
 public class DeleteRecordMojo extends BaseDNSMEMojo {
 16  
 
 17  
     /**
 18  
      * The domain to delete a record from
 19  
      *
 20  
      * @parameter expression="${dnsme.domainName}"
 21  
      * @required
 22  
      */
 23  
     String domainName;
 24  
 
 25  
     /**
 26  
      * The name of the record to delete
 27  
      *
 28  
      * @parameter expression="${dnsme.recordName}"
 29  
      */
 30  
     String recordName;
 31  
 
 32  
     /**
 33  
      * The id of the record to delete
 34  
      *
 35  
      * @parameter expression="${dnsme.recordId}"
 36  
      */
 37  
     Integer recordId;
 38  
 
 39  
     @Override
 40  
     public void performTasks(DNSMEClient client) throws MojoExecutionException, MojoFailureException {
 41  0
         Domain domain = client.getDomain(domainName);
 42  0
         Record record = getRecord(client, domain);
 43  0
         getLog().info("Deleting a record from '" + domainName + "'");
 44  0
         getLog().info("[" + getLog(record) + "]");
 45  0
         client.deleteRecord(domain, record.getId());
 46  0
     }
 47  
 
 48  
     protected Record getRecord(DNSMEClient client, Domain domain) throws MojoExecutionException {
 49  0
         if (recordId != null) {
 50  0
             client.getRecord(domain, recordId);
 51  
         }
 52  0
         if (recordName != null) {
 53  0
             return client.getRecord(domain, recordName);
 54  
         }
 55  0
         throw new MojoExecutionException("Must supply a value for either recordName or recordId");
 56  
     }
 57  
 
 58  
     protected String getCompactLog(Record record) {
 59  0
         StringBuilder sb = new StringBuilder();
 60  0
         sb.append(record.getName());
 61  0
         sb.append("->" + record.getData());
 62  0
         sb.append("," + record.getType());
 63  0
         sb.append(",ttl=" + record.getTtl() + "s");
 64  0
         return sb.toString();
 65  
     }
 66  
 
 67  
     protected String getLog(Record record) {
 68  0
         StringBuilder sb = new StringBuilder();
 69  0
         sb.append(record.getId());
 70  0
         sb.append("," + record.getName());
 71  0
         sb.append("->" + record.getData());
 72  0
         sb.append("," + record.getType());
 73  0
         sb.append(",ttl=" + record.getTtl() + "s");
 74  0
         sb.append(",gtd=" + record.getGtdLocation());
 75  0
         return sb.toString();
 76  
     }
 77  
 
 78  
 }