2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.job.command;
23 import org.apache.commons.lang3.ObjectUtils;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.vid.job.Job;
26 import org.onap.vid.job.JobCommand;
27 import org.onap.vid.job.NextCommand;
28 import org.onap.vid.job.impl.JobSharedData;
29 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
31 import javax.inject.Inject;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
37 public abstract class BaseWatchingCommand extends BaseInstantiationCommand implements JobCommand {
39 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseWatchingCommand.class);
42 protected AsyncInstantiationBusinessLogic asyncInstantiationBL;
45 private WatchChildrenJobsBL watchChildrenJobsBL;
47 private List<String> childrenJobsIds;
49 protected boolean isService;
51 public BaseWatchingCommand() {}
53 public BaseWatchingCommand(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
54 init(sharedData, childrenJobsIds, isService);
58 public NextCommand call() {
59 Job.JobStatus cumulativeJobsStatus = watchChildrenJobsBL.cumulateJobStatus(
60 watchChildrenJobsBL.retrieveChildrenJobsStatus(childrenJobsIds),
61 Job.JobStatus.COMPLETED);
62 return getNextCommand(cumulativeJobsStatus);
65 protected abstract NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus);
68 public BaseWatchingCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
71 (List<String>) commandData.get("childrenJobs"),
72 (boolean) commandData.get("isService")
76 protected BaseWatchingCommand init(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
77 super.init(sharedData);
78 this.childrenJobsIds = ObjectUtils.defaultIfNull(childrenJobsIds, new ArrayList<>());
79 this.isService = isService;
84 public Map<String, Object> getData() {
85 Map<String, Object> data = new HashMap<>();
86 data.put("childrenJobs", childrenJobsIds);
87 data.put("isService", isService);