Search in sources :

Example 11 with Bundle

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

the class LocalBundleStagerServiceImpl 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)

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