Search in sources :

Example 16 with NYCFileUtils

use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImpl method downloadFeedValidator.

public synchronized void downloadFeedValidator() {
    String tmpDir = System.getProperty("java.io.tmpdir");
    String localFile = tmpDir + File.separatorChar + TRANSIT_FEED + ".tar.gz";
    if (new File(localFile).exists()) {
        _log.error("feed Validator found at " + localFile + ", exiting");
        _log.error("remove the file at " + localFile + " if it is corrupt");
        return;
    }
    NYCFileUtils fs = new NYCFileUtils(tmpDir);
    String url = "http://developer.onebusaway.org/tmp/" + TRANSIT_FEED + ".tar.gz";
    fs.wget(url);
    fs.tarzxf(localFile);
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) File(java.io.File)

Example 17 with NYCFileUtils

use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.

the class DirectoryBundleDeployerImpl method setup.

@PostConstruct
public void setup() {
    _fileUtil = new FileUtility();
    _nycFileUtils = new NYCFileUtils();
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) FileUtility(org.onebusaway.util.FileUtility) PostConstruct(javax.annotation.PostConstruct)

Example 18 with NYCFileUtils

use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.

the class BaseModTask method cleanup.

private String cleanup(GtfsBundle gtfsBundle) throws Exception {
    File gtfsFile = gtfsBundle.getPath();
    FileUtility fu = new FileUtility();
    NYCFileUtils fs = new NYCFileUtils();
    _log.info("gtfsBundle.getPath=" + gtfsFile.getPath());
    String oldGtfsName = gtfsFile.getPath().toString();
    // delete the old zip file
    _log.info("deleting " + gtfsFile.getPath());
    gtfsFile.delete();
    // create a new zip file
    String newGtfsName = fs.parseDirectory(oldGtfsName) + File.separator + fs.parseFileNameMinusExtension(oldGtfsName) + "_mod.zip";
    String basePath = fs.parseDirectory(oldGtfsName);
    String includeExpression = ".*\\.txt";
    fu.zip(newGtfsName, basePath, includeExpression);
    int deletedFiles = fu.deleteFilesInFolder(basePath, includeExpression);
    if (deletedFiles < 1) {
        throw new IllegalStateException("Missing expected modded gtfs files in directory " + basePath);
    }
    gtfsBundle.setPath(new File(newGtfsName));
    _log.info("gtfsBundle.getPath(mod)=" + gtfsBundle.getPath() + " with mappings= " + gtfsBundle.getAgencyIdMappings());
    if (getOutputDirectory() != null) {
        File outputDir = new File(getOutputDirectory() + File.separator + getDirectoryHint());
        if (!outputDir.exists() || !outputDir.isDirectory()) {
            outputDir.mkdirs();
        }
        String outputLocation = getOutputDirectory() + File.separator + getDirectoryHint() + File.separator + fs.parseFileName(newGtfsName).replaceAll("_mod", "");
        // copy to outputs for downstream systems
        NYCFileUtils.copyFile(new File(newGtfsName), new File(outputLocation));
    }
    return newGtfsName;
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) FileUtility(org.onebusaway.util.FileUtility) File(java.io.File)

Example 19 with NYCFileUtils

use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.

the class DiskFileServiceImpl method put.

@Override
public // copy file to dir
String put(String key, String directory) {
    _log.debug("put(" + key + ", " + directory + ")");
    NYCFileUtils fs = new NYCFileUtils();
    String baseDirectoryName = _basePath + File.separator + fs.parseDirectory(key);
    File baseDirectory = new File(baseDirectoryName);
    if (!baseDirectory.exists()) {
        baseDirectory.mkdirs();
    }
    String destFileName = _basePath + File.separator + key;
    File destLocation = new File(destFileName);
    File srcLocation = new File(directory);
    try {
        _log.debug("cp " + srcLocation + " " + destLocation);
        fs.copyFiles(srcLocation, destLocation);
    } catch (Exception e) {
        _log.error("put failed(" + key + ", " + directory + "):", e);
    }
    return null;
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException)

Example 20 with NYCFileUtils

use of org.onebusaway.admin.util.NYCFileUtils in project onebusaway-application-modules by camsys.

the class HastusTranslateTask method buildAgencyMap.

private void buildAgencyMap(String zipFile) {
    File auxFilePath = new File(zipFile);
    if (auxFilePath.exists() && auxFilePath.getName().contains("_")) {
        NYCFileUtils fu = new NYCFileUtils();
        String agencyId = fu.parseAgency(auxFilePath.toString());
        HastusData hd = null;
        if (agencyId != null) {
            hd = _agencyMap.get(agencyId);
        }
        if (hd == null) {
            hd = new HastusData();
            hd.setAgencyId(agencyId);
            _agencyMap.put(agencyId, hd);
        }
        if (zipFile.toUpperCase().contains("HASTUS")) {
            hd.setScheduleDataDirectory(createScheduleDataDir(zipFile));
        } else if (zipFile.toUpperCase().contains("GIS")) {
            hd.setGisDataDirectory(createGisDataDir(zipFile));
        }
    }
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) 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