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;
}
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());
}
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;
}
Aggregations