]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceImpl.java
remove a warning
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / services / impl / SlcExecutionServiceImpl.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.services.impl;
18
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;
28
29 public class SlcExecutionServiceImpl implements SlcExecutionService {
30 private final Log log = LogFactory.getLog(getClass());
31
32 private final SlcExecutionDao slcExecutionDao;
33
34 public SlcExecutionServiceImpl(SlcExecutionDao slcExecutionDao) {
35 this.slcExecutionDao = slcExecutionDao;
36 }
37
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());
45
46 slcExecutionDao.create(slcExecutionMsg);
47 } else {
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());
54 //
55 // slcExecutionDao.merge(slcExecutionMsg);
56 }
57 }
58
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());
65
66 slcExecution.setStatus(msg.getNewStatus());
67
68 if (msg.getNewStatus().equals(SlcExecution.STATUS_FINISHED))
69 slcExecution.getSteps().add(
70 new SlcExecutionStep(SlcExecutionStep.TYPE_END,
71 "Process finished."));
72
73 if (log.isTraceEnabled())
74 log.trace("Updating status for SLC execution #"
75 + slcExecution.getUuid() + " to status "
76 + msg.getNewStatus());
77
78 slcExecutionDao.update(slcExecution);
79 }
80
81 public void addSteps(SlcExecutionStepsRequest msg) {
82 slcExecutionDao.addSteps(msg.getSlcExecutionUuid(), msg.getSteps());
83 }
84
85 }