Example #1
0
  @Override
  public Application updateApplication(Application application) throws DatastoreException {

    log.debug("Updating application: [%s]", application);
    if (getApplication(application.getBareJid()) == null) {
      log.error("Application [%s] does not exist", application);
      throw new ApplicationNotFoundException();
    }
    return saveApplication(application);
  }
Example #2
0
  @Override
  public Application storeApplication(Application application) throws DatastoreException {

    log.debug("Storing application: [%s]", application);
    if (getApplication(application.getBareJid()) != null) {
      log.error("Application [%s] already exists", application);
      throw new ApplicationAlreadyExistsException();
    }

    return saveApplication(application);
  }
Example #3
0
  private void populateApplicationData(Application application, List<Column> columns) {

    for (Column column : columns) {
      String name = Bytes.toUTF8(column.getName());
      if (name.equals("appId")) {
        application.setAppId(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("platformId")) {
        application.setPlatform(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("name")) {
        application.setName(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("accountId")) {
        application.setAccountId(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("permissions")) {
        application.setPermissions(Bytes.toUTF8((column.getValue())));
      }
    }
  }
Example #4
0
  private Application saveApplication(Application application) throws DatastoreException {

    Mutator mutator = Pelops.createMutator(schemaName);

    mutator.writeColumns(
        "applications",
        application.getBareJid(),
        mutator.newColumnList(
            mutator.newColumn(Bytes.fromUTF8("appId"), Bytes.fromUTF8(application.getAppId())),
            mutator.newColumn(
                Bytes.fromUTF8("platformId"), Bytes.fromUTF8(application.getPlatform())),
            mutator.newColumn(Bytes.fromUTF8("name"), Bytes.fromUTF8(application.getName())),
            mutator.newColumn(
                Bytes.fromUTF8("accountId"), Bytes.fromUTF8(application.getAccountId())),
            mutator.newColumn(
                Bytes.fromUTF8("permissions"), Bytes.fromUTF8(application.getPermissions()))));

    try {
      mutator.execute(ConsistencyLevel.ONE);
      log.debug("Application [%s] stored successfully", application);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new DatastoreException(String.format("Could not create application [%s]", application));
    }

    return application;
  }
Example #5
0
  @Override
  public GatewayClient getClient(String jid) {

    log.debug("Finding client with jid: [%s]", jid);
    GatewayClient client = null;
    try {
      String bareJid = JIDUtils.getBareJid(jid);
      String resource = JIDUtils.getResource(jid);
      boolean resourceFound = false;

      Selector selector = Pelops.createSelector(schemaName);
      List<Column> columns =
          selector.getColumnsFromRow("clients", bareJid, false, ConsistencyLevel.ONE);
      if (columns != null && columns.size() > 0) {
        for (Column column : columns) {
          String name = Bytes.toUTF8(column.getName());
          if (name.equals(resource)) {
            resourceFound = true;
          }
        }
      }

      if (resourceFound) {
        Application application = getApplication(JIDUtils.getBareJid(jid));
        if (application != null) {
          client = new GatewayClient();
          client.setJid(jid);
          client.setPlatform(application.getPlatform());
        }
      }

    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
    }
    return client;
  }