Coverage Report - org.kuali.maven.plugins.dnsme.mojo.ShowRecordsMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ShowRecordsMojo
0%
0/28
0%
0/2
1.333
 
 1  
 package org.kuali.maven.plugins.dnsme.mojo;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.apache.maven.plugin.MojoExecutionException;
 6  
 import org.apache.maven.plugin.MojoFailureException;
 7  
 import org.kuali.maven.plugins.dnsme.DNSMEClient;
 8  
 import org.kuali.maven.plugins.dnsme.beans.Domain;
 9  
 import org.kuali.maven.plugins.dnsme.beans.GTDLocation;
 10  
 import org.kuali.maven.plugins.dnsme.beans.Record;
 11  
 import org.kuali.maven.plugins.dnsme.beans.RecordType;
 12  
 import org.kuali.maven.plugins.dnsme.beans.Search;
 13  
 
 14  
 /**
 15  
  * Show records for the domain indicated. By default, all records are shown. Search criteria can be used to restrict the
 16  
  * display
 17  
  *
 18  
  * @author Jeff Caddel
 19  
  * @goal showrecords
 20  
  */
 21  0
 public class ShowRecordsMojo extends BaseDNSMEMojo {
 22  
     /**
 23  
      * The domain to show records for
 24  
      *
 25  
      * @parameter expression="${dnsme.domainName}"
 26  
      * @required
 27  
      */
 28  
     String domainName;
 29  
 
 30  
     /**
 31  
      * DEFAULT, US_EAST, US_WEST, ASIA
 32  
      *
 33  
      * @parameter expression="${dnsme.gtdLocation}"
 34  
      */
 35  
     GTDLocation gtdLocation;
 36  
 
 37  
     /**
 38  
      * A, CNAME, MX, NS, PTR, SRV, AAAA, HTTPRED, TXT
 39  
      *
 40  
      * @parameter expression="${dnsme.recordType}"
 41  
      */
 42  
     RecordType recordType;
 43  
 
 44  
     /**
 45  
      * Matches a single record with this exact name
 46  
      *
 47  
      * @parameter expression="${dnsme.recordName}"
 48  
      */
 49  
     String recordName;
 50  
 
 51  
     /**
 52  
      * Matches any record with a name that contains this value
 53  
      *
 54  
      * @parameter expression="${dnsme.recordNameContains}"
 55  
      */
 56  
     String recordNameContains;
 57  
 
 58  
     /**
 59  
      * Matches any record with this exact value
 60  
      *
 61  
      * @parameter expression="${dnsme.recordValue}"
 62  
      */
 63  
     String recordValue;
 64  
 
 65  
     /**
 66  
      * Matches any record with a value that contains this value
 67  
      *
 68  
      * @parameter expression="${dnsme.recordValueContains}"
 69  
      */
 70  
     String recordValueContains;
 71  
 
 72  
     @Override
 73  
     public void performTasks(DNSMEClient client) throws MojoExecutionException, MojoFailureException {
 74  0
         Search search = new Search();
 75  0
         search.setGtdLocation(gtdLocation);
 76  0
         search.setType(recordType);
 77  0
         search.setName(recordName);
 78  0
         search.setNameContains(recordNameContains);
 79  0
         search.setValue(recordValue);
 80  0
         search.setValueContains(recordValueContains);
 81  
 
 82  0
         Domain domain = client.getDomain(domainName);
 83  0
         List<Record> records = client.getRecords(domain, search);
 84  0
         getLog().info("Showing records for: " + domainName);
 85  0
         for (Record record : records) {
 86  0
             getLog().info(getCompactLog(record));
 87  
         }
 88  0
     }
 89  
 
 90  
     protected String getCompactLog(Record record) {
 91  0
         StringBuilder sb = new StringBuilder();
 92  0
         sb.append(record.getName());
 93  0
         sb.append("->" + record.getData());
 94  0
         sb.append("," + record.getType());
 95  0
         sb.append(",ttl=" + record.getTtl() + "s");
 96  0
         return sb.toString();
 97  
     }
 98  
 
 99  
     protected String getLog(Record record) {
 100  0
         StringBuilder sb = new StringBuilder();
 101  0
         sb.append("Id:" + record.getId());
 102  0
         sb.append(" Name:" + record.getName());
 103  0
         sb.append(" Value:" + record.getData());
 104  0
         sb.append(" Type:" + record.getType());
 105  0
         sb.append(" TTL:" + record.getTtl());
 106  0
         sb.append(" GTD:" + record.getGtdLocation());
 107  0
         return sb.toString();
 108  
     }
 109  
 
 110  
 }