Search in sources :

Example 6 with BundleBuildRequest

use of org.onebusaway.admin.model.BundleBuildRequest 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

BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)6 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)6 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)3 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)1 Test (org.junit.Test)1 GtfsBundleInfo (org.onebusaway.admin.service.bundle.task.model.GtfsBundleInfo)1 DateValidationException (org.onebusaway.admin.service.exceptions.DateValidationException)1