1 37 package net.sourceforge.cruisecontrol.publishers.sfee; 38 39 import com.vasoftware.sf.soap42.types.SoapNamedValues; 40 import com.vasoftware.sf.soap42.webservices.ClientSoapStubFactory; 41 import com.vasoftware.sf.soap42.webservices.sfmain.ISourceForgeSoap; 42 import com.vasoftware.sf.soap42.webservices.tracker.ITrackerAppSoap; 43 import com.vasoftware.sf.soap42.webservices.tracker.TrackerSoapList; 44 import com.vasoftware.sf.soap42.webservices.tracker.TrackerSoapRow; 45 import net.sourceforge.cruisecontrol.CruiseControlException; 46 import net.sourceforge.cruisecontrol.util.ValidationHelper; 47 import net.sourceforge.cruisecontrol.util.XPathAwareChild; 48 import net.sourceforge.cruisecontrol.util.NamedXPathAwareChild; 49 import org.jdom.Element; 50 51 import java.rmi.RemoteException ; 52 import java.util.ArrayList ; 53 import java.util.Collection ; 54 import java.util.Iterator ; 55 56 57 65 public class SfeeTrackerPublisher extends SfeePublisher { 66 67 private String trackerName; 68 private final Collection fields = new ArrayList (); 69 private String projectName; 70 private XPathAwareChild title; 71 private XPathAwareChild description; 72 private XPathAwareChild status; 73 74 public void setTrackerName(String name) { 75 this.trackerName = name; 76 } 77 78 public void setProjectName(String projectName) { 79 this.projectName = projectName; 80 } 81 82 public NamedXPathAwareChild createField() { 83 NamedXPathAwareChild field = new NamedXPathAwareChild(); 84 fields.add(field); 85 return field; 86 } 87 88 public XPathAwareChild createTitle() { 89 title = new XPathAwareChild(); 90 return title; 91 } 92 93 public XPathAwareChild createDescription() { 94 description = new XPathAwareChild(); 95 return description; 96 } 97 98 public XPathAwareChild createStatus() { 99 status = new XPathAwareChild(); 100 return status; 101 } 102 103 public void publish(Element cruisecontrolLog) throws CruiseControlException { 104 105 ISourceForgeSoap soapStub = (ISourceForgeSoap) ClientSoapStubFactory 106 .getSoapStub(ISourceForgeSoap.class, getServerURL()); 107 108 try { 109 String sessionID = soapStub.login(getUsername(), getPassword()); 110 String projectID = SfeeUtils.findProjectID(soapStub, sessionID, projectName); 111 112 ITrackerAppSoap tracker = (ITrackerAppSoap) ClientSoapStubFactory 113 .getSoapStub(ITrackerAppSoap.class, getServerURL()); 114 TrackerSoapList trackerList = tracker.getTrackerList(sessionID, projectID); 115 TrackerSoapRow[] trackerListRows = trackerList.getDataRows(); 116 String trackerID = null; 117 for (int i = 0; i < trackerListRows.length; i++) { 118 TrackerSoapRow trackerListRow = trackerListRows[i]; 119 String nextTitle = trackerListRow.getTitle(); 120 if (nextTitle.equals(trackerName)) { 121 trackerID = trackerListRow.getId(); 122 } 123 } 124 SfeeUtils.assertFoundValue(trackerID, "trackerName", trackerName); 125 126 tracker.createArtifact(sessionID, trackerID, title.lookupValue(cruisecontrolLog), 127 description.lookupValue(cruisecontrolLog), null, null, status.lookupValue(cruisecontrolLog), null, 128 0, 0, null, null, buildFlexFields(cruisecontrolLog), 129 null, null, null); 130 } catch (RemoteException e) { 131 throw new CruiseControlException(e); 132 } 133 134 } 135 136 private SoapNamedValues buildFlexFields(Element log) throws CruiseControlException { 137 SoapNamedValues namedValues = new SoapNamedValues(); 138 String [] names = new String [fields.size()]; 139 String [] values = new String [fields.size()]; 140 int i = 0; 141 for (Iterator iterator = fields.iterator(); iterator.hasNext(); i++) { 142 NamedXPathAwareChild nextField = (NamedXPathAwareChild) iterator.next(); 143 names[i] = nextField.getName(); 144 values[i] = nextField.lookupValue(log); 145 } 146 namedValues.setNames(names); 147 namedValues.setValues(values); 148 return namedValues; 149 } 150 151 public void subValidate() throws CruiseControlException { 152 ValidationHelper.assertNotEmpty(projectName, "projectName", this.getClass()); 153 ValidationHelper.assertNotEmpty(trackerName, "trackerName", this.getClass()); 154 ValidationHelper.assertHasChild(title, "title", this.getClass()); 155 ValidationHelper.assertHasChild(description, "description", this.getClass()); 156 ValidationHelper.assertHasChild(status, "status", this.getClass()); 157 158 title.validate(); 160 description.validate(); 161 status.validate(); 162 163 for (Iterator iterator = fields.iterator(); iterator.hasNext();) { 165 NamedXPathAwareChild nextField = (NamedXPathAwareChild) iterator.next(); 166 nextField.validate(); 167 } 168 } 169 170 171 } 172 | Popular Tags |