1 package org.apache.maven.continuum.web.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.buildmanager.BuildManagerException;
23 import org.apache.continuum.web.util.AuditLog;
24 import org.apache.continuum.web.util.AuditLogConstants;
25 import org.apache.maven.continuum.ContinuumException;
26 import org.apache.maven.continuum.model.project.BuildResult;
27 import org.apache.maven.continuum.model.project.Project;
28 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
29 import org.codehaus.plexus.util.StringUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.List;
36
37
38
39
40
41
42 public class BuildResultsListAction
43 extends AbstractBuildAction
44 {
45 private static final Logger logger = LoggerFactory.getLogger( BuildResultsListAction.class );
46
47 private Project project;
48
49 private Collection<BuildResult> buildResults;
50
51 private Collection<String> selectedBuildResults;
52
53 private int projectId;
54
55 private int projectGroupId;
56
57 private String projectName;
58
59 private String projectGroupName = "";
60
61 public String execute()
62 throws ContinuumException
63 {
64 try
65 {
66 checkViewProjectGroupAuthorization( getProjectGroupName() );
67 }
68 catch ( AuthorizationRequiredException e )
69 {
70 return REQUIRES_AUTHORIZATION;
71 }
72
73 project = getContinuum().getProject( projectId );
74
75 buildResults = getContinuum().getBuildResultsForProject( projectId );
76
77 return SUCCESS;
78 }
79
80 public String remove()
81 throws ContinuumException
82 {
83 try
84 {
85 checkModifyProjectGroupAuthorization( getProjectGroupName() );
86 }
87 catch ( AuthorizationRequiredException e )
88 {
89 return REQUIRES_AUTHORIZATION;
90 }
91 if ( this.isConfirmed() )
92 {
93 if ( selectedBuildResults != null && !selectedBuildResults.isEmpty() )
94 {
95 for ( String id : selectedBuildResults )
96 {
97 int buildId = Integer.parseInt( id );
98
99 try
100 {
101 logger.info( "Removing BuildResult with id=" + buildId );
102
103 getContinuum().removeBuildResult( buildId );
104
105 AuditLog event = new AuditLog( "Build Result id=" + buildId,
106 AuditLogConstants.REMOVE_BUILD_RESULT );
107 event.setCategory( AuditLogConstants.BUILD_RESULT );
108 event.setCurrentUser( getPrincipal() );
109 event.log();
110 }
111 catch ( ContinuumException e )
112 {
113 logger.error( "Error removing BuildResult with id=" + buildId );
114 addActionError( getText( "buildResult.delete.error", "Unable to delete build result",
115 new Integer( buildId ).toString() ) );
116 }
117 }
118 }
119 return SUCCESS;
120 }
121 else
122 {
123 List<String> buildResultsRemovable = new ArrayList<String>();
124 if ( selectedBuildResults != null && !selectedBuildResults.isEmpty() )
125 {
126 for ( String id : selectedBuildResults )
127 {
128 int buildId = Integer.parseInt( id );
129
130 try
131 {
132 if ( canRemoveBuildResult( getContinuum().getBuildResult( buildId ) ) )
133 {
134 buildResultsRemovable.add( Integer.toString( buildId ) );
135 }
136 else
137 {
138 this.addActionMessage( getResourceBundle().getString( "buildResult.cannot.delete" ) );
139 return SUCCESS;
140 }
141 }
142 catch ( BuildManagerException e )
143 {
144 logger.error( e.getMessage() );
145 throw new ContinuumException( e.getMessage(), e );
146 }
147 }
148 }
149 this.setSelectedBuildResults( buildResultsRemovable );
150 }
151 return CONFIRM;
152 }
153
154 public int getProjectId()
155 {
156 return projectId;
157 }
158
159 public void setProjectId( int projectId )
160 {
161 this.projectId = projectId;
162 }
163
164 public Collection<BuildResult> getBuildResults()
165 {
166 return buildResults;
167 }
168
169 public String getProjectName()
170 {
171 return projectName;
172 }
173
174 public void setProjectName( String projectName )
175 {
176 this.projectName = projectName;
177 }
178
179 public Project getProject()
180 {
181 return project;
182 }
183
184 public String getProjectGroupName()
185 throws ContinuumException
186 {
187 if ( StringUtils.isEmpty( projectGroupName ) )
188 {
189 projectGroupName = getContinuum().getProject( projectId ).getProjectGroup().getName();
190 }
191
192 return projectGroupName;
193 }
194
195 public Collection<String> getSelectedBuildResults()
196 {
197 return selectedBuildResults;
198 }
199
200 public void setSelectedBuildResults( Collection<String> selectedBuildResults )
201 {
202 this.selectedBuildResults = selectedBuildResults;
203 }
204
205 public int getProjectGroupId()
206 {
207 return projectGroupId;
208 }
209
210 public void setProjectGroupId( int projectGroupId )
211 {
212 this.projectGroupId = projectGroupId;
213 }
214 }