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 org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  31 import org.onap.appc.dg.common.OutputMessagePlugin;
 
  32 import org.onap.appc.exceptions.APPCException;
 
  34 import static org.apache.commons.lang3.StringUtils.isEmpty;
 
  36 public class OutputMessagePluginImpl implements OutputMessagePlugin {
 
  39     public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
 
  40         String errorDescription, eventDescription;
 
  42         //making output.status.message
 
  43         errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
 
  44         eventDescription = params.get(Constants.EVENT_MESSAGE);
 
  46         addToContextIfNotContains(errorDescription , eventDescription, ctx);
 
  48         //making event-message
 
  50         if (!isEmpty(eventDescription)) {
 
  51             ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
 
  53             ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
 
  57     public static void addToContextIfNotContains(String errorDescription, String eventDescription, SvcLogicContext ctx) {
 
  58         if (!isEmpty(errorDescription)){
 
  59             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
 
  60                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription);
 
  61             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(errorDescription)) {
 
  62                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + errorDescription);
 
  65         if (!isEmpty(eventDescription)){
 
  66             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
 
  67                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
 
  68             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
 
  69                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);