Search in sources :

Example 1 with DateValidationException

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);
    }
}
Also used : DateTime(org.joda.time.DateTime) DateValidationException(org.onebusaway.admin.service.exceptions.DateValidationException)

Example 2 with DateValidationException

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;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) BundleBuildRequest(org.onebusaway.admin.model.BundleBuildRequest) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) DateValidationException(org.onebusaway.admin.service.exceptions.DateValidationException) DateValidationException(org.onebusaway.admin.service.exceptions.DateValidationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

DateValidationException (org.onebusaway.admin.service.exceptions.DateValidationException)2 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 DateTime (org.joda.time.DateTime)1 BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)1 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)1