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.web.exception.AuthorizationRequiredException;
27  
28  /**
29   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
30   * @version $Id: ProjectEditAction.java 781927 2009-06-05 06:52:07Z ctan $
31   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="projectEdit"
32   */
33  public class ProjectEditAction
34      extends ContinuumActionSupport
35  {
36      private Project project;
37  
38      private int projectId;
39  
40      private String name;
41  
42      private String version;
43  
44      private String scmUrl;
45  
46      private String scmUsername;
47  
48      private String scmPassword;
49  
50      private String scmTag;
51  
52      private boolean scmUseCache;
53  
54      public String save()
55          throws ContinuumException
56      {
57          try
58          {
59              checkModifyProjectInGroupAuthorization( getProjectGroupName() );
60          }
61          catch ( AuthorizationRequiredException e )
62          {
63              return REQUIRES_AUTHORIZATION;
64          }
65  
66          project = getProject( projectId );
67  
68          project.setName( name );
69  
70          project.setVersion( version );
71  
72          project.setScmUrl( scmUrl );
73  
74          project.setScmUseCache( scmUseCache );
75  
76          project.setScmUsername( scmUsername );
77  
78          project.setScmPassword( scmPassword );
79  
80          project.setScmTag( scmTag );
81  
82          getContinuum().updateProject( project );
83  
84          AuditLog event = new AuditLog( "Project id=" + projectId, AuditLogConstants.MODIFY_PROJECT );
85          event.setCategory( AuditLogConstants.PROJECT );
86          event.setCurrentUser( getPrincipal() );
87          event.log();
88  
89          return SUCCESS;
90      }
91  
92      public String edit()
93          throws ContinuumException
94      {
95          try
96          {
97              checkModifyProjectInGroupAuthorization( getProjectGroupName() );
98          }
99          catch ( AuthorizationRequiredException e )
100         {
101             return REQUIRES_AUTHORIZATION;
102         }
103 
104         project = getProject( projectId );
105 
106         name = project.getName();
107 
108         version = project.getVersion();
109 
110         scmUrl = project.getScmUrl();
111 
112         scmUsername = project.getScmUsername();
113 
114         scmPassword = project.getScmPassword();
115 
116         scmUseCache = project.isScmUseCache();
117 
118         scmTag = project.getScmTag();
119 
120         return SUCCESS;
121     }
122 
123     private Project getProject( int projectId )
124         throws ContinuumException
125     {
126         return getContinuum().getProject( projectId );
127     }
128 
129     public int getProjectId()
130     {
131         return projectId;
132     }
133 
134     public void setProjectId( int projectId )
135     {
136         this.projectId = projectId;
137     }
138 
139     public String getName()
140     {
141         return name;
142     }
143 
144     public void setName( String name )
145     {
146         this.name = name;
147     }
148 
149     public String getVersion()
150     {
151         return version;
152     }
153 
154     public void setVersion( String version )
155     {
156         this.version = version;
157     }
158 
159     public String getScmUrl()
160     {
161         return scmUrl;
162     }
163 
164     public void setScmUrl( String scmUrl )
165     {
166         this.scmUrl = scmUrl;
167     }
168 
169     public String getScmUsername()
170     {
171         return scmUsername;
172     }
173 
174     public void setScmUsername( String scmUsername )
175     {
176         this.scmUsername = scmUsername;
177     }
178 
179     public String getScmPassword()
180     {
181         return scmPassword;
182     }
183 
184     public void setScmPassword( String scmPassword )
185     {
186         this.scmPassword = scmPassword;
187     }
188 
189     public String getScmTag()
190     {
191         return scmTag;
192     }
193 
194     public void setScmTag( String scmTag )
195     {
196         this.scmTag = scmTag;
197     }
198 
199     public Project getProject()
200     {
201         return project;
202     }
203 
204     public void setScmUseCache( boolean scmUseCache )
205     {
206         this.scmUseCache = scmUseCache;
207     }
208 
209     public boolean isScmUseCache()
210     {
211         return scmUseCache;
212     }
213 
214     public String getProjectGroupName()
215         throws ContinuumException
216     {
217         return getProject( projectId ).getProjectGroup().getName();
218     }
219 }