2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.so.adapters.appc.orchestrator.client;
23 import org.camunda.bpm.client.task.ExternalTask;
24 import org.camunda.bpm.client.task.ExternalTaskService;
25 import org.onap.appc.client.lcm.api.ResponseHandler;
26 import org.onap.appc.client.lcm.exceptions.AppcClientException;
27 import org.onap.appc.client.lcm.model.Status;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class ApplicationControllerCallback<T> implements ResponseHandler<T> {
33 private static final Logger logger = LoggerFactory.getLogger(ApplicationControllerCallback.class);
35 private final ExternalTask externalTask;
36 private final ExternalTaskService externalTaskService;
37 private final ApplicationControllerSupport appCSupport;
39 public ApplicationControllerCallback(ExternalTask externalTask, ExternalTaskService externalTaskService,
40 ApplicationControllerSupport appCSupport) {
41 this.externalTask = externalTask;
42 this.externalTaskService = externalTaskService;
43 this.appCSupport = appCSupport;
47 public void onResponse(T response) {
48 logger.info("ON RESPONSE IN CALLBACK");
50 Status status = appCSupport.getStatusFromGenericResponse(response);
52 logger.info("Status code is: " + status.getCode());
53 logger.info("Status message is: " + status.getMessage());
55 if (appCSupport.getFinalityOf(status)) {
56 logger.debug("Obtained final status, complete the task");
57 completeExternalTask(externalTask, externalTaskService, status);
59 logger.debug("Intermediate status, continue the task");
64 public void onException(AppcClientException exception) {
66 logger.info("ON EXCEPTION IN CALLBACK");
67 logger.info("Exception from APPC: " + exception.getMessage());
68 Status exceptionStatus = appCSupport.buildStatusFromAppcException(exception);
69 completeExternalTask(externalTask, externalTaskService, exceptionStatus);
72 private void completeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService,
75 if (appCSupport.getCategoryOf(status).equals(StatusCategory.NORMAL)) {
76 externalTaskService.complete(externalTask);
77 logger.debug("The External Task Id: {} Successful", externalTask.getId());
79 logger.debug("The External Task Id: {} Failed", externalTask.getId());
80 externalTaskService.handleBpmnError(externalTask, "MSOWorkflowException", status.getMessage());