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.ProjectGroup;
24 import org.apache.maven.continuum.model.project.ProjectNotifier;
25 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
26 import org.codehaus.plexus.util.StringUtils;
27
28 /**
29 * Common base class for all Project Group notifier edit actions.
30 *
31 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
32 * @version $Id: AbstractGroupNotifierEditAction.java 729461 2008-12-26 08:38:10Z olamy $
33 */
34 public abstract class AbstractGroupNotifierEditAction
35 extends AbstractNotifierEditActionSupport
36 {
37
38 /**
39 * {@link ProjectGroup} identifier for which the notifier is being edited.
40 */
41 private int projectGroupId;
42
43 private String projectGroupName = "";
44
45 /**
46 * Creates or updates the {@link ProjectNotifier} instance for the
47 * {@link ProjectGroup} here.<p>
48 * This is used by the subclasses that create/obtain an instance of
49 * {@link ProjectNotifier} to be saved.
50 *
51 * @see org.apache.maven.continuum.web.action.notifier.AbstractNotifierEditActionSupport#saveNotifier(ProjectNotifier)
52 */
53 protected void saveNotifier( ProjectNotifier notifier )
54 throws ContinuumException
55 {
56 boolean isNew = notifier.getId() <= 0;
57 if ( !isNew )
58 {
59 getContinuum().updateGroupNotifier( projectGroupId, notifier );
60 }
61 else
62 {
63 getContinuum().addGroupNotifier( projectGroupId, notifier );
64 }
65 }
66
67 /**
68 * @return the notifier
69 * @throws ContinuumException
70 */
71 protected ProjectNotifier getNotifier()
72 throws ContinuumException
73 {
74 return getContinuum().getGroupNotifier( projectGroupId, getNotifierId() );
75 }
76
77 /**
78 * @return the projectGroupId
79 */
80 public int getProjectGroupId()
81 {
82 return projectGroupId;
83 }
84
85 /**
86 * @param projectGroupId the projectGroupId to set
87 */
88 public void setProjectGroupId( int projectGroupId )
89 {
90 this.projectGroupId = projectGroupId;
91 }
92
93 protected void checkAuthorization()
94 throws AuthorizationRequiredException, ContinuumException
95 {
96 if ( getNotifier() == null )
97 {
98 checkAddProjectGroupNotifierAuthorization( getProjectGroupName() );
99 }
100 else
101 {
102 checkModifyProjectGroupNotifierAuthorization( getProjectGroupName() );
103 }
104 }
105
106 public String getProjectGroupName()
107 throws ContinuumException
108 {
109 if ( StringUtils.isEmpty( projectGroupName ) )
110 {
111 projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName();
112 }
113
114 return projectGroupName;
115 }
116
117 }