2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.dg.common.impl;
27 import static org.apache.commons.lang3.StringUtils.isEmpty;
30 import org.onap.appc.dg.common.OutputMessagePlugin;
31 import org.onap.appc.exceptions.APPCException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 public class OutputMessagePluginImpl implements OutputMessagePlugin {
37 public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
38 String errorDescription;
39 String eventDescription;
41 //making output.status.message
42 errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
43 eventDescription = params.get(Constants.EVENT_MESSAGE);
45 addToContextIfNotContains(errorDescription, eventDescription, ctx);
47 //making event-message
49 if (!isEmpty(eventDescription)) {
50 ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
52 ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
56 private static void addToContextIfNotContains(String errorDescription, String eventDescription,
57 SvcLogicContext ctx) {
58 if (!isEmpty(errorDescription)) {
59 updateContext(errorDescription, ctx);
61 if (!isEmpty(eventDescription)) {
62 updateContext(eventDescription, ctx);
66 private static void updateContext(String eventDescription, SvcLogicContext ctx) {
67 if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
68 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
69 } else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
70 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE,
71 ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);