Esempio n. 1
0
  public void save(Service service) throws MongoException {
    BasicDBObject serviceDoc = new BasicDBObject();

    serviceDoc.put("name", service.getName());
    serviceDoc.put("uri", service.getUri());
    serviceDoc.put("state", service.getState());

    if (service.getParams() != null) {
      ArrayList<Param> params = service.getParams();
      ArrayList paramsToDoc = new ArrayList();
      for (Param param : params) {
        BasicDBObject paramDoc = new BasicDBObject();
        paramDoc.put("name", param.getName());
        paramDoc.put("required", param.getRequired());
        paramsToDoc.add(paramDoc);
      }
      serviceDoc.put("params", paramsToDoc);
    }

    if (service.getPlugins() != null) {
      ArrayList<Plugin> plugins = service.getPlugins();
      ArrayList pluginsToDoc = new ArrayList();
      for (Plugin plugin : plugins) {
        BasicDBObject pluginDoc = new BasicDBObject();
        pluginDoc.put("class_name", plugin.getClassName());
        pluginDoc.put("type", plugin.getType());
        pluginsToDoc.add(pluginDoc);
      }
      serviceDoc.put("plugins", pluginsToDoc);
    }

    System.out.println(serviceDoc.toString());

    this.services.insert(serviceDoc);
  }
Esempio n. 2
0
  public void update(String name, Service newService) throws MongoException {
    BasicDBObject query = new BasicDBObject("name", name);
    DBObject resp;
    DBCursor cur;

    cur = this.services.find(query);

    resp = cur.next();

    if (resp != null) {
      BasicDBObject serviceDoc = new BasicDBObject();

      if (newService.getName() != null) {
        serviceDoc.put("name", newService.getName());
      } else {
        serviceDoc.put("name", (String) resp.get("name"));
      }

      if (newService.getUri() != null) {
        serviceDoc.put("uri", newService.getUri());
      } else {
        serviceDoc.put("uri", (String) resp.get("uri"));
      }

      if (newService.getState() != null) {
        serviceDoc.put("state", newService.getState());
      } else {
        serviceDoc.put("state", (String) resp.get("state"));
      }

      ArrayList<Param> params = newService.getParams();

      if (params != null) {
        ArrayList paramsToDoc = new ArrayList();

        for (Param param : params) {
          BasicDBObject paramDoc = new BasicDBObject();
          paramDoc.put("name", param.getName());
          paramDoc.put("required", param.getRequired());
          paramsToDoc.add(paramDoc);
        }
        serviceDoc.put("params", paramsToDoc);
      } else {
        serviceDoc.put("params", resp.get("params"));
      }

      ArrayList<Plugin> plugins = newService.getPlugins();

      if (plugins != null) {
        ArrayList pluginsToDoc = new ArrayList();

        for (Plugin plugin : plugins) {
          BasicDBObject pluginDoc = new BasicDBObject();
          pluginDoc.put("class_name", plugin.getClassName());
          pluginDoc.put("type", plugin.getType());
          pluginsToDoc.add(pluginDoc);
        }
        serviceDoc.put("plugins", pluginsToDoc);
      } else {
        serviceDoc.put("plugins", resp.get("plugins"));
      }

      this.services.update(new BasicDBObject().append("name", name), serviceDoc);
    }
  }