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 java
.util
.ArrayList
;
20 import java
.util
.List
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.argeo
.slc
.dao
.process
.SlcExecutionDao
;
26 import org
.argeo
.slc
.msg
.process
.SlcExecutionStatusRequest
;
27 import org
.argeo
.slc
.msg
.process
.SlcExecutionStepsRequest
;
28 import org
.argeo
.slc
.process
.SlcExecution
;
29 import org
.argeo
.slc
.process
.SlcExecutionStep
;
30 import org
.argeo
.slc
.services
.SlcExecutionService
;
32 public class SlcExecutionServiceImpl
implements SlcExecutionService
{
33 private final Log log
= LogFactory
.getLog(getClass());
35 private final SlcExecutionDao slcExecutionDao
;
37 public SlcExecutionServiceImpl(SlcExecutionDao slcExecutionDao
) {
38 this.slcExecutionDao
= slcExecutionDao
;
41 public void newExecution(SlcExecution slcExecutionMsg
) {
42 SlcExecution slcExecutionPersisted
= slcExecutionDao
43 .getSlcExecution(slcExecutionMsg
.getUuid());
44 if (slcExecutionPersisted
== null) {
45 if (log
.isTraceEnabled())
46 log
.trace("Creating SLC execution #"
47 + slcExecutionMsg
.getUuid());
49 slcExecutionDao
.create(slcExecutionMsg
);
51 throw new SlcException(
52 "There is already an SlcExecution registered with id "
53 + slcExecutionMsg
.getUuid());
54 // if (log.isTraceEnabled())
55 // log.trace("Updating SLC execution #"
56 // + slcExecutionMsg.getUuid());
58 // slcExecutionDao.merge(slcExecutionMsg);
62 public void updateStatus(SlcExecutionStatusRequest msg
) {
63 SlcExecution slcExecution
= slcExecutionDao
.getSlcExecution(msg
64 .getSlcExecutionUuid());
65 if (slcExecution
== null)
66 throw new SlcException("Could not find SLC execution #"
67 + msg
.getSlcExecutionUuid());
69 slcExecution
.setStatus(msg
.getNewStatus());
71 if (msg
.getNewStatus().equals(SlcExecution
.STATUS_FINISHED
)) {
72 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
73 steps
.add(new SlcExecutionStep(SlcExecutionStep
.END
,
74 "Process finished."));
75 slcExecutionDao
.addSteps(slcExecution
.getUuid(), steps
);
78 if (log
.isTraceEnabled())
79 log
.trace("Updating status for SLC execution #"
80 + slcExecution
.getUuid() + " to status "
81 + msg
.getNewStatus());
83 slcExecutionDao
.update(slcExecution
);
86 public void addSteps(SlcExecutionStepsRequest msg
) {
87 slcExecutionDao
.addSteps(msg
.getSlcExecutionUuid(), msg
.getSteps());