Change the header to SO
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / LogTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.core;
22
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.camunda.bpm.engine.delegate.Expression;
25
26 import org.openecomp.mso.logger.MsoAlarmLogger;
27 import org.openecomp.mso.logger.MsoLogger;
28
29 /**
30  * Logs a text message.  The text may contain variable references.
31  * For example:<br/><br/>
32  * &nbsp;&nbsp;&nbsp;&nbsp;name=$name, address=$address
33  * <p>
34  * Required fields:<br/><br/>
35  * &nbsp;&nbsp;&nbsp;&nbsp;text: The text to log<br/>
36  * Optional fields:<br/><br/>
37  * &nbsp;&nbsp;&nbsp;&nbsp;level: The log level (TRACE, DEBUG, INFO, WARN, ERROR)<br/>
38  */
39 public class LogTask extends BaseTask {
40         
41
42         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
43         private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
44
45         private Expression text;
46         private Expression level;
47         
48         public void execute(DelegateExecution execution) throws Exception {
49                 String theText = getStringField(text, execution, "text");
50                                 
51
52                 
53                         StringBuilder out = new StringBuilder();
54                         StringBuilder var = new StringBuilder();
55                         boolean inVar = false;
56
57                         int pos = 0;
58                         int len = theText.length();
59
60                         while (pos < len) {
61                                 char c = theText.charAt(pos++);
62
63                                 if (inVar && !Character.isLetterOrDigit(c) && c != '_') {
64                                         if (var.length() > 0) {
65                                                 Object value = execution.getVariable(var.toString());
66
67                                                 if (value != null) {
68                                                         out.append(value.toString());
69                                                 }
70
71                                                 var.setLength(0);
72                                         }
73
74                                         inVar = false;
75                                 }
76
77                                 if (c == '$') {
78                                         inVar = true;
79                                 } else {
80                                         if (inVar) {
81                                                 var.append(c);
82                                         } else {
83                                                 out.append(c);
84                                         }
85                                 }
86                         }
87
88                         if (inVar && var.length() > 0) {
89                                 Object value = execution.getVariable(var.toString());
90                                 if (value != null) {
91                                         out.append(value.toString());
92                                 }
93                         }
94
95                         
96                 
97         }
98 }