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 java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.apache.continuum.buildmanager.BuildManagerException;
27 import org.apache.continuum.web.util.AuditLog;
28 import org.apache.continuum.web.util.AuditLogConstants;
29 import org.apache.maven.continuum.ContinuumException;
30 import org.apache.maven.continuum.model.project.BuildResult;
31 import org.apache.maven.continuum.model.project.Project;
32 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
33 import org.codehaus.plexus.util.StringUtils;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
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, AuditLogConstants.REMOVE_BUILD_RESULT );
106 event.setCategory( AuditLogConstants.BUILD_RESULT );
107 event.setCurrentUser( getPrincipal() );
108 event.log();
109 }
110 catch ( ContinuumException e )
111 {
112 logger.error( "Error removing BuildResult with id=" + buildId );
113 addActionError( getText( "buildResult.delete.error", "Unable to delete build result",
114 new Integer( buildId ).toString() ) );
115 }
116 }
117 }
118 return SUCCESS;
119 }
120 else
121 {
122 List<String> buildResultsRemovable = new ArrayList<String>();
123 if ( selectedBuildResults != null && !selectedBuildResults.isEmpty() )
124 {
125 for ( String id : selectedBuildResults )
126 {
127 int buildId = Integer.parseInt( id );
128
129 try
130 {
131 if ( canRemoveBuildResult( getContinuum().getBuildResult( buildId ) ) )
132 {
133 buildResultsRemovable.add( Integer.toString( buildId ) );
134 }
135 else
136 {
137 this.addActionMessage( getResourceBundle().getString( "buildResult.cannot.delete" ) );
138 return SUCCESS;
139 }
140 }
141 catch ( BuildManagerException e )
142 {
143 logger.error( e.getMessage() );
144 throw new ContinuumException( e.getMessage(), e );
145 }
146 }
147 }
148 this.setSelectedBuildResults( buildResultsRemovable );
149 }
150 return CONFIRM;
151 }
152
153 public int getProjectId()
154 {
155 return projectId;
156 }
157
158 public void setProjectId( int projectId )
159 {
160 this.projectId = projectId;
161 }
162
163 public Collection<BuildResult> getBuildResults()
164 {
165 return buildResults;
166 }
167
168 public String getProjectName()
169 {
170 return projectName;
171 }
172
173 public void setProjectName( String projectName )
174 {
175 this.projectName = projectName;
176 }
177
178 public Project getProject()
179 {
180 return project;
181 }
182
183 public String getProjectGroupName()
184 throws ContinuumException
185 {
186 if ( StringUtils.isEmpty( projectGroupName ) )
187 {
188 projectGroupName = getContinuum().getProject( projectId ).getProjectGroup().getName();
189 }
190
191 return projectGroupName;
192 }
193
194 public Collection<String> getSelectedBuildResults()
195 {
196 return selectedBuildResults;
197 }
198
199 public void setSelectedBuildResults( Collection<String> selectedBuildResults )
200 {
201 this.selectedBuildResults = selectedBuildResults;
202 }
203
204 public int getProjectGroupId()
205 {
206 return projectGroupId;
207 }
208
209 public void setProjectGroupId( int projectGroupId )
210 {
211 this.projectGroupId = projectGroupId;
212 }
213 }