View Javadoc

1   package org.apache.maven.continuum.web.action;
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.AuditLog;
23  import org.apache.continuum.web.util.AuditLogConstants;
24  import org.apache.maven.continuum.ContinuumException;
25  import org.apache.maven.continuum.model.project.Project;
26  import org.apache.maven.continuum.model.project.ProjectGroup;
27  import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  /**
32   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
33   * @version $Id: DeleteProjectAction.java 1372260 2012-08-13 04:29:09Z brett $
34   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteProject"
35   */
36  public class DeleteProjectAction
37      extends ContinuumActionSupport
38  {
39      private Logger logger = LoggerFactory.getLogger( this.getClass() );
40  
41      private int projectId;
42  
43      private String projectName;
44  
45      private int projectGroupId;
46  
47      private String projectGroupName = "";
48  
49      public String execute()
50          throws ContinuumException
51      {
52          try
53          {
54              checkRemoveProjectFromGroupAuthorization( getProjectGroupName() );
55          }
56          catch ( AuthorizationRequiredException e )
57          {
58              return REQUIRES_AUTHORIZATION;
59          }
60  
61          AuditLog event = new AuditLog( "Project id=" + projectId, AuditLogConstants.REMOVE_PROJECT );
62          event.setCurrentUser( getPrincipal() );
63          event.setCategory( AuditLogConstants.PROJECT );
64          event.log();
65  
66          try
67          {
68              getContinuum().removeProject( projectId );
69          }
70          catch ( ContinuumException e )
71          {
72              logger.error( "Error removing project with id " + projectId, e );
73              addActionError( getText( "deleteProject.error", "Unable to delete project", new Integer(
74                  projectId ).toString() ) );
75          }
76  
77          return SUCCESS;
78      }
79  
80      public String doDefault()
81          throws ContinuumException
82      {
83          try
84          {
85              checkRemoveProjectFromGroupAuthorization( getProjectGroupName() );
86          }
87          catch ( AuthorizationRequiredException e )
88          {
89              return REQUIRES_AUTHORIZATION;
90          }
91  
92          Project project = getContinuum().getProject( projectId );
93          projectName = project.getName();
94  
95          return "delete";
96      }
97  
98      public void setProjectId( int projectId )
99      {
100         this.projectId = projectId;
101     }
102 
103     public int getProjectId()
104     {
105         return projectId;
106     }
107 
108     public void setProjectName( String projectName )
109     {
110         this.projectName = projectName;
111     }
112 
113     public String getProjectName()
114     {
115         return projectName;
116     }
117 
118     public void setProjectGroupId( int projectGroupId )
119     {
120         this.projectGroupId = projectGroupId;
121     }
122 
123     public int getProjectGroupId()
124     {
125         return projectGroupId;
126     }
127 
128     public String getProjectGroupName()
129         throws ContinuumException
130     {
131         if ( projectGroupName == null || "".equals( projectGroupName ) )
132         {
133             if ( projectGroupId != 0 )
134             {
135                 projectGroupName = getContinuum().getProjectGroup( projectGroupId ).getName();
136             }
137             else
138             {
139                 ProjectGroup group = getContinuum().getProjectGroupByProjectId( projectId );
140                 projectGroupName = group.getName();
141                 projectGroupId = group.getId();
142             }
143         }
144 
145         return projectGroupName;
146     }
147 }