Search in sources :

Example 11 with BundleBuildResponse

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

Example 12 with BundleBuildResponse

use of org.onebusaway.admin.model.BundleBuildResponse in project onebusaway-application-modules by camsys.

the class BuildResource method url.

@Path("/{id}/url")
@GET
@Produces("application/json")
public Response url(@PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleBuildResponse buildResponse = _bundleService.lookupBuildRequest(id);
    try {
        response = constructResponse(buildResponse);
    } catch (Exception any) {
        _log.error("exception looking up build:", any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) 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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with BundleBuildResponse

use of org.onebusaway.admin.model.BundleBuildResponse in project onebusaway-application-modules by camsys.

the class BuildRemoteResource method list.

@Path("/{id}/list")
@GET
@Produces("application/json")
public Response list(@PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    try {
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        BundleBuildResponse bbr = _buildMap.get(id);
        if (bbr == null) {
            bbr = _bundleService.getBundleBuildResponseForId(id);
        }
        if (bbr != null && bbr.getException() != null) {
            _log.error("id=" + id + " has exception=" + bbr.getException());
        }
        _mapper.writeValue(jsonGenerator, bbr);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)13 BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Response (javax.ws.rs.core.Response)5 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 GET (javax.ws.rs.GET)3 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)3 JsonGenerator (org.codehaus.jackson.JsonGenerator)3 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)3 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)3 DateValidationException (org.onebusaway.admin.service.exceptions.DateValidationException)3 POST (javax.ws.rs.POST)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 Session (org.hibernate.Session)1