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.onap.so.adapters.appc.orchestrator.client.StatusCategory;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class ApplicationControllerCallback<T> implements ResponseHandler<T> {
34 private static final Logger logger = LoggerFactory.getLogger(ApplicationControllerCallback.class);
36 private final ExternalTask externalTask;
37 private final ExternalTaskService externalTaskService;
38 private final ApplicationControllerSupport appCSupport;
40 public ApplicationControllerCallback(ExternalTask externalTask, ExternalTaskService externalTaskService,
41 ApplicationControllerSupport appCSupport) {
42 this.externalTask = externalTask;
43 this.externalTaskService = externalTaskService;
44 this.appCSupport = appCSupport;
48 public void onResponse(T response) {
49 logger.info("ON RESPONSE IN CALLBACK");
51 Status status = appCSupport.getStatusFromGenericResponse(response);
53 logger.info("Status code is: " + status.getCode());
54 logger.info("Status message is: " + status.getMessage());
56 if (appCSupport.getFinalityOf(status)) {
57 logger.debug("Obtained final status, complete the task");
58 completeExternalTask(externalTask, externalTaskService, status);
60 logger.debug("Intermediate status, continue the task");
65 public void onException(AppcClientException exception) {
67 logger.info("ON EXCEPTION IN CALLBACK");
68 logger.info("Exception from APPC: " + exception.getMessage());
69 Status exceptionStatus = appCSupport.buildStatusFromAppcException(exception);
70 completeExternalTask(externalTask, externalTaskService, exceptionStatus);
73 private void completeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService,
76 if (appCSupport.getCategoryOf(status).equals(StatusCategory.NORMAL)) {
77 externalTaskService.complete(externalTask);
78 logger.debug("The External Task Id: {} Successful", externalTask.getId());
80 logger.debug("The External Task Id: {} Failed", externalTask.getId());
81 externalTaskService.handleBpmnError(externalTask, "MSOWorkflowException", status.getMessage());