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