Change to CCSDK and ODL Carbon
[appc.git] / appc-dg / appc-dg-shared / appc-dg-common / src / main / java / org / openecomp / appc / dg / common / impl / OutputMessagePluginImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.dg.common.impl;
26
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28
29 import java.util.Map;
30
31 import org.openecomp.appc.dg.common.OutputMessagePlugin;
32 import org.openecomp.appc.exceptions.APPCException;
33
34 import static org.apache.commons.lang3.StringUtils.isEmpty;
35
36 public class OutputMessagePluginImpl implements OutputMessagePlugin {
37
38     @Override
39     public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
40         String errorDescription, eventDescription;
41
42         //making output.status.message
43         errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
44         eventDescription = params.get(Constants.EVENT_MESSAGE);
45
46         addToContextIfNotContains(errorDescription , eventDescription, ctx);
47
48         //making event-message
49
50         if (!isEmpty(eventDescription)) {
51             ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
52         } else {
53             ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
54         }
55     }
56
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);
63             }
64         }
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);
70             }
71         }
72     }
73 }