Search in sources :

Example 6 with BundleResponse

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

the class ValidateRemoteResource method validate.

@Path("/{bundleDirectory}/{bundleName}/{id}/create")
@GET
@Produces("application/json")
public Response validate(@PathParam("bundleDirectory") String bundleDirectory, @PathParam("bundleName") String bundleName, @PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleRequest bundleRequest = new BundleRequest();
    _log.debug("bundleName=" + bundleName + ", bundleDirectory=" + bundleDirectory);
    bundleRequest.setBundleBuildName(bundleName);
    bundleRequest.setBundleDirectory(bundleDirectory);
    bundleRequest.setId(id);
    BundleResponse bundleResponse = new BundleResponse(id);
    try {
        bundleResponse.addStatusMessage("server started");
        bundleResponse.addStatusMessage("queueing");
        // place execution in its own thread
        _executorService.execute(new ValidateThread(bundleRequest, bundleResponse));
        // place handle to response in map
        _validationMap.put(id, bundleResponse);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        // write back response
        _log.debug("returning id=" + bundleResponse.getId() + " for bundleResponse=" + bundleResponse);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("validate resource caught exception:" + any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) BundleResponse(org.onebusaway.admin.model.BundleResponse) StringWriter(java.io.StringWriter) BundleRequest(org.onebusaway.admin.model.BundleRequest) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with BundleResponse

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

the class ValidateResource 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();
    }
    BundleResponse bundleResponse = null;
    try {
        bundleResponse = _bundleService.lookupValidationRequest(id);
        bundleResponse.setBuildName(bundleName);
        bundleResponse.setDirectoryName(directoryName);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) BundleResponse(org.onebusaway.admin.model.BundleResponse) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BundleResponse (org.onebusaway.admin.model.BundleResponse)7 StringWriter (java.io.StringWriter)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Response (javax.ws.rs.core.Response)4 JsonGenerator (org.codehaus.jackson.JsonGenerator)4 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)4 BundleRequest (org.onebusaway.admin.model.BundleRequest)3 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Before (org.junit.Before)1 Test (org.junit.Test)1 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)1 FileService (org.onebusaway.admin.service.FileService)1 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)1 BundleRequestServiceImpl (org.onebusaway.admin.service.impl.BundleRequestServiceImpl)1 S3FileServiceImpl (org.onebusaway.admin.service.impl.S3FileServiceImpl)1 BundleServerServiceImpl (org.onebusaway.admin.service.server.impl.BundleServerServiceImpl)1