Search in sources :

Example 1 with BundleRequest

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

the class ValidateResource method validate.

@Path("/{bundleDirectory}/{bundleName}/create")
@GET
@Produces("application/json")
public Response validate(@PathParam("bundleDirectory") String bundleDirectory, @PathParam("bundleName") String bundleName) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleRequest bundleRequest = new BundleRequest();
    directoryName = bundleDirectory;
    this.bundleName = bundleName;
    bundleRequest.setBundleBuildName(bundleName);
    bundleRequest.setBundleDirectory(bundleDirectory);
    String session = RequestContextHolder.currentRequestAttributes().getSessionId();
    bundleRequest.setSessionId(session);
    BundleResponse bundleResponse = null;
    try {
        bundleResponse = _bundleService.validate(bundleRequest);
        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) {
        _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 2 with BundleRequest

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

the class BundleRequestServiceImplTest method testValidate.

@Test
public void testValidate() throws Exception {
    BundleRequest req = new BundleRequest();
    String key = "2012Jan";
    // String key = "m34"; // use for faster testing
    req.setBundleDirectory(key);
    req.setBundleBuildName("test_0");
    _log.debug("calling validate for dir=" + req.getBundleDirectory() + " name=" + req.getBundleBuildName());
    BundleResponse res = service.validate(req);
    assertFalse(res.isComplete());
    int count = 0;
    while (count < 300 && !res.isComplete() && res.getException() == null) {
        // _log.info("sleeping[" + count + "]...");
        Thread.sleep(10 * 1000);
        count++;
        // NOTE: this is optional to demonstrate retrieval service
        _log.debug("calling lookup(local) for id=" + res.getId());
        res = service.lookupValidationRequest(res.getId());
        assertNotNull(res);
    }
    if (res.getException() != null) {
        _log.error("Failed with exception=" + res.getException());
    }
    assertNull(res.getException());
    assertTrue(res.isComplete());
    assertNotNull(res.getValidationFiles());
    assertEquals(2, res.getValidationFiles().size());
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) BundleRequest(org.onebusaway.admin.model.BundleRequest) Test(org.junit.Test)

Example 3 with BundleRequest

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

Aggregations

BundleRequest (org.onebusaway.admin.model.BundleRequest)3 BundleResponse (org.onebusaway.admin.model.BundleResponse)3 StringWriter (java.io.StringWriter)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 JsonGenerator (org.codehaus.jackson.JsonGenerator)2 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)2 Test (org.junit.Test)1