2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.sdnc.sli.recording;
25 import java.io.FileWriter;
26 import java.io.PrintWriter;
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
29 import java.util.Date;
31 import java.util.TimeZone;
33 import org.openecomp.sdnc.sli.ConfigurationException;
34 import org.openecomp.sdnc.sli.SvcLogicException;
35 import org.openecomp.sdnc.sli.SvcLogicRecorder;
38 public class FileRecorder implements SvcLogicRecorder {
41 public void record(Map<String, String> parmMap) throws SvcLogicException {
43 String fileName = parmMap.get("file");
46 throw new ConfigurationException("No file parameter specified");
49 String record = parmMap.get("record");
52 String delimiter = parmMap.get("delimiter");
53 if (delimiter == null)
59 boolean moreFields = true;
62 String curField = parmMap.get("field"+idx++);
73 record = record + curField + delimiter;
80 throw new ConfigurationException("No record/fields passed in record node");
83 File recordFile = new File(fileName);
84 PrintWriter recPrinter = null;
85 Date now = new Date();
87 TimeZone tz = TimeZone.getTimeZone("UTC");
88 DateFormat dateFmt = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss:SS'+00:00'");
89 dateFmt.setTimeZone(tz);
90 if (record.indexOf("__TIMESTAMP__") != -1)
92 record = record.replaceFirst("__TIMESTAMP__", dateFmt.format(now));
98 recPrinter = new PrintWriter(new FileWriter(recordFile, true));
99 recPrinter.println(record);
103 throw new SvcLogicException("Cannot write record to file", e);
107 if (recPrinter != null)