use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.
the class BundleValidationServiceImplTest method testValidateGtfs.
// @Test
public void testValidateGtfs() throws Exception {
BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
InputStream source = this.getClass().getResourceAsStream("gtfs-m34.zip");
assertNotNull(source);
String goodFeedFilename = getTmpDir() + File.separatorChar + "good_feed.zip";
new NYCFileUtils().copy(source, goodFeedFilename);
assertTrue(new File(goodFeedFilename).exists());
String emptyFeedFilename = getTmpDir() + File.separatorChar + "good_feed.zip";
assertTrue(new File(emptyFeedFilename).exists());
String feedFilename = getTmpDir() + File.separatorChar + "feed.html";
int rc = impl.installAndValidateGtfs(emptyFeedFilename, feedFilename);
// feedValidator exits with returnCode 1
if (rc == 2) {
throw new RuntimeException("please execute this command: 'sudo ln -s /usr/bin/python /usr/bin/python2.5'");
}
assertEquals(1, rc);
File output = new File(feedFilename);
assertTrue(output.exists());
}
use of org.onebusaway.admin.util.NYCFileUtils 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.util.NYCFileUtils 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.util.NYCFileUtils in project onebusaway-application-modules by camsys.
the class BundleBuildingServiceImpl method prepHastus.
private void prepHastus(BundleBuildRequest request, BundleBuildResponse response) {
NYCFileUtils fs = new NYCFileUtils();
// create AUX dir as well
String auxPath = request.getTmpDirectory() + File.separator + "aux";
File auxDir = new File(auxPath);
_log.info("creating aux directory=" + auxPath);
auxDir.mkdirs();
}
use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.
the class BundleBuildingServiceImpl method addStifTask.
private void addStifTask(Map<String, BeanDefinition> beans, BundleBuildRequest request, BundleBuildResponse response) {
// STEP 3
BeanDefinitionBuilder stifLoaderTask = BeanDefinitionBuilder.genericBeanDefinition(StifTask.class);
stifLoaderTask.addPropertyValue("fallBackToStifBlocks", Boolean.TRUE);
stifLoaderTask.addPropertyReference("logger", "multiCSVLogger");
// TODO this is a convention, pull out into config?
stifLoaderTask.addPropertyValue("stifPath", request.getTmpDirectory() + File.separator + "stif");
String notInServiceDirString = request.getTmpDirectory() + File.separator + "config";
String notInServiceFilename = notInServiceDirString + File.separator + "NotInServiceDSCs.txt";
_log.info("creating NotInServiceDSCs file = " + notInServiceFilename);
new File(notInServiceDirString).mkdirs();
new NYCFileUtils().createFile(notInServiceFilename, listToFile(request.getNotInServiceDSCList()));
stifLoaderTask.addPropertyValue("notInServiceDscPath", notInServiceFilename);
String dscMapPath = response.getBundleInputDirectory() + File.separator + "config" + File.separator + getTripToDSCFilename();
_log.info("looking for configuration at " + dscMapPath);
File dscMapFile = new File(dscMapPath);
if (dscMapFile.exists()) {
_log.info("loading tripToDSCMap at" + dscMapPath);
response.addStatusMessage("loading tripToDSCMap at" + dscMapPath);
stifLoaderTask.addPropertyValue("tripToDSCOverridePath", dscMapPath);
} else {
response.addStatusMessage(getTripToDSCFilename() + " not found, override ignored");
}
beans.put("stifLoaderTask", stifLoaderTask.getBeanDefinition());
BeanDefinitionBuilder task = null;
task = BeanDefinitionBuilder.genericBeanDefinition(TaskDefinition.class);
task.addPropertyValue("taskName", "stifLoaderTask");
task.addPropertyValue("afterTaskName", "check_shapes");
task.addPropertyValue("beforeTaskName", "transit_graph");
task.addPropertyReference("task", "stifLoaderTask");
beans.put("stifLoaderTaskDef", task.getBeanDefinition());
}
Aggregations