Search in sources :

Example 1 with Bundle

use of org.onebusaway.admin.bundle.model.Bundle in project onebusaway-application-modules by camsys.

the class DirectoryBundleSource method checkIsValidBundleFile.

@Override
public boolean checkIsValidBundleFile(String bundleId, String relativeFilePath) {
    init();
    boolean isValid = false;
    Bundle requestedBundle;
    try {
        requestedBundle = loadBundleDirectory(bundleId);
        if (requestedBundle != null) {
            if (requestedBundle.containsFile(relativeFilePath)) {
                isValid = true;
            }
        }
    } catch (IOException e) {
        isValid = false;
    }
    return isValid;
}
Also used : Bundle(org.onebusaway.admin.bundle.model.Bundle) IOException(java.io.IOException)

Example 2 with Bundle

use of org.onebusaway.admin.bundle.model.Bundle in project onebusaway-application-modules by camsys.

the class LocalBundleDeployerServiceImpl method getBundleList.

@Override
public Response getBundleList() {
    _log.info("Starting getBundleList.");
    List<Bundle> bundles = bundleProvider.getBundles();
    Response response;
    if (bundles != null) {
        BundlesListMessage bundlesMessage = new BundlesListMessage();
        bundlesMessage.setBundles(bundles);
        bundlesMessage.setStatus("OK");
        final BundlesListMessage bundlesMessageToWrite = bundlesMessage;
        StreamingOutput output = new StreamingOutput() {

            @Override
            public void write(OutputStream out) throws IOException, WebApplicationException {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
                jsonTool.writeJson(writer, bundlesMessageToWrite);
                writer.close();
                out.close();
            }
        };
        response = Response.ok(output, "application/json").build();
    } else {
        response = Response.serverError().build();
    }
    _log.info("Returning Response in getBundleList.");
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Bundle(org.onebusaway.admin.bundle.model.Bundle) BundlesListMessage(org.onebusaway.admin.bundle.BundlesListMessage) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 3 with Bundle

use of org.onebusaway.admin.bundle.model.Bundle in project onebusaway-application-modules by camsys.

the class LocalBundleDeployerServiceImpl method getLatestBundle.

/**
 * displays the latest active bundle.
 */
@Override
public Response getLatestBundle() {
    _log.info("Starting getLatestBundle.");
    Bundle latestBundle = getLatestBundleAsBundle();
    if (latestBundle != null) {
        try {
            JSONObject response = new JSONObject();
            response.put("id", latestBundle.getId());
            response.put("dataset", latestBundle.getDataset());
            response.put("name", latestBundle.getName());
            return Response.ok(response.toString()).build();
        } catch (Exception e) {
            _log.error("Error reading latest bundle: " + e);
        }
    }
    return Response.ok("Error: No bundles deployed.").build();
}
Also used : JSONObject(org.json.JSONObject) Bundle(org.onebusaway.admin.bundle.model.Bundle) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 4 with Bundle

use of org.onebusaway.admin.bundle.model.Bundle in project onebusaway-application-modules by camsys.

the class LocalBundleDeployerServiceImpl method getLatestBundleAsBundle.

private Bundle getLatestBundleAsBundle() {
    List<Bundle> bundles = bundleProvider.getBundles();
    Bundle latestBundle = null;
    for (Bundle bundle : bundles) {
        // make sure bundle is active
        if (bundle.getServiceDateFrom().isBefore(new LocalDate()) || bundle.getServiceDateFrom().isEqual(new LocalDate())) {
            if (latestBundle == null || bundle.getCreated().isAfter(latestBundle.getCreated())) {
                latestBundle = bundle;
            }
        }
    }
    return latestBundle;
}
Also used : Bundle(org.onebusaway.admin.bundle.model.Bundle) LocalDate(org.joda.time.LocalDate)

Example 5 with Bundle

use of org.onebusaway.admin.bundle.model.Bundle in project onebusaway-application-modules by camsys.

the class DirectoryBundleSource method loadBundleMetadata.

private Bundle loadBundleMetadata(File metadataFile) throws FileNotFoundException {
    FileReader metadataReader = null;
    Bundle resultBundle = null;
    try {
        metadataReader = new FileReader(metadataFile);
        if (jsonTool == null) {
            // we have an issue with the spring configuration
            throw new RuntimeException("Configuration Error:  jsonTool not configured!");
        }
        resultBundle = jsonTool.readJson(metadataReader, Bundle.class);
    } catch (RuntimeException re) {
        _log.error("fatal configuration error!", re);
    } catch (Exception e) {
        // our bundle is corrupt or we have permissions/configuration issue
        // give up on this bundle and hope that others exist!
        _log.error("Configuration Exception:  Unable to load file " + metadataFile, e);
        return null;
    } finally {
        if (metadataReader != null)
            try {
                metadataReader.close();
            } catch (IOException e) {
            }
    }
    return resultBundle;
}
Also used : Bundle(org.onebusaway.admin.bundle.model.Bundle) FileReader(java.io.FileReader) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Bundle (org.onebusaway.admin.bundle.model.Bundle)11 IOException (java.io.IOException)7 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 BufferedWriter (java.io.BufferedWriter)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 LocalDate (org.joda.time.LocalDate)2 BundlesListMessage (org.onebusaway.admin.bundle.BundlesListMessage)2 BundleFile (org.onebusaway.admin.bundle.model.BundleFile)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 FileReader (java.io.FileReader)1 PrintWriter (java.io.PrintWriter)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DateTime (org.joda.time.DateTime)1 JSONObject (org.json.JSONObject)1