Package org.mokai.web.admin.jogger.controllers

Source Code of org.mokai.web.admin.jogger.controllers.Connections

package org.mokai.web.admin.jogger.controllers;

import java.util.List;

import org.jogger.http.Request;
import org.jogger.http.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mokai.ConnectorService;
import org.mokai.RoutingEngine;
import org.mokai.web.admin.jogger.annotations.Secured;

/**
* Connections controller.
*
* @author German Escobar
*/
@Secured
public class Connections {

  private RoutingEngine routingEngine;

  public void index(Request request, Response response) throws JSONException {
    List<ConnectorService> connections = routingEngine.getConnections();

    JSONArray jsonConnections = new JSONArray();
    for (ConnectorService connection : connections) {
      jsonConnections.put( new ConnectorUI(connection).toJSON() );
    }

    response.contentType("application/json").print(jsonConnections.toString());
  }

  public void show(Request request, Response response) throws JSONException {
    String id = request.getPathVariable("id").asString();
    ConnectorService connectorService = routingEngine.getConnection(id);

    if (connectorService == null) {
      response.notFound();
      return;
    }

    JSONObject jsonConnector = HelperUI.getConnectorJSON(connectorService);
    response.contentType("application/json").print(jsonConnector.toString());
  }

  public void start(Request request, Response response) throws JSONException {
    String id = request.getPathVariable("id").asString();
    ConnectorService connectorService = routingEngine.getConnection(id);

    if (connectorService == null) {
      response.notFound();
      return;
    }

    connectorService.start();
  }

  public void stop(Request request, Response response) throws JSONException {
    String id = request.getPathVariable("id").asString();
    ConnectorService connectorService = routingEngine.getConnection(id);

    if (connectorService == null) {
      response.notFound();
      return;
    }

    connectorService.stop();
  }

  public void setRoutingEngine(RoutingEngine routingEngine) {
    this.routingEngine = routingEngine;
  }

}
TOP

Related Classes of org.mokai.web.admin.jogger.controllers.Connections

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.