2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.services
.impl
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.dao
.process
.SlcExecutionDao
;
23 import org
.argeo
.slc
.msg
.process
.SlcExecutionStatusRequest
;
24 import org
.argeo
.slc
.msg
.process
.SlcExecutionStepsRequest
;
25 import org
.argeo
.slc
.process
.SlcExecution
;
26 import org
.argeo
.slc
.process
.SlcExecutionStep
;
27 import org
.argeo
.slc
.services
.SlcExecutionService
;
29 public class SlcExecutionServiceImpl
implements SlcExecutionService
{
30 private final Log log
= LogFactory
.getLog(getClass());
32 private final SlcExecutionDao slcExecutionDao
;
34 public SlcExecutionServiceImpl(SlcExecutionDao slcExecutionDao
) {
35 this.slcExecutionDao
= slcExecutionDao
;
38 public void newExecution(SlcExecution slcExecutionMsg
) {
39 SlcExecution slcExecutionPersisted
= slcExecutionDao
40 .getSlcExecution(slcExecutionMsg
.getUuid());
41 if (slcExecutionPersisted
== null) {
42 if (log
.isTraceEnabled())
43 log
.trace("Creating SLC execution #"
44 + slcExecutionMsg
.getUuid());
46 slcExecutionDao
.create(slcExecutionMsg
);
48 throw new SlcException(
49 "There is already an SlcExecution registered with id "
50 + slcExecutionMsg
.getUuid());
51 // if (log.isTraceEnabled())
52 // log.trace("Updating SLC execution #"
53 // + slcExecutionMsg.getUuid());
55 // slcExecutionDao.merge(slcExecutionMsg);
59 public void updateStatus(SlcExecutionStatusRequest msg
) {
60 SlcExecution slcExecution
= slcExecutionDao
.getSlcExecution(msg
61 .getSlcExecutionUuid());
62 if (slcExecution
== null)
63 throw new SlcException("Could not find SLC execution #"
64 + msg
.getSlcExecutionUuid());
66 slcExecution
.setStatus(msg
.getNewStatus());
68 if (msg
.getNewStatus().equals(SlcExecution
.STATUS_FINISHED
))
69 slcExecution
.getSteps().add(
70 new SlcExecutionStep(SlcExecutionStep
.TYPE_END
,
71 "Process finished."));
73 if (log
.isTraceEnabled())
74 log
.trace("Updating status for SLC execution #"
75 + slcExecution
.getUuid() + " to status "
76 + msg
.getNewStatus());
78 slcExecutionDao
.update(slcExecution
);
81 public void addSteps(SlcExecutionStepsRequest msg
) {
82 slcExecutionDao
.addSteps(msg
.getSlcExecutionUuid(), msg
.getSteps());