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.buildmanager.BuildManagerException;
23  import org.apache.continuum.buildmanager.BuildsManager;
24  import org.apache.continuum.taskqueue.BuildProjectTask;
25  import org.apache.maven.continuum.model.project.BuildResult;
26  import org.apache.maven.continuum.project.ContinuumProjectState;
27  
28  import java.util.Map;
29  import java.util.Set;
30  
31  /**
32   * @author <a href="mailto:olamy@apache.org">olamy</a>
33   * @version $Id: AbstractBuildAction.java 1372267 2012-08-13 05:47:30Z brett $
34   * @since 5 oct. 07
35   */
36  public abstract class AbstractBuildAction
37      extends ContinuumConfirmAction
38  {
39      private int projectId;
40  
41      private boolean canDelete = true;
42  
43      protected boolean canRemoveBuildResult( BuildResult buildResult )
44          throws BuildManagerException
45      {
46          BuildsManager buildsManager = getContinuum().getBuildsManager();
47  
48          Map<String, BuildProjectTask> currentBuilds = buildsManager.getCurrentBuilds();
49          Set<String> keySet = currentBuilds.keySet();
50          for ( String key : keySet )
51          {
52              BuildProjectTask buildProjectTask = currentBuilds.get( key );
53              if ( buildProjectTask != null && buildResult != null )
54              {
55                  return !( buildResult.getState() == ContinuumProjectState.BUILDING &&
56                      ( buildProjectTask.getBuildDefinitionId() == buildResult.getBuildDefinition().getId() &&
57                          buildProjectTask.getProjectId() == this.getProjectId() ) );
58              }
59          }
60          return true;
61      }
62  
63      public int getProjectId()
64      {
65          return projectId;
66      }
67  
68      public void setProjectId( int projectId )
69      {
70          this.projectId = projectId;
71      }
72  
73      public boolean isCanDelete()
74      {
75          return canDelete;
76      }
77  
78      public void setCanDelete( boolean canDelete )
79      {
80          this.canDelete = canDelete;
81      }
82  }