use of org.onebusaway.admin.service.exceptions.DateValidationException in project onebusaway-application-modules by camsys.
the class BuildResource method validateDates.
/**
* Performs various validations on start and end dates
* @param bundleStartDateString
* @param bundleEndDateString
*/
protected void validateDates(String bundleStartDateString, String bundleEndDateString) throws DateValidationException {
if (StringUtils.isBlank(bundleStartDateString)) {
throw new DateValidationException(bundleStartDateString, bundleEndDateString);
}
if (StringUtils.isBlank(bundleEndDateString)) {
throw new DateValidationException(bundleStartDateString, bundleEndDateString);
}
DateTime startDate = ISODateTimeFormat.date().parseDateTime(bundleStartDateString);
DateTime endDate = ISODateTimeFormat.date().parseDateTime(bundleEndDateString);
if (startDate.isAfter(endDate)) {
throw new DateValidationException(bundleStartDateString, bundleEndDateString);
}
}
use of org.onebusaway.admin.service.exceptions.DateValidationException in project onebusaway-application-modules by camsys.
the class BuildResource method build.
@Path("create")
@POST
@Produces("application/json")
public Response build(@FormParam("bundleDirectory") String bundleDirectory, @FormParam("bundleName") String bundleName, @FormParam("email") String email, @FormParam("bundleStartDate") String bundleStartDate, @FormParam("bundleEndDate") String bundleEndDate, @FormParam("bundleComment") String bundleComment, @FormParam("archive") boolean archiveFlag, @FormParam("consolidate") boolean consolidateFlag, @FormParam("predate") boolean predateFlag) {
Response response = null;
directoryName = bundleDirectory;
this.bundleName = bundleName;
startDate = bundleStartDate;
endDate = bundleEndDate;
emailTo = email;
comment = bundleComment;
archive = archiveFlag;
consolidate = consolidateFlag;
predate = predateFlag;
if (!isAuthorized()) {
return Response.noContent().build();
}
BundleBuildResponse buildResponse = null;
try {
validateDates(bundleStartDate, bundleEndDate);
} catch (DateValidationException e) {
try {
buildResponse = new BundleBuildResponse();
buildResponse.setException(e);
response = constructResponse(buildResponse);
} catch (Exception any) {
_log.error("exception in build:", any);
response = Response.serverError().build();
}
}
// Proceed only if date validation passes
if (response == null) {
BundleBuildRequest buildRequest = new BundleBuildRequest();
buildRequest.setBundleDirectory(bundleDirectory);
buildRequest.setBundleName(bundleName);
buildRequest.setEmailAddress(email);
buildRequest.setBundleStartDate(bundleStartDate);
buildRequest.setBundleEndDate(bundleEndDate);
buildRequest.setBundleComment(bundleComment);
buildRequest.setArchiveFlag(archive);
buildRequest.setConsolidateFlag(consolidate);
buildRequest.setPredate(predate);
String session = RequestContextHolder.currentRequestAttributes().getSessionId();
buildRequest.setSessionId(session);
try {
String message = "Starting bundle building process for bundle '" + buildRequest.getBundleName() + "' initiated by user : " + _currentUserService.getCurrentUserDetails().getUsername();
String component = System.getProperty("admin.chefRole");
loggingService.log(component, Level.INFO, message);
buildResponse = _bundleService.build(buildRequest);
buildResponse = _bundleService.buildBundleResultURL(buildResponse.getId());
response = constructResponse(buildResponse);
} catch (Exception any) {
_log.error("exception in build:", any);
response = Response.serverError().build();
}
}
return response;
}
Aggregations