View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.continuum.web.action;
20  
21  import java.util.Map;
22  import java.util.Set;
23  
24  import org.apache.continuum.buildmanager.BuildManagerException;
25  import org.apache.continuum.buildmanager.BuildsManager;
26  import org.apache.continuum.taskqueue.BuildProjectTask;
27  import org.apache.maven.continuum.model.project.BuildResult;
28  import org.apache.maven.continuum.project.ContinuumProjectState;
29  
30  /**
31   * @author <a href="mailto:olamy@apache.org">olamy</a>
32   * @version $Id: AbstractBuildAction.java 822971 2009-10-08 00:34:21Z ctan $
33   * @since 5 oct. 07
34   */
35  public abstract class AbstractBuildAction
36      extends ContinuumConfirmAction
37  {
38      private int projectId;
39  
40      private boolean canDelete = true;
41  
42      protected boolean canRemoveBuildResult( BuildResult buildResult )
43          throws BuildManagerException
44      {
45          BuildsManager buildsManager = getContinuum().getBuildsManager();
46  
47          Map<String, BuildProjectTask> currentBuilds = buildsManager.getCurrentBuilds();
48          Set<String> keySet = currentBuilds.keySet();
49          for ( String key : keySet )
50          {
51              BuildProjectTask buildProjectTask = currentBuilds.get( key );
52              if ( buildProjectTask != null && buildResult != null )
53              {
54                  return !( buildResult.getState() == ContinuumProjectState.BUILDING &&
55                      ( buildProjectTask.getBuildDefinitionId() == buildResult.getBuildDefinition().getId() &&
56                          buildProjectTask.getProjectId() == this.getProjectId() ) );
57              }
58          }
59          return true;
60      }
61  
62      public int getProjectId()
63      {
64          return projectId;
65      }
66  
67      public void setProjectId( int projectId )
68      {
69          this.projectId = projectId;
70      }
71  
72      public boolean isCanDelete()
73      {
74          return canDelete;
75      }
76  
77      public void setCanDelete( boolean canDelete )
78      {
79          this.canDelete = canDelete;
80      }
81  }