Skip to content

Commit

Permalink
Fix policy generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Mar 27, 2024
1 parent 73658d7 commit 7c4a6da
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PolicyGenerator {
private Document document;
private StringBuilder content;
private String fileName;
private String shortFilePath;
private String shortFileName;
private InputStream report;
private ValidationProfile customProfile;
private boolean isLogsEnabled = true;
Expand Down Expand Up @@ -184,8 +184,7 @@ public void generate() {
try {
document = (DocumentBuilderFactory.newInstance().newDocumentBuilder()).parse(report);

String[] name = fileName.split("/");
shortFilePath = name[name.length - 1];
shortFileName = new File(fileName).getName();
Path policy = Paths.get(fileName.replace(".pdf", ".sch"));
NodeList nodeList = document.getElementsByTagName("validationReport");

Expand Down Expand Up @@ -216,8 +215,8 @@ private void generateFailPolicy() {
String failedRulesToBeReplaced = nodeList.item(0).getAttributes().getNamedItem("failedRules").getNodeValue();

content = new StringBuilder(PolicyHelper.FAIL
.replace("{fileNameToBeReplaced}", shortFilePath)
.replace("ISSUE_NUM", getIssueNumberPart())
.replace("{fileNameToBeReplaced}", shortFileName)
.replace("ISSUE_NUMBER_PART", getIssueNumberPart())
.replace("{failedRulesToBeReplaced}", failedRulesToBeReplaced));

nodeList = document.getElementsByTagName("rule");
Expand Down Expand Up @@ -259,8 +258,8 @@ private void generateFailPolicy() {

private void generatePassPolicy() {
content = new StringBuilder(PolicyHelper.PASS
.replace("{fileNameToBeReplaced}", shortFilePath)
.replace("ISSUE_NUM", getIssueNumberPart()));
.replace("{fileNameToBeReplaced}", shortFileName)
.replace("ISSUE_NUMBER_PART", getIssueNumberPart()));

System.out.println("Policy was created. PDF file is compliant with Validation Profile requirements");
}
Expand All @@ -280,8 +279,8 @@ private void generateExceptionPolicy() {
String outOfMemoryToBeReplaced = node.getNamedItem("outOfMemory").getNodeValue();
String veraExceptionsToBeReplaced = node.getNamedItem("veraExceptions").getNodeValue();
content = new StringBuilder(PolicyHelper.EXC
.replace("{fileNameToBeReplaced}", shortFilePath)
.replace("ISSUE_NUM", getIssueNumberPart())
.replace("{fileNameToBeReplaced}", shortFileName)
.replace("ISSUE_NUMBER_PART", getIssueNumberPart())
.replace("{exceptionMessageToBeReplaced}", exceptionMessageToBeReplaced)
.replace("{exceptionToBeReplaced}", exceptionToBeReplaced)
.replace("{totalJobsToBeReplaced}", totalJobsToBeReplaced)
Expand Down Expand Up @@ -323,7 +322,7 @@ private void appendLogs() {
LogInfo logInfo = iterator.next();
content.append(PolicyHelper.LOG
.replace("{logToBeReplaced}", logInfo.getMessage().replace("'", "'")
.replace(shortFilePath, ".pdf"))
.replace(shortFileName, ".pdf"))
.replace("{occurrencesToBeReplaced}", String.valueOf(logInfo.getOccurrences()))
.replace("{levelToBeReplaced}", logInfo.getLevel().getName()));

Expand Down

0 comments on commit 7c4a6da

Please sign in to comment.