c5ee88fe15ef6765973e19b02744d79465171a59
[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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.dg.common.impl;
24
25 import org.openecomp.sdnc.sli.SvcLogicContext;
26
27 import java.util.Map;
28
29 import org.openecomp.appc.dg.common.OutputMessagePlugin;
30 import org.openecomp.appc.exceptions.APPCException;
31
32 import static org.apache.commons.lang3.StringUtils.isEmpty;
33
34 public class OutputMessagePluginImpl implements OutputMessagePlugin {
35
36     @Override
37     public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
38         String errorDescription, eventDescription;
39
40         //making output.status.message
41         errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
42         eventDescription = params.get(Constants.EVENT_MESSAGE);
43
44         addToContextIfNotContains(errorDescription , eventDescription, ctx);
45
46         //making event-message
47
48         if (!isEmpty(eventDescription)) {
49             ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
50         } else {
51             ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
52         }
53     }
54
55     public static void addToContextIfNotContains(String errorDescription, String eventDescription, SvcLogicContext ctx) {
56         if (!isEmpty(errorDescription)){
57             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
58                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription);
59             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(errorDescription)) {
60                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + errorDescription);
61             }
62         }
63         if (!isEmpty(eventDescription)){
64             if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
65                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
66             }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
67                 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);
68             }
69         }
70     }
71 }