use of org.onebusaway.admin.model.BundleBuildRequest in project onebusaway-application-modules by camsys.
the class BundleBuildingServiceImplTest method testBuildHastus.
private void testBuildHastus() {
_service.setAuxConfig("true");
String bundleDir = "test";
String tmpDir = new NYCFileUtils().createTmpDirectory();
BundleBuildRequest request = new BundleBuildRequest();
request.setBundleDirectory(bundleDir);
request.setBundleName("testnameHastus");
request.setTmpDirectory(tmpDir);
request.setBundleStartDate("2012-04-08");
request.setBundleEndDate("2012-07-07");
assertNotNull(request.getTmpDirectory());
assertNotNull(request.getBundleDirectory());
BundleBuildResponse response = new BundleBuildResponse("" + System.currentTimeMillis());
assertEquals(0, response.getStatusList().size());
// step 1
_service.download(request, response);
assertNotNull(response.getGtfsList());
assertEquals(1, response.getGtfsList().size());
assertNotNull(response.getAuxZipList());
assertEquals(2, response.getAuxZipList().size());
assertNotNull(response.getStatusList());
assertTrue(response.getStatusList().size() > 0);
assertNotNull(response.getConfigList());
assertEquals(0, response.getConfigList().size());
// step 2
_service.prepare(request, response);
assertFalse(response.isComplete());
// step 3
int rc = _service.build(request, response);
if (response.getException() != null) {
_log.error("Failed with exception=" + response.getException(), response.getException());
}
assertNull(response.getException());
assertFalse(response.isComplete());
assertEquals(0, rc);
// step 4
// OBANYC-1451 -- fails on OSX TODO
// _service.assemble(request, response);
// step 5
_service.upload(request, response);
// set by BundleRequestService
assertFalse(response.isComplete());
}
use of org.onebusaway.admin.model.BundleBuildRequest in project onebusaway-application-modules by camsys.
the class BuildRemoteResource method build.
@Path("/create")
@POST
@Produces("application/json")
public Response build(@FormParam("bundleDirectory") String bundleDirectory, @FormParam("bundleBuildName") String bundleName, @FormParam("email") String email, @FormParam("id") String id, @FormParam("bundleStartDate") String bundleStartDate, @FormParam("bundleEndDate") String bundleEndDate, @FormParam("bundleComment") String bundleComment, @FormParam("archive") boolean archive, @FormParam("consolidate") boolean consolidate, @FormParam("predate") boolean predate) {
Response response = null;
if (!isAuthorized()) {
return Response.noContent().build();
}
_log.info("in build(local) with archive=" + archive + ", and consolidate=" + consolidate);
BundleBuildRequest bundleRequest = new BundleBuildRequest();
bundleRequest.setBundleDirectory(bundleDirectory);
bundleRequest.setBundleName(bundleName);
bundleRequest.setEmailAddress(email);
bundleRequest.setId(id);
bundleRequest.setBundleStartDate(bundleStartDate);
bundleRequest.setBundleEndDate(bundleEndDate);
bundleRequest.setBundleComment(bundleComment);
bundleRequest.setArchiveFlag(archive);
bundleRequest.setConsolidateFlag(consolidate);
bundleRequest.setPredate(predate);
BundleBuildResponse bundleResponse = new BundleBuildResponse(id);
try {
bundleResponse.addStatusMessage("server started");
bundleResponse.addStatusMessage("queueing");
// place execution in its own thread
_executorService.execute(new BuildThread(bundleRequest, bundleResponse));
// place handle to response in map
_buildMap.put(id, bundleResponse);
final StringWriter sw = new StringWriter();
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
// write back response
_mapper.writeValue(jsonGenerator, bundleResponse);
response = Response.ok(sw.toString()).build();
} catch (Exception any) {
_log.error("execption in build:", any);
response = Response.serverError().build();
}
return response;
}
use of org.onebusaway.admin.model.BundleBuildRequest in project onebusaway-application-modules by camsys.
the class BundleBuildingServiceImplTest method testBuildStif.
private void testBuildStif() {
_service.setAuxConfig("false");
String bundleDir = "test";
String tmpDir = new NYCFileUtils().createTmpDirectory();
BundleBuildRequest request = new BundleBuildRequest();
request.setBundleDirectory(bundleDir);
request.setBundleName("testname");
request.setTmpDirectory(tmpDir);
request.setBundleStartDate("2012-04-08");
request.setBundleEndDate("2012-07-07");
request.setBundleComment("Test");
assertNotNull(request.getTmpDirectory());
assertNotNull(request.getBundleDirectory());
BundleBuildResponse response = new BundleBuildResponse("" + System.currentTimeMillis());
assertEquals(0, response.getStatusList().size());
// step 1
_service.download(request, response);
assertNotNull(response.getGtfsList());
assertEquals(1, response.getGtfsList().size());
assertNotNull(response.getAuxZipList());
assertEquals(1, response.getAuxZipList().size());
assertNotNull(response.getStatusList());
assertTrue(response.getStatusList().size() > 0);
assertNotNull(response.getConfigList());
assertEquals(0, response.getConfigList().size());
// step 2
_service.prepare(request, response);
assertFalse(response.isComplete());
// step 3
int rc = _service.build(request, response);
if (response.getException() != null) {
_log.error("Failed with exception=" + response.getException(), response.getException());
}
assertNull(response.getException());
assertFalse(response.isComplete());
assertEquals(0, rc);
// step 4
// OBANYC-1451 -- fails on OSX TODO
// _service.assemble(request, response);
// step 5
_service.upload(request, response);
// set by BundleRequestService
assertFalse(response.isComplete());
}
use of org.onebusaway.admin.model.BundleBuildRequest in project onebusaway-application-modules by camsys.
the class BundleRequestServiceImplTest method testBuild.
@Test
public void testBuild() throws Exception {
BundleBuildRequest req = new BundleBuildRequest();
String key = "2012Jan";
// String key = "m34"; // use for faster testing
req.setBundleDirectory(key);
req.setBundleName("test_0");
req.setTmpDirectory(new NYCFileUtils().createTmpDirectory());
req.setBundleStartDate("2012-04-08");
req.setBundleEndDate("2012-07-07");
req.setBundleComment("Test Bundle");
_log.debug("calling build for dir=" + req.getBundleDirectory() + " name=" + req.getBundleName());
BundleBuildResponse res = service.build(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.info("calling lookup(local) for id=" + res.getId());
res = service.lookupBuildRequest(res.getId());
assertNotNull(res);
}
if (res.getException() != null) {
_log.error("Failed with exception=" + res.getException());
}
assertNull(res.getException());
assertTrue(res.isComplete());
assertNotNull(res.getGtfsList());
assertEquals(2, res.getGtfsList().size());
}
use of org.onebusaway.admin.model.BundleBuildRequest in project onebusaway-application-modules by camsys.
the class GtfsArchiveTask method createMetaData.
private Integer createMetaData(Session session, BundleRequestResponse requestResponse) {
GtfsBundleInfo info = new GtfsBundleInfo();
BundleBuildRequest request = requestResponse.getRequest();
BundleBuildResponse response = requestResponse.getResponse();
info.setBundleId(response.getBundleId());
info.setName(request.getBundleName());
info.setDirectory(request.getBundleDirectory());
info.setStartDate(request.getBundleStartDate().toDate());
info.setEndDate(request.getBundleEndDate().toDate());
info.setTimestamp(new Date());
return (Integer) session.save(info);
}
Aggregations