1 | package org.apache.maven.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.maven.continuum.ContinuumException; |
23 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
24 | import org.apache.continuum.web.util.AuditLog; |
25 | import org.apache.continuum.web.util.AuditLogConstants; |
26 | import org.codehaus.plexus.util.StringUtils; |
27 | |
28 | /** |
29 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
30 | * @version $Id: BuildProjectAction.java 790386 2009-07-01 21:27:25Z evenisse $ |
31 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="buildProject" |
32 | */ |
33 | public class BuildProjectAction |
34 | extends ContinuumActionSupport |
35 | { |
36 | private int projectId; |
37 | |
38 | private int buildDefinitionId; |
39 | |
40 | private int projectGroupId; |
41 | |
42 | private boolean fromGroupPage = false; |
43 | |
44 | private boolean fromProjectPage = false; |
45 | |
46 | private String projectGroupName = ""; |
47 | |
48 | public String execute() |
49 | throws ContinuumException |
50 | { |
51 | try |
52 | { |
53 | checkBuildProjectInGroupAuthorization( getProjectGroupName() ); |
54 | } |
55 | catch ( AuthorizationRequiredException e ) |
56 | { |
57 | return REQUIRES_AUTHORIZATION; |
58 | } |
59 | |
60 | if ( projectId > 0 ) |
61 | { |
62 | if ( buildDefinitionId > 0 ) |
63 | { |
64 | getContinuum().buildProjectWithBuildDefinition( projectId, buildDefinitionId ); |
65 | } |
66 | else |
67 | { |
68 | getContinuum().buildProject( projectId ); |
69 | } |
70 | } |
71 | else |
72 | { |
73 | if ( buildDefinitionId > 0 ) |
74 | { |
75 | getContinuum().buildProjectGroupWithBuildDefinition( projectGroupId, buildDefinitionId ); |
76 | } |
77 | else |
78 | { |
79 | //TODO: Check if this code is called, I don't think |
80 | //If it is, it should used the projectId |
81 | getContinuum().buildProjects(); |
82 | } |
83 | } |
84 | |
85 | AuditLog event = new AuditLog( AuditLogConstants.FORCE_BUILD ); |
86 | event.setCurrentUser( getPrincipal() ); |
87 | |
88 | if ( projectId > 0 ) |
89 | { |
90 | event.setResource( "Project id=" + projectId ); |
91 | event.setCategory( AuditLogConstants.PROJECT ); |
92 | event.log(); |
93 | |
94 | if ( fromGroupPage ) |
95 | { |
96 | return "to_group_page"; |
97 | } |
98 | if ( fromProjectPage ) |
99 | { |
100 | return "to_project_page"; |
101 | } |
102 | } |
103 | else |
104 | { |
105 | event.setResource( "Project Group id=" + projectGroupId ); |
106 | event.setCategory( AuditLogConstants.PROJECT_GROUP ); |
107 | event.log(); |
108 | if ( fromGroupPage ) |
109 | { |
110 | return "to_group_page"; |
111 | } |
112 | } |
113 | |
114 | return SUCCESS; |
115 | } |
116 | |
117 | public void setProjectId( int projectId ) |
118 | { |
119 | this.projectId = projectId; |
120 | } |
121 | |
122 | public int getProjectId() |
123 | { |
124 | return projectId; |
125 | } |
126 | |
127 | public void setBuildDefinitionId( int buildDefinitionId ) |
128 | { |
129 | this.buildDefinitionId = buildDefinitionId; |
130 | } |
131 | |
132 | public int getBuildDefinition() |
133 | { |
134 | return buildDefinitionId; |
135 | } |
136 | |
137 | public int getProjectGroupId() |
138 | { |
139 | return projectGroupId; |
140 | } |
141 | |
142 | public void setProjectGroupId( int projectGroupId ) |
143 | { |
144 | this.projectGroupId = projectGroupId; |
145 | } |
146 | |
147 | public boolean isFromGroupPage() |
148 | { |
149 | return fromGroupPage; |
150 | } |
151 | |
152 | public void setFromGroupPage( boolean fromGroupPage ) |
153 | { |
154 | this.fromGroupPage = fromGroupPage; |
155 | } |
156 | |
157 | public boolean isFromProjectPage() |
158 | { |
159 | return fromProjectPage; |
160 | } |
161 | |
162 | public void setFromProjectPage( boolean fromProjectPage ) |
163 | { |
164 | this.fromProjectPage = fromProjectPage; |
165 | } |
166 | |
167 | public String getProjectGroupName() |
168 | throws ContinuumException |
169 | { |
170 | if ( StringUtils.isEmpty( projectGroupName ) ) |
171 | { |
172 | if ( projectGroupId != 0 ) |
173 | { |
174 | projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName(); |
175 | } |
176 | else |
177 | { |
178 | projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName(); |
179 | } |
180 | } |
181 | |
182 | return projectGroupName; |
183 | } |
184 | } |