Search in sources :

Example 11 with NYCFileUtils

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());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) File(java.io.File)

Example 12 with NYCFileUtils

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());
}
Also used : BundleBuildRequest(org.onebusaway.admin.model.BundleBuildRequest) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse)

Example 13 with NYCFileUtils

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());
}
Also used : BundleBuildRequest(org.onebusaway.admin.model.BundleBuildRequest) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Test(org.junit.Test)

Example 14 with NYCFileUtils

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();
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 15 with NYCFileUtils

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());
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) TaskDefinition(org.onebusaway.transit_data_federation.bundle.model.TaskDefinition) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)22 File (java.io.File)15 ZipFile (java.util.zip.ZipFile)6 InputStream (java.io.InputStream)4 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)4 BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 FileService (org.onebusaway.admin.service.FileService)2 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)2 S3FileServiceImpl (org.onebusaway.admin.service.impl.S3FileServiceImpl)2 FileUtility (org.onebusaway.util.FileUtility)2 RemoteConnectFailureException (org.springframework.remoting.RemoteConnectFailureException)2 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1