View Javadoc

1   package org.apache.continuum.buildqueue;
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.dao.BuildQueueDao;
23  import org.apache.continuum.dao.ScheduleDao;
24  import org.apache.maven.continuum.model.project.BuildQueue;
25  import org.apache.maven.continuum.model.project.Schedule;
26  import org.apache.maven.continuum.store.ContinuumStoreException;
27  
28  import java.util.List;
29  import javax.annotation.Resource;
30  
31  /**
32   * DefaultBuildQueueService
33   *
34   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
35   */
36  public class DefaultBuildQueueService
37      implements BuildQueueService
38  {
39      @Resource
40      private BuildQueueDao buildQueueDao;
41  
42      @Resource
43      private ScheduleDao scheduleDao;
44  
45      public BuildQueue addBuildQueue( BuildQueue buildQueue )
46          throws BuildQueueServiceException
47      {
48          try
49          {
50              return buildQueueDao.addBuildQueue( buildQueue );
51          }
52          catch ( ContinuumStoreException e )
53          {
54              throw new BuildQueueServiceException( e );
55          }
56      }
57  
58      public List<BuildQueue> getAllBuildQueues()
59          throws BuildQueueServiceException
60      {
61          try
62          {
63              return buildQueueDao.getAllBuildQueues();
64          }
65          catch ( ContinuumStoreException e )
66          {
67              throw new BuildQueueServiceException( e );
68          }
69      }
70  
71      public BuildQueue getBuildQueue( int buildQueueId )
72          throws BuildQueueServiceException
73      {
74          try
75          {
76              return buildQueueDao.getBuildQueue( buildQueueId );
77          }
78          catch ( ContinuumStoreException e )
79          {
80              throw new BuildQueueServiceException( e );
81          }
82      }
83  
84      public BuildQueue getBuildQueueByName( String buildQueueName )
85          throws BuildQueueServiceException
86      {
87          try
88          {
89              return buildQueueDao.getBuildQueueByName( buildQueueName );
90          }
91          catch ( ContinuumStoreException e )
92          {
93              throw new BuildQueueServiceException( e );
94          }
95      }
96  
97      public void removeBuildQueue( BuildQueue buildQueue )
98          throws BuildQueueServiceException
99      {
100         try
101         {
102             // detach from schedule(s) first
103             List<Schedule> schedules = scheduleDao.getAllSchedulesByName();
104             for ( Schedule schedule : schedules )
105             {
106                 List<BuildQueue> buildQueues = schedule.getBuildQueues();
107                 if ( buildQueues.contains( buildQueue ) )
108                 {
109                     buildQueues.remove( buildQueue );
110                 }
111                 schedule.setBuildQueues( buildQueues );
112 
113                 scheduleDao.updateSchedule( schedule );
114             }
115 
116             buildQueueDao.removeBuildQueue( buildQueue );
117         }
118         catch ( ContinuumStoreException e )
119         {
120             throw new BuildQueueServiceException( e );
121         }
122     }
123 
124     public BuildQueue updateBuildQueue( BuildQueue buildQueue )
125         throws BuildQueueServiceException
126     {
127         try
128         {
129             return buildQueueDao.storeBuildQueue( buildQueue );
130         }
131         catch ( ContinuumStoreException e )
132         {
133             throw new BuildQueueServiceException( e );
134         }
135     }
136 
137     public BuildQueueDao getBuildQueueDao()
138     {
139         return buildQueueDao;
140     }
141 
142     public void setBuildQueueDao( BuildQueueDao buildQueueDao )
143     {
144         this.buildQueueDao = buildQueueDao;
145     }
146 
147     public ScheduleDao getScheduleDao()
148     {
149         return scheduleDao;
150     }
151 
152     public void setScheduleDao( ScheduleDao scheduleDao )
153     {
154         this.scheduleDao = scheduleDao;
155     }
156 
157 }