1 | package org.apache.maven.continuum.web.action.notifier; |
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.model.project.Project; |
24 | import org.apache.maven.continuum.model.project.ProjectGroup; |
25 | import org.apache.maven.continuum.model.project.ProjectNotifier; |
26 | import org.apache.maven.continuum.web.action.ContinuumActionSupport; |
27 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
28 | import org.codehaus.plexus.util.StringUtils; |
29 | |
30 | /** |
31 | * Action to add a {@link ProjectNotifier} for a specified {@link Project}. |
32 | * |
33 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
34 | * @version $Id: AddProjectNotifierAction.java 766895 2009-04-20 22:02:13Z evenisse $ |
35 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addProjectNotifier" |
36 | * @since 1.1 |
37 | */ |
38 | public class AddProjectNotifierAction |
39 | extends ContinuumActionSupport |
40 | { |
41 | /** |
42 | * Identifier for the {@link Project} instance. |
43 | */ |
44 | private int projectId; |
45 | |
46 | /** |
47 | * Identifier for the {@link ProjectGroup} instance that the current {@link Project} is a member of. |
48 | */ |
49 | private int projectGroupId; |
50 | |
51 | /** |
52 | * Type for a {@link ProjectNotifier}. |
53 | */ |
54 | private String notifierType; |
55 | |
56 | /** |
57 | * Detemines if the save operation returns to the project group notifier page or not.<p> |
58 | * <code>true</code> implies return to the project group notifier page. |
59 | */ |
60 | private boolean fromGroupPage = false; |
61 | |
62 | private String projectGroupName = ""; |
63 | |
64 | /** |
65 | * Default method executed when no specific method is specified |
66 | * for invocation. |
67 | * |
68 | * @return result as a String value to determines the control flow. |
69 | */ |
70 | public String execute() |
71 | throws ContinuumException |
72 | { |
73 | try |
74 | { |
75 | checkAddProjectNotifierAuthorization( getProjectGroupName() ); |
76 | } |
77 | catch ( AuthorizationRequiredException authzE ) |
78 | { |
79 | addActionError( authzE.getMessage() ); |
80 | return REQUIRES_AUTHORIZATION; |
81 | } |
82 | |
83 | return notifierType + "_" + INPUT; |
84 | } |
85 | |
86 | // TODO: Remove this method because a default method return SUCCESS instead of INPUT |
87 | public String doDefault() |
88 | throws ContinuumException |
89 | { |
90 | return input(); |
91 | } |
92 | |
93 | public String input() |
94 | throws ContinuumException |
95 | { |
96 | try |
97 | { |
98 | checkAddProjectNotifierAuthorization( getProjectGroupName() ); |
99 | } |
100 | catch ( AuthorizationRequiredException authzE ) |
101 | { |
102 | addActionError( authzE.getMessage() ); |
103 | return REQUIRES_AUTHORIZATION; |
104 | } |
105 | |
106 | return INPUT; |
107 | } |
108 | |
109 | /** |
110 | * Returns the type for the {@link ProjectNotifier}. |
111 | * |
112 | * @return Notifier type as String. |
113 | */ |
114 | public String getNotifierType() |
115 | { |
116 | return notifierType; |
117 | } |
118 | |
119 | /** |
120 | * Sets the type for the {@link ProjectNotifier}. |
121 | * |
122 | * @param notifierType Notifier type to set. |
123 | */ |
124 | public void setNotifierType( String notifierType ) |
125 | { |
126 | this.notifierType = notifierType; |
127 | } |
128 | |
129 | /** |
130 | * Identifier for the Project being edited. |
131 | * |
132 | * @return project id. |
133 | */ |
134 | public int getProjectId() |
135 | { |
136 | return projectId; |
137 | } |
138 | |
139 | /** |
140 | * Sets the identifier for the Project to be edited for |
141 | * project notifiers. |
142 | * |
143 | * @param projectId The project id to set. |
144 | */ |
145 | public void setProjectId( int projectId ) |
146 | { |
147 | this.projectId = projectId; |
148 | } |
149 | |
150 | /** |
151 | * Returns the identifier for the {@link ProjectGroup} that the |
152 | * {@link Project} is a member of. |
153 | * |
154 | * @return the projectGroupId |
155 | */ |
156 | public int getProjectGroupId() |
157 | { |
158 | return projectGroupId; |
159 | } |
160 | |
161 | /** |
162 | * Sets the identifier for the {@link ProjectGroup} that the |
163 | * {@link Project} is a member of. |
164 | * |
165 | * @param projectGroupId the identifier to set |
166 | */ |
167 | public void setProjectGroupId( int projectGroupId ) |
168 | { |
169 | this.projectGroupId = projectGroupId; |
170 | } |
171 | |
172 | /** |
173 | * @return the fromGroupPage |
174 | */ |
175 | public boolean isFromGroupPage() |
176 | { |
177 | return fromGroupPage; |
178 | } |
179 | |
180 | /** |
181 | * @param fromGroupPage the fromGroupPage to set |
182 | */ |
183 | public void setFromGroupPage( boolean fromGroupPage ) |
184 | { |
185 | this.fromGroupPage = fromGroupPage; |
186 | } |
187 | |
188 | public String getProjectGroupName() |
189 | throws ContinuumException |
190 | { |
191 | if ( StringUtils.isEmpty( projectGroupName ) ) |
192 | { |
193 | if ( projectGroupId != 0 ) |
194 | { |
195 | projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName(); |
196 | } |
197 | else |
198 | { |
199 | projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName(); |
200 | } |
201 | } |
202 | |
203 | return projectGroupName; |
204 | } |
205 | } |