diff options
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java')
-rw-r--r-- | common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java | 288 |
1 files changed, 144 insertions, 144 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java b/common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java index f57695de99..d46ead42a9 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,8 @@ import org.openecomp.sdc.common.config.EcompErrorEnum; import org.openecomp.sdc.common.config.EcompErrorEnum.AlarmSeverity; import org.openecomp.sdc.common.config.EcompErrorEnum.ErrorType; import org.openecomp.sdc.common.config.EcompErrorLogUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileWriter; @@ -33,200 +35,198 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class GenerateEcompErrorsCsv { - private static Logger log = LoggerFactory.getLogger(GenerateEcompErrorsCsv.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GenerateEcompErrorsCsv.class); - private static String DATE_FORMAT = "dd-M-yyyy-hh-mm-ss"; + private static final String DATE_FORMAT = "dd-M-yyyy-hh-mm-ss"; - private static String NEW_LINE = System.getProperty("line.separator"); + private static final String NEW_LINE = System.getProperty("line.separator"); - private static void usage() { - System.out.println("java org.openecomp.sdc.common.config.generation.GenerateEcompErrorsCsv <target folder>"); - System.exit(1); - } + private static void usage() { + System.out.println("java org.openecomp.sdc.common.config.generation.GenerateEcompErrorsCsv <target folder>"); + System.exit(1); + } - public static void main(String[] args) { + public static void main(String[] args) { - String targetFolder = "target"; - if (args.length > 1) { - targetFolder = args[0]; - } + String targetFolder = "target"; + if (args.length > 1) { + targetFolder = args[0]; + } - GenerateEcompErrorsCsv ecompErrorsCsv = new GenerateEcompErrorsCsv(); + GenerateEcompErrorsCsv ecompErrorsCsv = new GenerateEcompErrorsCsv(); - ecompErrorsCsv.generateEcompErrorsCsvFile(targetFolder, true); - } + ecompErrorsCsv.generateEcompErrorsCsvFile(targetFolder, true); + } - public static class EcompErrorRow { + public static class EcompErrorRow { - String errorName; - String errorCode; - String description; - ErrorType errorType; - AlarmSeverity alarmSeverity; - String cleanErrorCode; - String resolution; + private String errorName; + private String errorCode; + private String description; + private ErrorType errorType; + private AlarmSeverity alarmSeverity; + private String cleanErrorCode; + private String resolution; - public String getErrorName() { - return errorName; - } + public String getErrorName() { + return errorName; + } - public void setErrorName(String errorName) { - this.errorName = errorName; - } + public void setErrorName(String errorName) { + this.errorName = errorName; + } - public String getErrorCode() { - return errorCode; - } + public String getErrorCode() { + return errorCode; + } - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } - public ErrorType getErrorType() { - return errorType; - } + public ErrorType getErrorType() { + return errorType; + } - public void setErrorType(ErrorType errorType) { - this.errorType = errorType; - } + public void setErrorType(ErrorType errorType) { + this.errorType = errorType; + } - public AlarmSeverity getAlarmSeverity() { - return alarmSeverity; - } + public AlarmSeverity getAlarmSeverity() { + return alarmSeverity; + } - public void setAlarmSeverity(AlarmSeverity alarmSeverity) { - this.alarmSeverity = alarmSeverity; - } + public void setAlarmSeverity(AlarmSeverity alarmSeverity) { + this.alarmSeverity = alarmSeverity; + } - public String getCleanErrorCode() { - return cleanErrorCode; - } + public String getCleanErrorCode() { + return cleanErrorCode; + } - public void setCleanErrorCode(String cleanErrorCode) { - this.cleanErrorCode = cleanErrorCode; - } + public void setCleanErrorCode(String cleanErrorCode) { + this.cleanErrorCode = cleanErrorCode; + } - public String getResolution() { - return resolution; - } + public String getResolution() { + return resolution; + } - public void setResolution(String resolution) { - this.resolution = resolution; - } + public void setResolution(String resolution) { + this.resolution = resolution; + } - } + } - public boolean generateEcompErrorsCsvFile(String targetFolder, boolean addTimeToFileName) { + public boolean generateEcompErrorsCsvFile(String targetFolder, boolean addTimeToFileName) { - targetFolder += File.separator; + targetFolder += File.separator; - boolean result = false; - String dateFormatted = ""; + boolean result = false; + String dateFormatted = ""; - if (addTimeToFileName) { - DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); + if (addTimeToFileName) { + DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); - Date date = new Date(); + Date date = new Date(); - dateFormatted = "." + dateFormat.format(date); + dateFormatted = "." + dateFormat.format(date); - } + } - String outputFile = targetFolder + "ecompErrorCodes" + dateFormatted + ".csv"; + String outputFile = targetFolder + "ecompErrorCodes" + dateFormatted + ".csv"; - try(FileWriter writer = new FileWriter(outputFile)) { + try (FileWriter writer = new FileWriter(outputFile)) { - List<EcompErrorRow> errors = new ArrayList<>(); + List<EcompErrorRow> errors = new ArrayList<>(); - for (EcompErrorEnum ecompErrorEnum : EcompErrorEnum.values()) { + for (EcompErrorEnum ecompErrorEnum : EcompErrorEnum.values()) { - EcompErrorRow ecompErrorRow = new EcompErrorRow(); + EcompErrorRow ecompErrorRow = new EcompErrorRow(); - String errorCode = EcompErrorLogUtil.createEcode(ecompErrorEnum); + String errorCode = EcompErrorLogUtil.createEcode(ecompErrorEnum); - EcompErrorEnum clearCodeEnum = ecompErrorEnum.getClearCode(); - String cleanErrorCode = null; - if (clearCodeEnum != null) { - cleanErrorCode = EcompErrorLogUtil.createEcode(clearCodeEnum); - } + EcompErrorEnum clearCodeEnum = ecompErrorEnum.getClearCode(); + String cleanErrorCode = null; + if (clearCodeEnum != null) { + cleanErrorCode = EcompErrorLogUtil.createEcode(clearCodeEnum); + } - ecompErrorRow.setAlarmSeverity(ecompErrorEnum.getAlarmSeverity()); - ecompErrorRow.setCleanErrorCode(cleanErrorCode); - ecompErrorRow.setDescription(ecompErrorEnum.getEcompErrorCode().getDescription()); - ecompErrorRow.setErrorCode(errorCode); - ecompErrorRow.setErrorName(ecompErrorEnum.name().toString()); - ecompErrorRow.setErrorType(ecompErrorEnum.geteType()); - ecompErrorRow.setResolution(ecompErrorEnum.getEcompErrorCode().getResolution()); + ecompErrorRow.setAlarmSeverity(ecompErrorEnum.getAlarmSeverity()); + ecompErrorRow.setCleanErrorCode(cleanErrorCode); + ecompErrorRow.setDescription(ecompErrorEnum.getEcompErrorCode().getDescription()); + ecompErrorRow.setErrorCode(errorCode); + ecompErrorRow.setErrorName(ecompErrorEnum.name().toString()); + ecompErrorRow.setErrorType(ecompErrorEnum.geteType()); + ecompErrorRow.setResolution(ecompErrorEnum.getEcompErrorCode().getResolution()); - errors.add(ecompErrorRow); - } + errors.add(ecompErrorRow); + } - writeHeaders(writer); + writeHeaders(writer); - for (EcompErrorRow ecompErrorRow : errors) { - writer.append(addInvertedCommas(ecompErrorRow.getErrorCode())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getErrorType().toString())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getDescription())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getResolution())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getAlarmSeverity().toString())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getErrorName())); - writer.append(','); - writer.append(addInvertedCommas(ecompErrorRow.getCleanErrorCode())); - writer.append(NEW_LINE); - } + for (EcompErrorRow ecompErrorRow : errors) { + writer.append(addInvertedCommas(ecompErrorRow.getErrorCode())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getErrorType().toString())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getDescription())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getResolution())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getAlarmSeverity().toString())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getErrorName())); + writer.append(','); + writer.append(addInvertedCommas(ecompErrorRow.getCleanErrorCode())); + writer.append(NEW_LINE); + } - result = true; + result = true; - } catch (Exception e) { - log.info("generate Ecomp Errors Csv File failed - {}" , e); - } + } catch (Exception e) { + LOGGER.info("generate Ecomp Errors Csv File failed - {}", e); + } - return result; - } + return result; + } - private void writeHeaders(FileWriter writer) throws IOException { + private void writeHeaders(FileWriter writer) throws IOException { - writer.append("\"ERROR CODE\""); - writer.append(','); - writer.append("\"ERROR TYPE\""); - writer.append(','); - writer.append("\"DESCRIPTION\""); - writer.append(','); - writer.append("\"RESOLUTION\""); - writer.append(','); - writer.append("\"ALARM SEVERITY\""); - writer.append(','); - writer.append("\"ERROR NAME\""); - writer.append(','); - writer.append("\"CLEAN CODE\""); - writer.append(NEW_LINE); - } + writer.append("\"ERROR CODE\""); + writer.append(','); + writer.append("\"ERROR TYPE\""); + writer.append(','); + writer.append("\"DESCRIPTION\""); + writer.append(','); + writer.append("\"RESOLUTION\""); + writer.append(','); + writer.append("\"ALARM SEVERITY\""); + writer.append(','); + writer.append("\"ERROR NAME\""); + writer.append(','); + writer.append("\"CLEAN CODE\""); + writer.append(NEW_LINE); + } - private String addInvertedCommas(String str) { + private String addInvertedCommas(String str) { - if (str == null) { - return "\"\""; - } + if (str == null) { + return "\"\""; + } - return "\"" + str + "\""; - } + return "\"" + str + "\""; + } } |