Example #1
0
  public static void moveUsersToRole(String from, String to) {
    String sqlAdd = "update ouser add roles = {TO_ROLE} where roles contains {FROM_ROLE}";
    String sqlRemove = "update ouser remove roles = {FROM_ROLE} where roles contains {FROM_ROLE}";
    ORole fromRole = RoleDao.getRole(from);
    ORole toRole = RoleDao.getRole(to);

    ORID fromRID = fromRole.getDocument().getRecord().getIdentity();
    ORID toRID = toRole.getDocument().getRecord().getIdentity();

    sqlAdd =
        sqlAdd.replace("{TO_ROLE}", toRID.toString()).replace("{FROM_ROLE}", fromRID.toString());
    sqlRemove =
        sqlRemove.replace("{TO_ROLE}", toRID.toString()).replace("{FROM_ROLE}", fromRID.toString());

    GenericDao.getInstance().executeCommand(sqlAdd, new String[] {});
    GenericDao.getInstance().executeCommand(sqlRemove, new String[] {});
  }
Example #2
0
 public static void addUserToRole(String username, String role) {
   boolean admin = true;
   if (!DbHelper.currentUsername().equals(BBConfiguration.getBaasBoxAdminUsername())) {
     DbHelper.reconnectAsAdmin();
     admin = false;
   }
   String sqlAdd = "update ouser add roles = {TO_ROLE} where name = ?";
   ORole toRole = RoleDao.getRole(role);
   ORID toRID = toRole.getDocument().getRecord().getIdentity();
   sqlAdd = sqlAdd.replace("{TO_ROLE}", toRID.toString());
   GenericDao.getInstance().executeCommand(sqlAdd, new String[] {username});
   if (!admin) {
     DbHelper.reconnectAsAuthenticatedUser();
   }
 }
Example #3
0
 public static void removeUserFromRole(String username, String role) {
   boolean admin = false;
   if (!DbHelper.currentUsername().equals(BBConfiguration.getBaasBoxAdminUsername())) {
     DbHelper.reconnectAsAdmin();
     admin = true;
   }
   String sqlRemove =
       "update ouser remove roles = {FROM_ROLE} where roles contains {FROM_ROLE} and name = ?";
   ORole fromRole = RoleDao.getRole(role);
   ORID fromRID = fromRole.getDocument().getRecord().getIdentity();
   sqlRemove = sqlRemove.replace("{FROM_ROLE}", fromRID.toString());
   GenericDao.getInstance().executeCommand(sqlRemove, new String[] {username});
   if (admin) {
     DbHelper.reconnectAsAuthenticatedUser();
   }
 }
Example #4
0
File: DB.java Project: o-nix/Kafra
  protected Object wrap(ODocument document) {
    Context context = Context.getCurrentContext();
    Scriptable scope = getParentScope();
    ScriptableObject current = (ScriptableObject) context.newObject(scope);

    for (String key : document.fieldNames()) {
      if (!key.startsWith("_")) {
        Object value = document.field(key);

        if (value instanceof ODocument) value = wrap((ODocument) value);
        else if (value instanceof List) value = wrap((List<?>) value);
        else value = Context.javaToJS(value, scope);

        current.put(key, current, value);
      }
    }

    ORID id = document.getIdentity();

    if (!id.isNew()) current.put("id", current, id.toString());

    // if (proxy == null) {
    String function;

    try {
      function = Files.toString(new File("scripts/me/o_nix/db/DB.template"), Charsets.UTF_8);
    } catch (IOException e) {
      throw new RuntimeException("DB script file not found.", e);
    }

    proxy = context.compileFunction(current, function, getClass().getSimpleName(), 0, null);
    // }

    // proxy.setParentScope(current);

    current.putConst("__noSuchMethod__", current, proxy);
    current.putConst("__original__", current, Context.javaToJS(document, scope));

    return current;
  }
 public final Object getORIDAsString() {
   final ORID aOrid = getORID();
   if (aOrid == null) return null;
   return aOrid.toString();
 }