mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-19 04:58:00 +00:00
Add input formatting and validation to client and server side. Close dialog box on submission.
This commit is contained in:
parent
4acfbf3026
commit
177e307a17
@ -41,6 +41,8 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the Validation Reports page.
|
* Controller for the Validation Reports page.
|
||||||
@ -55,6 +57,7 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
|||||||
|
|
||||||
private static final Logger LOGGER = getLogger(ValidationReportsPageController.class);
|
private static final Logger LOGGER = getLogger(ValidationReportsPageController.class);
|
||||||
private static final String DEFAULT_COMPANY = "AllDevices";
|
private static final String DEFAULT_COMPANY = "AllDevices";
|
||||||
|
private static final String UNDEFINED = "undefined";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor providing the Page's display and routing specification.
|
* Constructor providing the Page's display and routing specification.
|
||||||
@ -148,7 +151,8 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
|||||||
LOGGER.info("Downloading validation report");
|
LOGGER.info("Downloading validation report");
|
||||||
String company = "";
|
String company = "";
|
||||||
String contractNumber = "";
|
String contractNumber = "";
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM/dd/uuuu");
|
Pattern pattern = Pattern.compile("[A-Za-z0-9\\s]*");
|
||||||
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd");
|
||||||
DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
|
DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
|
||||||
LocalDate startDate = null;
|
LocalDate startDate = null;
|
||||||
LocalDate endDate = null;
|
LocalDate endDate = null;
|
||||||
@ -158,56 +162,59 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
|||||||
while (parameters.hasMoreElements()) {
|
while (parameters.hasMoreElements()) {
|
||||||
String parameter = (String) parameters.nextElement();
|
String parameter = (String) parameters.nextElement();
|
||||||
String parameterValue = request.getParameter(parameter);
|
String parameterValue = request.getParameter(parameter);
|
||||||
|
LOGGER.info(parameter + ": " + parameterValue);
|
||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case "company":
|
case "company":
|
||||||
company = parameterValue;
|
Matcher companyMatcher = pattern.matcher(parameterValue);
|
||||||
|
if (companyMatcher.matches()) {
|
||||||
|
company = parameterValue;
|
||||||
|
} else {
|
||||||
|
company = DEFAULT_COMPANY;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "contract":
|
case "contract":
|
||||||
contractNumber = parameterValue;
|
Matcher contractMatcher = pattern.matcher(parameterValue);
|
||||||
|
if (contractMatcher.matches()) {
|
||||||
|
contractNumber = parameterValue;
|
||||||
|
} else {
|
||||||
|
contractNumber = "none";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "dateStart":
|
case "dateStart":
|
||||||
if (parameterValue != null && !parameterValue.isEmpty()) {
|
if (parameterValue != null && !parameterValue.isEmpty()) {
|
||||||
startDate = LocalDate.parse(parameterValue, dateFormat);
|
startDate = LocalDate.parse(parameterValue, dateFormat);
|
||||||
|
} else {
|
||||||
|
startDate = LocalDate.ofEpochDay(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "dateEnd":
|
case "dateEnd":
|
||||||
if (parameterValue != null && !parameterValue.isEmpty()) {
|
if (parameterValue != null && !parameterValue.isEmpty()) {
|
||||||
endDate = LocalDate.parse(parameterValue, dateFormat);
|
endDate = LocalDate.parse(parameterValue, dateFormat);
|
||||||
|
} else {
|
||||||
|
endDate = LocalDate.now();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "createTimes":
|
case "createTimes":
|
||||||
String[] timestamps = parameterValue.split(",");
|
if (!parameterValue.equals(UNDEFINED)) {
|
||||||
for (String timestamp : timestamps) {
|
String[] timestamps = parameterValue.split(",");
|
||||||
createTimes.add(LocalDateTime.parse(timestamp,
|
for (String timestamp : timestamps) {
|
||||||
dateTimeFormat).toLocalDate());
|
createTimes.add(LocalDateTime.parse(timestamp,
|
||||||
LOGGER.info("Create time added: "
|
dateTimeFormat).toLocalDate());
|
||||||
+ createTimes.get(createTimes.size() - 1));
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "deviceNames":
|
case "deviceNames":
|
||||||
deviceNames = parameterValue.split(",");
|
if (!parameterValue.equals(UNDEFINED)) {
|
||||||
|
deviceNames = parameterValue.split(",");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
LOGGER.info(parameter + ": " + parameterValue);
|
|
||||||
}
|
}
|
||||||
if (company.equals("")) {
|
|
||||||
company = DEFAULT_COMPANY;
|
|
||||||
}
|
|
||||||
if (contractNumber.equals("")) {
|
|
||||||
contractNumber = "none";
|
|
||||||
}
|
|
||||||
if (startDate == null) {
|
|
||||||
startDate = LocalDate.ofEpochDay(0);
|
|
||||||
}
|
|
||||||
if (endDate == null) {
|
|
||||||
endDate = LocalDate.now();
|
|
||||||
}
|
|
||||||
LOGGER.info("Start date: " + startDate.toString() + ", end date: " + endDate.toString());
|
|
||||||
|
|
||||||
response.setHeader("Content-Type", "text/csv");
|
response.setHeader("Content-Type", "text/csv");
|
||||||
response.setHeader("Content-Disposition",
|
response.setHeader("Content-Disposition",
|
||||||
"attachment;filename=\"validation_report.csv\"");
|
"attachment;filename=" + company + "_validation_report.csv");
|
||||||
BufferedWriter bufferedWriter = new BufferedWriter(
|
BufferedWriter bufferedWriter = new BufferedWriter(
|
||||||
new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
|
new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
|
||||||
String columnHeaders = "Verified Manufacturer, "
|
String columnHeaders = "Verified Manufacturer, "
|
||||||
@ -243,13 +250,13 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
|||||||
+ "\nComponent status: "
|
+ "\nComponent status: "
|
||||||
+ ((ComponentIdentifierV2) ci).getAttributeStatus());
|
+ ((ComponentIdentifierV2) ci).getAttributeStatus());
|
||||||
} else {
|
} else {
|
||||||
//("Platform Components" + "\n");
|
|
||||||
LOGGER.info("\nPlatform Components");
|
LOGGER.info("\nPlatform Components");
|
||||||
}
|
}
|
||||||
LOGGER.info("Component manufacturer : "
|
LOGGER.info("Component manufacturer : "
|
||||||
+ ci.getComponentManufacturer().getString()
|
+ ci.getComponentManufacturer().getString()
|
||||||
+ "\nComponent model: " + ci.getComponentModel().getString()
|
+ "\nComponent model: " + ci.getComponentModel().getString()
|
||||||
+ "\nComponent revision: " + ci.getComponentRevision().getString());
|
+ "\nComponent revision: "
|
||||||
|
+ ci.getComponentRevision().getString());
|
||||||
}
|
}
|
||||||
attributeStatuses = attributeStatuses.substring(0,
|
attributeStatuses = attributeStatuses.substring(0,
|
||||||
attributeStatuses.length() - 1);
|
attributeStatuses.length() - 1);
|
||||||
|
@ -28,11 +28,13 @@
|
|||||||
<form:form id="download" method="POST" action="${portal}/validation-reports/download">
|
<form:form id="download" method="POST" action="${portal}/validation-reports/download">
|
||||||
Download Validation Reports
|
Download Validation Reports
|
||||||
<my:download-info id="validationReportsDownload" label="Download Validation Reports">
|
<my:download-info id="validationReportsDownload" label="Download Validation Reports">
|
||||||
<label>Company<input id="company" type="text" name="company" /></label>
|
<label>Company<input id="company" type="text" pattern="[A-Za-z0-9\s]*"
|
||||||
<label>Contract #<input id="contract" type="text" name="contract" /></label>
|
title="Letters, numbers, and spaces only" name="company" /></label>
|
||||||
|
<label>Contract #<input id="contract" type="text" pattern="[A-Za-z0-9\s]*"
|
||||||
|
title="Letters, numbers, and spaces only" name="contract" /></label>
|
||||||
<br>
|
<br>
|
||||||
<label>Date range start (mm/dd/yyyy)<input id="dateStart" type="text" name="dateStart" /></label>
|
<label>Date range start<input id="dateStart" type="date" name="dateStart" /></label>
|
||||||
<label>Date range end (mm/dd/yyyy)<input id="dateEnd" type="text" name="dateEnd" /></label>
|
<label>Date range end<input id="dateEnd" type="date" name="dateEnd" /></label>
|
||||||
</my:download-info>
|
</my:download-info>
|
||||||
</form:form>
|
</form:form>
|
||||||
|
|
||||||
@ -166,6 +168,10 @@
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".btn-primary").click(function() {
|
||||||
|
$("#validationReportsDownload").modal('hide');
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets HTML to display (icon tag) for the specified validation type.
|
* Gets HTML to display (icon tag) for the specified validation type.
|
||||||
* If a validation for the requested type is not found, an empty
|
* If a validation for the requested type is not found, an empty
|
||||||
|
Loading…
Reference in New Issue
Block a user