1 | /** |
2 | * |
3 | */ |
4 | package org.apache.maven.continuum.web.action.notifier; |
5 | |
6 | /* |
7 | * Licensed to the Apache Software Foundation (ASF) under one |
8 | * or more contributor license agreements. See the NOTICE file |
9 | * distributed with this work for additional information |
10 | * regarding copyright ownership. The ASF licenses this file |
11 | * to you under the Apache License, Version 2.0 (the |
12 | * "License"); you may not use this file except in compliance |
13 | * with the License. You may obtain a copy of the License at |
14 | * |
15 | * http://www.apache.org/licenses/LICENSE-2.0 |
16 | * |
17 | * Unless required by applicable law or agreed to in writing, |
18 | * software distributed under the License is distributed on an |
19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
20 | * KIND, either express or implied. See the License for the |
21 | * specific language governing permissions and limitations |
22 | * under the License. |
23 | */ |
24 | |
25 | import org.apache.maven.continuum.ContinuumException; |
26 | import org.apache.maven.continuum.model.project.ProjectGroup; |
27 | import org.apache.maven.continuum.model.project.ProjectNotifier; |
28 | import org.apache.maven.continuum.web.action.ContinuumActionSupport; |
29 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
30 | import org.codehaus.plexus.util.StringUtils; |
31 | |
32 | /** |
33 | * WW action that sets up a new {@link ProjectNotifier} instance for |
34 | * the specified {@link ProjectGroup}. |
35 | * |
36 | * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a> |
37 | * @version $Id: AddGroupNotifierAction.java 729461 2008-12-26 08:38:10Z olamy $ |
38 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addGroupNotifier" |
39 | * @since 1.1 |
40 | */ |
41 | public class AddGroupNotifierAction |
42 | extends ContinuumActionSupport |
43 | { |
44 | /** |
45 | * Target {@link ProjectGroup} instance to add the Notifier for. |
46 | */ |
47 | private int projectGroupId; |
48 | |
49 | /** |
50 | * String based type identifier for the {@link ProjectNotifier}. |
51 | */ |
52 | private String notifierType; |
53 | |
54 | private String projectGroupName = ""; |
55 | |
56 | /** |
57 | * Default action method executed in case no method is specified |
58 | * for invocation. |
59 | * |
60 | * @return a String result that determines the control flow. |
61 | */ |
62 | public String execute() |
63 | throws ContinuumException |
64 | { |
65 | try |
66 | { |
67 | checkAddProjectGroupNotifierAuthorization( getProjectGroupName() ); |
68 | } |
69 | catch ( AuthorizationRequiredException authzE ) |
70 | { |
71 | addActionError( authzE.getMessage() ); |
72 | return REQUIRES_AUTHORIZATION; |
73 | } |
74 | |
75 | return notifierType + "_" + INPUT; |
76 | } |
77 | |
78 | // TODO: Remove this method because a default method return SUCCESS instead of INPUT |
79 | public String doDefault() |
80 | throws ContinuumException |
81 | { |
82 | return input(); |
83 | } |
84 | |
85 | public String input() |
86 | throws ContinuumException |
87 | { |
88 | try |
89 | { |
90 | checkAddProjectGroupNotifierAuthorization( getProjectGroupName() ); |
91 | } |
92 | catch ( AuthorizationRequiredException authzE ) |
93 | { |
94 | addActionError( authzE.getMessage() ); |
95 | return REQUIRES_AUTHORIZATION; |
96 | } |
97 | |
98 | return INPUT; |
99 | } |
100 | |
101 | /** |
102 | * Returns the type identifier for the {@link ProjectNotifier} being |
103 | * edited as String. |
104 | * |
105 | * @return notifier type as String. |
106 | */ |
107 | public String getNotifierType() |
108 | { |
109 | return notifierType; |
110 | } |
111 | |
112 | /** |
113 | * Sets the notifier type for the {@link ProjectNotifier} instance |
114 | * being edited. |
115 | * |
116 | * @param notifierType notifier type to set. |
117 | */ |
118 | public void setNotifierType( String notifierType ) |
119 | { |
120 | this.notifierType = notifierType; |
121 | } |
122 | |
123 | /** |
124 | * Returns the current {@link ProjectGroup} Identifier. |
125 | * |
126 | * @return the projectGroupId |
127 | */ |
128 | public int getProjectGroupId() |
129 | { |
130 | return projectGroupId; |
131 | } |
132 | |
133 | /** |
134 | * Sets the Id for the target {@link ProjectGroup}. |
135 | * |
136 | * @param projectGroupId the projectGroupId to set |
137 | */ |
138 | public void setProjectGroupId( int projectGroupId ) |
139 | { |
140 | this.projectGroupId = projectGroupId; |
141 | } |
142 | |
143 | public String getProjectGroupName() |
144 | throws ContinuumException |
145 | { |
146 | if ( StringUtils.isEmpty( projectGroupName ) ) |
147 | { |
148 | projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName(); |
149 | } |
150 | |
151 | return projectGroupName; |
152 | } |
153 | } |