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.continuum.web.util.GenerateRecipentNotifier; |
23 | import org.apache.maven.continuum.ContinuumException; |
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 delete a {@link ProjectNotifier} instance from a |
32 | * specified {@link ProjectGroup}. |
33 | * |
34 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
35 | * @version $Id: DeleteGroupNotifierAction.java 756580 2009-03-20 16:25:46Z ctan $ |
36 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteGroupNotifier" |
37 | * @since 1.1 |
38 | */ |
39 | public class DeleteGroupNotifierAction |
40 | extends ContinuumActionSupport |
41 | { |
42 | private int projectGroupId; |
43 | |
44 | private int notifierId; |
45 | |
46 | private String notifierType; |
47 | |
48 | private String recipient; |
49 | |
50 | private String projectGroupName = ""; |
51 | |
52 | public String execute() |
53 | throws ContinuumException |
54 | { |
55 | try |
56 | { |
57 | checkRemoveProjectGroupNotifierAuthorization( getProjectGroupName() ); |
58 | } |
59 | catch ( AuthorizationRequiredException authzE ) |
60 | { |
61 | addActionError( authzE.getMessage() ); |
62 | return REQUIRES_AUTHORIZATION; |
63 | } |
64 | |
65 | getContinuum().removeGroupNotifier( projectGroupId, notifierId ); |
66 | |
67 | return SUCCESS; |
68 | } |
69 | |
70 | public String doDefault() |
71 | throws ContinuumException |
72 | { |
73 | try |
74 | { |
75 | checkRemoveProjectGroupNotifierAuthorization( getProjectGroupName() ); |
76 | } |
77 | catch ( AuthorizationRequiredException authzE ) |
78 | { |
79 | addActionError( authzE.getMessage() ); |
80 | return REQUIRES_AUTHORIZATION; |
81 | } |
82 | |
83 | ProjectNotifier notifier = getContinuum().getGroupNotifier( projectGroupId, notifierId ); |
84 | |
85 | notifierType = notifier.getType(); |
86 | |
87 | recipient = GenerateRecipentNotifier.generate( notifier ); |
88 | |
89 | return "delete"; |
90 | } |
91 | |
92 | public void setNotifierId( int notifierId ) |
93 | { |
94 | this.notifierId = notifierId; |
95 | } |
96 | |
97 | public int getNotifierId() |
98 | { |
99 | return notifierId; |
100 | } |
101 | |
102 | public void setNotifierType( String notifierType ) |
103 | { |
104 | this.notifierType = notifierType; |
105 | } |
106 | |
107 | public String getNotifierType() |
108 | { |
109 | return notifierType; |
110 | } |
111 | |
112 | /** |
113 | * @return the projectGroupId |
114 | */ |
115 | public int getProjectGroupId() |
116 | { |
117 | return projectGroupId; |
118 | } |
119 | |
120 | /** |
121 | * @param projectGroupId the projectGroupId to set |
122 | */ |
123 | public void setProjectGroupId( int projectGroupId ) |
124 | { |
125 | this.projectGroupId = projectGroupId; |
126 | } |
127 | |
128 | public int getProjectId() |
129 | { |
130 | //flags that this is a group notifier |
131 | return -1; |
132 | } |
133 | |
134 | public String getRecipient() |
135 | { |
136 | return recipient; |
137 | } |
138 | |
139 | public void setRecipient( String recipient ) |
140 | { |
141 | this.recipient = recipient; |
142 | } |
143 | |
144 | public String getProjectGroupName() |
145 | throws ContinuumException |
146 | { |
147 | if ( StringUtils.isEmpty( projectGroupName ) ) |
148 | { |
149 | projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName(); |
150 | } |
151 | |
152 | return projectGroupName; |
153 | } |
154 | } |