View Javadoc

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.Project;
25  import org.apache.maven.continuum.model.project.ProjectGroup;
26  import org.apache.maven.continuum.model.project.ProjectNotifier;
27  import org.apache.maven.continuum.web.action.ContinuumActionSupport;
28  import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
29  import org.codehaus.plexus.util.StringUtils;
30  
31  /**
32   * Action that deletes a {@link ProjectNotifier} from a specified {@link Project}.
33   *
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   * @version $Id: DeleteProjectNotifierAction.java 756580 2009-03-20 16:25:46Z ctan $
36   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteProjectNotifier"
37   */
38  public class DeleteProjectNotifierAction
39      extends ContinuumActionSupport
40  {
41      private int projectId;
42  
43      /**
44       * Identifier for the {@link ProjectGroup} that the current {@link Project} is a member of.
45       */
46      private int projectGroupId;
47  
48      private int notifierId;
49  
50      private String notifierType;
51  
52      private String recipient;
53  
54      private boolean fromGroupPage = false;
55  
56      private String projectGroupName = "";
57  
58      public String execute()
59          throws ContinuumException
60      {
61          try
62          {
63              checkRemoveProjectNotifierAuthorization( getProjectGroupName() );
64          }
65          catch ( AuthorizationRequiredException authzE )
66          {
67              addActionError( authzE.getMessage() );
68              return REQUIRES_AUTHORIZATION;
69          }
70  
71          getContinuum().removeNotifier( projectId, notifierId );
72  
73          if ( fromGroupPage )
74          {
75              return "to_group_page";
76          }
77  
78          return SUCCESS;
79      }
80  
81      public String doDefault()
82          throws ContinuumException
83      {
84          try
85          {
86              checkRemoveProjectNotifierAuthorization( getProjectGroupName() );
87          }
88          catch ( AuthorizationRequiredException authzE )
89          {
90              addActionError( authzE.getMessage() );
91              return REQUIRES_AUTHORIZATION;
92          }
93  
94          ProjectNotifier notifier = getContinuum().getNotifier( projectId, notifierId );
95  
96          notifierType = notifier.getType();
97  
98          recipient = GenerateRecipentNotifier.generate( notifier );
99  
100         return "delete";
101     }
102 
103     public void setProjectId( int projectId )
104     {
105         this.projectId = projectId;
106     }
107 
108     public int getProjectId()
109     {
110         return projectId;
111     }
112 
113     public void setNotifierId( int notifierId )
114     {
115         this.notifierId = notifierId;
116     }
117 
118     public int getNotifierId()
119     {
120         return notifierId;
121     }
122 
123     public void setNotifierType( String notifierType )
124     {
125         this.notifierType = notifierType;
126     }
127 
128     public String getNotifierType()
129     {
130         return notifierType;
131     }
132 
133     public int getProjectGroupId()
134     {
135         return projectGroupId;
136     }
137 
138     public void setProjectGroupId( int projectGroupId )
139     {
140         this.projectGroupId = projectGroupId;
141     }
142 
143     public String getRecipient()
144     {
145         return recipient;
146     }
147 
148     public void setRecipient( String recipient )
149     {
150         this.recipient = recipient;
151     }
152 
153     public boolean isFromGroupPage()
154     {
155         return fromGroupPage;
156     }
157 
158     public void setFromGroupPage( boolean fromGroupPage )
159     {
160         this.fromGroupPage = fromGroupPage;
161     }
162 
163     public String getProjectGroupName()
164         throws ContinuumException
165     {
166         if ( StringUtils.isEmpty( projectGroupName ) )
167         {
168             if ( projectGroupId != 0 )
169             {
170                 projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName();
171             }
172             else
173             {
174                 projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
175             }
176         }
177 
178         return projectGroupName;
179     }
180 }