]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceImpl.java
56ad0ac2180c2267afae4c2857b364f129d52544
[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 java.util.ArrayList;
20 import java.util.List;
21
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;
31
32 public class SlcExecutionServiceImpl implements SlcExecutionService {
33 private final Log log = LogFactory.getLog(getClass());
34
35 private final SlcExecutionDao slcExecutionDao;
36
37 public SlcExecutionServiceImpl(SlcExecutionDao slcExecutionDao) {
38 this.slcExecutionDao = slcExecutionDao;
39 }
40
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());
48
49 slcExecutionDao.create(slcExecutionMsg);
50 } else {
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());
57 //
58 // slcExecutionDao.merge(slcExecutionMsg);
59 }
60 }
61
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());
68
69 slcExecution.setStatus(msg.getNewStatus());
70
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);
76 }
77
78 if (log.isTraceEnabled())
79 log.trace("Updating status for SLC execution #"
80 + slcExecution.getUuid() + " to status "
81 + msg.getNewStatus());
82
83 slcExecutionDao.update(slcExecution);
84 }
85
86 public void addSteps(SlcExecutionStepsRequest msg) {
87 slcExecutionDao.addSteps(msg.getSlcExecutionUuid(), msg.getSteps());
88 }
89
90 }