KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > sfee > SfeeTrackerPublisher


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

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 JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.Collection JavaDoc;
54 import java.util.Iterator JavaDoc;
55
56
57 /**
58  * <p>Publishes to a SourceForge Enterprise Edition Tracker. The publisher allows for arbitrary "fields", since tracker
59  * artifacts are configurable. Every tracker artifact must have a title, description, and status. So, those fields are
60  * not optional.</p>
61  *
62  * @author <a HREF="mailto:kspillne@thoughtworks.com">Kent Spillner</a>
63  * @author <a HREF="mailto:pj@thoughtworks.com">Paul Julius</a>
64  */

65 public class SfeeTrackerPublisher extends SfeePublisher {
66
67     private String JavaDoc trackerName;
68     private final Collection JavaDoc fields = new ArrayList JavaDoc();
69     private String JavaDoc projectName;
70     private XPathAwareChild title;
71     private XPathAwareChild description;
72     private XPathAwareChild status;
73
74     public void setTrackerName(String JavaDoc name) {
75         this.trackerName = name;
76     }
77
78     public void setProjectName(String JavaDoc 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 JavaDoc sessionID = soapStub.login(getUsername(), getPassword());
110             String JavaDoc 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 JavaDoc trackerID = null;
117             for (int i = 0; i < trackerListRows.length; i++) {
118                 TrackerSoapRow trackerListRow = trackerListRows[i];
119                 String JavaDoc 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 JavaDoc 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 JavaDoc[] names = new String JavaDoc[fields.size()];
139         String JavaDoc[] values = new String JavaDoc[fields.size()];
140         int i = 0;
141         for (Iterator JavaDoc 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         //Validate required children
159
title.validate();
160         description.validate();
161         status.validate();
162
163         //Validate all fields
164
for (Iterator JavaDoc iterator = fields.iterator(); iterator.hasNext();) {
165             NamedXPathAwareChild nextField = (NamedXPathAwareChild) iterator.next();
166             nextField.validate();
167         }
168     }
169
170
171 }
172
Popular Tags