1 package org.onap.vid.job.command;
3 import org.apache.commons.lang3.ObjectUtils;
4 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
5 import org.onap.vid.job.Job;
6 import org.onap.vid.job.JobCommand;
7 import org.onap.vid.job.NextCommand;
8 import org.onap.vid.job.impl.JobSharedData;
9 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
11 import javax.inject.Inject;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 public abstract class BaseWatchingCommand extends BaseInstantiationCommand implements JobCommand {
19 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseWatchingCommand.class);
22 protected AsyncInstantiationBusinessLogic asyncInstantiationBL;
25 private WatchChildrenJobsBL watchChildrenJobsBL;
27 private List<String> childrenJobsIds;
29 protected boolean isService;
31 public BaseWatchingCommand() {}
33 public BaseWatchingCommand(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
34 init(sharedData, childrenJobsIds, isService);
38 public NextCommand call() {
39 Job.JobStatus cumulativeJobsStatus = watchChildrenJobsBL.cumulateJobStatus(
40 watchChildrenJobsBL.retrieveChildrenJobsStatus(childrenJobsIds),
41 Job.JobStatus.COMPLETED);
42 return getNextCommand(cumulativeJobsStatus);
45 protected abstract NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus);
48 public BaseWatchingCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
51 (List<String>) commandData.get("childrenJobs"),
52 (boolean) commandData.get("isService")
56 protected BaseWatchingCommand init(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
57 super.init(sharedData);
58 this.childrenJobsIds = ObjectUtils.defaultIfNull(childrenJobsIds, new ArrayList<>());
59 this.isService = isService;
64 public Map<String, Object> getData() {
65 Map<String, Object> data = new HashMap<>();
66 data.put("childrenJobs", childrenJobsIds);
67 data.put("isService", isService);