View Javadoc

1   package org.apache.continuum.web.action;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang.StringEscapeUtils;
23  import org.apache.continuum.model.release.ContinuumReleaseResult;
24  import org.apache.maven.continuum.ContinuumException;
25  import org.apache.maven.continuum.configuration.ConfigurationException;
26  import org.apache.maven.continuum.model.project.ProjectGroup;
27  import org.apache.maven.continuum.web.action.ContinuumConfirmAction;
28  import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
29  import org.apache.maven.shared.release.ReleaseResult;
30  import org.codehaus.plexus.util.FileUtils;
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  import java.io.File;
35  import java.io.IOException;
36  import java.util.List;
37  
38  /**
39   * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
40   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseResult"
41   */
42  public class ReleaseResultAction
43      extends ContinuumConfirmAction
44  {
45      private static final Logger logger = LoggerFactory.getLogger( ReleaseResultAction.class );
46  
47      private int projectGroupId;
48  
49      private int releaseResultId;
50  
51      private List<ContinuumReleaseResult> releaseResults;
52  
53      private List<String> selectedReleaseResults;
54  
55      private ProjectGroup projectGroup;
56  
57      private ReleaseResult result;
58  
59      private boolean confirmed;
60  
61      private String projectName;
62  
63      private String releaseGoal;
64  
65      private String username;
66  
67      public String list()
68          throws ContinuumException
69      {
70          try
71          {
72              checkViewProjectGroupAuthorization( getProjectGroupName() );
73          }
74          catch ( AuthorizationRequiredException authzE )
75          {
76              addActionError( authzE.getMessage() );
77              return REQUIRES_AUTHORIZATION;
78          }
79  
80          releaseResults = getContinuum().getContinuumReleaseResultsByProjectGroup( projectGroupId );
81  
82          return SUCCESS;
83  
84      }
85  
86      public String remove()
87          throws ContinuumException
88      {
89          try
90          {
91              checkModifyProjectGroupAuthorization( getProjectGroupName() );
92          }
93          catch ( AuthorizationRequiredException e )
94          {
95              return REQUIRES_AUTHORIZATION;
96          }
97  
98          if ( confirmed )
99          {
100             if ( selectedReleaseResults != null && !selectedReleaseResults.isEmpty() )
101             {
102                 for ( String id : selectedReleaseResults )
103                 {
104                     int resultId = Integer.parseInt( id );
105 
106                     try
107                     {
108                         logger.info( "Removing ContinuumReleaseResult with id=" + resultId );
109 
110                         getContinuum().removeContinuumReleaseResult( resultId );
111                     }
112                     catch ( ContinuumException e )
113                     {
114                         logger.error( "Error removing ContinuumReleaseResult with id=" + resultId );
115                         addActionError( getText( "Unable to remove ContinuumReleaseResult with id=" + resultId ) );
116                     }
117                 }
118             }
119             return SUCCESS;
120         }
121 
122         return CONFIRM;
123     }
124 
125     public String viewResult()
126         throws ContinuumException
127     {
128         try
129         {
130             checkViewProjectGroupAuthorization( getProjectGroupName() );
131         }
132         catch ( AuthorizationRequiredException authzE )
133         {
134             addActionError( authzE.getMessage() );
135             return REQUIRES_AUTHORIZATION;
136         }
137 
138         ContinuumReleaseResult releaseResult = getContinuum().getContinuumReleaseResult( releaseResultId );
139 
140         result = new ReleaseResult();
141         result.setStartTime( releaseResult.getStartTime() );
142         result.setEndTime( releaseResult.getEndTime() );
143         result.setResultCode( releaseResult.getResultCode() );
144 
145         releaseGoal = releaseResult.getReleaseGoal();
146         projectName = releaseResult.getProject().getName();
147         username = releaseResult.getUsername();
148 
149         try
150         {
151             File releaseOutputFile = getContinuum().getConfiguration().getReleaseOutputFile( projectGroupId,
152                                                                                              "releases-" +
153                                                                                                  releaseResult.getStartTime() );
154 
155             if ( releaseOutputFile.exists() )
156             {
157                 String str = StringEscapeUtils.escapeHtml( FileUtils.fileRead( releaseOutputFile ) );
158                 result.appendOutput( str );
159             }
160         }
161         catch ( ConfigurationException e )
162         {
163             //getLogger().error( "" );
164         }
165         catch ( IOException e )
166         {
167             //getLogger().error( "" );
168         }
169 
170         return SUCCESS;
171     }
172 
173     public String getProjectGroupName()
174         throws ContinuumException
175     {
176 
177         return getProjectGroup( projectGroupId ).getName();
178     }
179 
180     public ProjectGroup getProjectGroup( int projectGroupId )
181         throws ContinuumException
182     {
183         if ( projectGroup == null )
184         {
185             projectGroup = getContinuum().getProjectGroup( projectGroupId );
186         }
187         else
188         {
189             if ( projectGroup.getId() != projectGroupId )
190             {
191                 projectGroup = getContinuum().getProjectGroup( projectGroupId );
192             }
193         }
194 
195         return projectGroup;
196     }
197 
198     public ProjectGroup getProjectGroup()
199     {
200         return projectGroup;
201     }
202 
203     public void setProjectGroup( ProjectGroup projectGroup )
204     {
205         this.projectGroup = projectGroup;
206     }
207 
208     public int getProjectGroupId()
209     {
210         return projectGroupId;
211     }
212 
213     public void setProjectGroupId( int projectGroupId )
214     {
215         this.projectGroupId = projectGroupId;
216     }
217 
218     public int getReleaseResultId()
219     {
220         return releaseResultId;
221     }
222 
223     public void setReleaseResultId( int releaseResultId )
224     {
225         this.releaseResultId = releaseResultId;
226     }
227 
228     public List<ContinuumReleaseResult> getReleaseResults()
229     {
230         return releaseResults;
231     }
232 
233     public void setReleaseResults( List<ContinuumReleaseResult> releaseResults )
234     {
235         this.releaseResults = releaseResults;
236     }
237 
238     public List<String> getSelectedReleaseResults()
239     {
240         return selectedReleaseResults;
241     }
242 
243     public void setSelectedReleaseResults( List<String> selectedReleaseResults )
244     {
245         this.selectedReleaseResults = selectedReleaseResults;
246     }
247 
248     public ReleaseResult getResult()
249     {
250         return result;
251     }
252 
253     public void setResult( ReleaseResult result )
254     {
255         this.result = result;
256     }
257 
258     public boolean isConfirmed()
259     {
260         return confirmed;
261     }
262 
263     public void setConfirmed( boolean confirmed )
264     {
265         this.confirmed = confirmed;
266     }
267 
268     public String getProjectName()
269     {
270         return projectName;
271     }
272 
273     public void setProjectName( String projectName )
274     {
275         this.projectName = projectName;
276     }
277 
278     public String getReleaseGoal()
279     {
280         return releaseGoal;
281     }
282 
283     public void setReleaseGoal( String releaseGoal )
284     {
285         this.releaseGoal = releaseGoal;
286     }
287 
288     public void setUsername( String username )
289     {
290         this.username = username;
291     }
292 
293     public String getUsername()
294     {
295         return username;
296     }
297 }