aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsv.java117
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsvTest.java24
2 files changed, 41 insertions, 100 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 b934ab6679..4f2eb6c5aa 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
@@ -24,9 +24,10 @@ import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.openecomp.sdc.common.config.EcompErrorEnum;
import org.openecomp.sdc.common.config.EcompErrorEnum.AlarmSeverity;
import org.openecomp.sdc.common.config.EcompErrorEnum.ErrorType;
@@ -36,26 +37,26 @@ import org.slf4j.LoggerFactory;
public class GenerateEcompErrorsCsv {
- private static Logger log = LoggerFactory.getLogger(GenerateEcompErrorsCsv.class);
- private static String DATE_FORMAT = "dd-M-yyyy-hh-mm-ss";
- private static String NEW_LINE = System.getProperty("line.separator");
+ private static final Logger log = LoggerFactory.getLogger(GenerateEcompErrorsCsv.class);
+ private static final String DATE_FORMAT = "dd-M-yyyy-hh-mm-ss";
+ private static final String NEW_LINE = System.getProperty("line.separator");
- public boolean generateEcompErrorsCsvFile(String targetFolder, boolean addTimeToFileName) {
+ public boolean generateEcompErrorsCsvFile(String targetFolder, final boolean addTimeToFileName) {
targetFolder += File.separator;
boolean result = false;
String dateFormatted = "";
if (addTimeToFileName) {
- DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
- Date date = new Date();
+ final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+ final Date date = new Date();
dateFormatted = "." + dateFormat.format(date);
}
- String outputFile = targetFolder + "ecompErrorCodes" + dateFormatted + ".csv";
- try (FileWriter writer = new FileWriter(outputFile)) {
- List<EcompErrorRow> errors = new ArrayList<>();
- for (EcompErrorEnum ecompErrorEnum : EcompErrorEnum.values()) {
- EcompErrorRow ecompErrorRow = new EcompErrorRow();
- String errorCode = EcompErrorLogUtil.createEcode(ecompErrorEnum);
- EcompErrorEnum clearCodeEnum = ecompErrorEnum.getClearCode();
+ final String outputFile = targetFolder + "ecompErrorCodes" + dateFormatted + ".csv";
+ try (final FileWriter writer = new FileWriter(outputFile)) {
+ writeHeaders(writer);
+ for (final EcompErrorEnum ecompErrorEnum : EcompErrorEnum.values()) {
+ final EcompErrorRow ecompErrorRow = new EcompErrorRow();
+ final String errorCode = EcompErrorLogUtil.createEcode(ecompErrorEnum);
+ final EcompErrorEnum clearCodeEnum = ecompErrorEnum.getClearCode();
String cleanErrorCode = null;
if (clearCodeEnum != null) {
cleanErrorCode = EcompErrorLogUtil.createEcode(clearCodeEnum);
@@ -67,10 +68,6 @@ public class GenerateEcompErrorsCsv {
ecompErrorRow.setErrorName(ecompErrorEnum.name());
ecompErrorRow.setErrorType(ecompErrorEnum.getEType());
ecompErrorRow.setResolution(ecompErrorEnum.getEcompErrorCode().getResolution());
- errors.add(ecompErrorRow);
- }
- writeHeaders(writer);
- for (EcompErrorRow ecompErrorRow : errors) {
writer.append(addInvertedCommas(ecompErrorRow.getErrorCode()));
writer.append(',');
writer.append(addInvertedCommas(ecompErrorRow.getErrorType().toString()));
@@ -87,13 +84,13 @@ public class GenerateEcompErrorsCsv {
writer.append(NEW_LINE);
}
result = true;
- } catch (Exception e) {
- log.info("generate Ecomp Errors Csv File failed", e);
+ } catch (final Exception e) {
+ log.warn("generate Ecomp Errors Csv File failed", e);
}
return result;
}
- private void writeHeaders(FileWriter writer) throws IOException {
+ private void writeHeaders(final FileWriter writer) throws IOException {
writer.append("\"ERROR CODE\"");
writer.append(',');
writer.append("\"ERROR TYPE\"");
@@ -110,77 +107,25 @@ public class GenerateEcompErrorsCsv {
writer.append(NEW_LINE);
}
- private String addInvertedCommas(String str) {
+ private String addInvertedCommas(final String str) {
if (str == null) {
return "\"\"";
}
return "\"" + str + "\"";
}
- public static class EcompErrorRow {
-
- String errorName;
- String errorCode;
- String description;
- ErrorType errorType;
- AlarmSeverity alarmSeverity;
- String cleanErrorCode;
- String resolution;
-
- public String getErrorName() {
- return errorName;
- }
-
- public void setErrorName(String errorName) {
- this.errorName = errorName;
- }
-
- public String getErrorCode() {
- return errorCode;
- }
-
- public void setErrorCode(String errorCode) {
- this.errorCode = errorCode;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public ErrorType getErrorType() {
- return errorType;
- }
-
- public void setErrorType(ErrorType errorType) {
- this.errorType = errorType;
- }
-
- public AlarmSeverity getAlarmSeverity() {
- return alarmSeverity;
- }
+ @Getter
+ @Setter
+ @NoArgsConstructor
+ private class EcompErrorRow {
- public void setAlarmSeverity(AlarmSeverity alarmSeverity) {
- this.alarmSeverity = alarmSeverity;
- }
+ private String errorName;
+ private String errorCode;
+ private String description;
+ private ErrorType errorType;
+ private AlarmSeverity alarmSeverity;
+ private String cleanErrorCode;
+ private String resolution;
- public String getCleanErrorCode() {
- return cleanErrorCode;
- }
-
- public void setCleanErrorCode(String cleanErrorCode) {
- this.cleanErrorCode = cleanErrorCode;
- }
-
- public String getResolution() {
- return resolution;
- }
-
- public void setResolution(String resolution) {
- this.resolution = resolution;
- }
}
}
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsvTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsvTest.java
index e9fe964dc1..8206665f23 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsvTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/config/generation/GenerateEcompErrorsCsvTest.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.
@@ -20,25 +20,21 @@
package org.openecomp.sdc.common.config.generation;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-public class GenerateEcompErrorsCsvTest {
+class GenerateEcompErrorsCsvTest {
private GenerateEcompErrorsCsv createTestSubject() {
return new GenerateEcompErrorsCsv();
}
-
@Test
- public void testGenerateEcompErrorsCsvFile() throws Exception {
- GenerateEcompErrorsCsv testSubject;
- String targetFolder = "";
- boolean addTimeToFileName = false;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.generateEcompErrorsCsvFile(targetFolder, addTimeToFileName);
+ void generateEcompErrorFileInTargetTest() {
+ final GenerateEcompErrorsCsv ecompErrorsCsv = createTestSubject();
+ Assertions.assertNotNull(ecompErrorsCsv);
+ final boolean result = ecompErrorsCsv.generateEcompErrorsCsvFile("target", true);
+ Assertions.assertTrue(result);
}
}