c70c754ca80ea1b97bb429ffc72c318871f29c79
[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  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.dg.common.impl;
23
24 import org.openecomp.sdnc.sli.SvcLogicContext;
25
26 import java.util.Map;
27
28 import org.openecomp.appc.dg.common.OutputMessagePlugin;
29 import org.openecomp.appc.exceptions.APPCException;
30
31 import static org.apache.commons.lang3.StringUtils.isEmpty;
32
33 public class OutputMessagePluginImpl implements OutputMessagePlugin {
34
35     @Override
36     public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
37         String errorDescription, eventDescription;
38
39         //making output.status.message
40         errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
41         eventDescription = params.get(Constants.EVENT_MESSAGE);
42
43         addToContextIfNotContains(errorDescription , eventDescription, ctx);
44
45         //making event-message
46
47         if (!isEmpty(eventDescription)) {
48             ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
49         } else {
50             ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
51         }
52     }
53
54     public static void addToContextIfNotContains(String errorDescription, String eventDescription, SvcLogicContext ctx) {
55         if (!isEmpty(errorDescription)){
56             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
57                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription);
58             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(errorDescription)) {
59                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + errorDescription);
60             }
61         }
62         if (!isEmpty(eventDescription)){
63             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
64                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
65             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
66                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);
67             }
68         }
69     }
70 }