コード例 #1
0
ファイル: UserService.java プロジェクト: neshte/baasbox
  public static ODocument updateProfile(
      ODocument profile,
      JsonNode nonAppUserAttributes,
      JsonNode privateAttributes,
      JsonNode friendsAttributes,
      JsonNode appUsersAttributes)
      throws Exception {
    if (nonAppUserAttributes != null) {
      ODocument attrObj = profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER);
      if (attrObj == null) attrObj = new ODocument(UserDao.USER_ATTRIBUTES_CLASS);
      attrObj.fromJSON(nonAppUserAttributes.toString());
      PermissionsHelper.grantRead(
          attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
      PermissionsHelper.grantRead(attrObj, RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString()));
      PermissionsHelper.grantRead(attrObj, RoleDao.getFriendRole());
      profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER, attrObj);
      attrObj.save();
    }
    if (privateAttributes != null) {
      ODocument attrObj = profile.field(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER);
      if (attrObj == null) attrObj = new ODocument(UserDao.USER_ATTRIBUTES_CLASS);
      attrObj.fromJSON(privateAttributes.toString());
      PermissionsHelper.grant(
          attrObj, Permissions.ALLOW, getOUserByUsername(getUsernameByProfile(profile)));
      profile.field(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER, attrObj);
      attrObj.save();
    }
    if (friendsAttributes != null) {
      ODocument attrObj = profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER);
      if (attrObj == null) attrObj = new ODocument(UserDao.USER_ATTRIBUTES_CLASS);
      attrObj.fromJSON(friendsAttributes.toString());
      PermissionsHelper.grantRead(attrObj, RoleDao.getFriendRole());
      profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER, attrObj);
      attrObj.save();
    }
    if (appUsersAttributes != null) {
      ODocument attrObj = profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER);
      if (attrObj == null) attrObj = new ODocument(UserDao.USER_ATTRIBUTES_CLASS);
      attrObj.fromJSON(appUsersAttributes.toString());
      PermissionsHelper.grantRead(
          attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
      PermissionsHelper.grantRead(attrObj, RoleDao.getFriendRole());
      profile.field(UserDao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER, attrObj);
      attrObj.save();
    }

    profile.save();
    return profile;
  }
コード例 #2
0
  @BeforeClass
  public void beforeClass() throws Exception {
    db = new ODatabaseDocumentTx(DB_STORAGE + ":" + DB_NAME);
    db.create();
    getProfilerInstance().startRecording();

    db.command(new OCommandSQL("CREATE class foo")).execute();
    db.command(new OCommandSQL("CREATE property foo.name STRING")).execute();
    db.command(new OCommandSQL("CREATE property foo.bar INTEGER")).execute();
    db.command(new OCommandSQL("CREATE property foo.address EMBEDDED")).execute();
    db.command(new OCommandSQL("CREATE property foo.comp STRING")).execute();
    db.command(new OCommandSQL("CREATE property foo.osite INTEGER")).execute();

    db.command(new OCommandSQL("CREATE index foo_name on foo (name) NOTUNIQUE")).execute();
    db.command(new OCommandSQL("CREATE index foo_bar on foo (bar) NOTUNIQUE")).execute();
    db.command(new OCommandSQL("CREATE index foo_comp_osite on foo (comp, osite) NOTUNIQUE"))
        .execute();

    db.command(
            new OCommandSQL(
                "insert into foo (name, bar, address) values ('a', 1, {'street':'1st street', 'city':'NY', '@type':'d'})"))
        .execute();
    db.command(new OCommandSQL("insert into foo (name, bar) values ('b', 2)")).execute();
    db.command(new OCommandSQL("insert into foo (name, bar) values ('c', 3)")).execute();

    db.command(new OCommandSQL("insert into foo (comp, osite) values ('a', 1)")).execute();
    db.command(new OCommandSQL("insert into foo (comp, osite) values ('b', 2)")).execute();

    db.command(new OCommandSQL("CREATE class bar")).execute();

    db.command(new OCommandSQL("insert into bar (name, foo) values ('a', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('b', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('c', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('d', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('e', 5)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('f', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('g', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('h', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('i', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('j', 5)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('k', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('l', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('m', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('n', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('o', 5)")).execute();

    db.command(new OCommandSQL("CREATE class ridsorttest")).execute();
    db.command(new OCommandSQL("CREATE property ridsorttest.name INTEGER")).execute();
    db.command(new OCommandSQL("CREATE index ridsorttest_name on ridsorttest (name) NOTUNIQUE"))
        .execute();

    db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (5)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (3)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (4)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (8)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (6)")).execute();

    db.command(new OCommandSQL("CREATE class unwindtest")).execute();
    db.command(
            new OCommandSQL("insert into unwindtest (name, coll) values ('foo', ['foo1', 'foo2'])"))
        .execute();
    db.command(
            new OCommandSQL("insert into unwindtest (name, coll) values ('bar', ['bar1', 'bar2'])"))
        .execute();

    db.command(new OCommandSQL("CREATE class edge")).execute();

    db.command(new OCommandSQL("CREATE class TestFromInSquare")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestFromInSquare set tags = {' from ':'foo',' to ':'bar'}"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestMultipleClusters")).execute();
    db.command(
            new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters1 "))
        .execute();
    db.command(
            new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters2 "))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters set name = 'aaa'"))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters1 set name = 'foo'"))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters2 set name = 'bar'"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestUrl")).execute();
    db.command(
            new OCommandSQL("insert into TestUrl content { \"url\": \"http://www.google.com\" }"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestParams")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestParams  set name = 'foo', surname ='foo', active = true"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into TestParams  set name = 'foo', surname ='bar', active = false"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestParamsEmbedded")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestParamsEmbedded set emb = {  \n"
                    + "            \"count\":0,\n"
                    + "            \"testupdate\":\"1441258203385\"\n"
                    + "         }"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into TestParamsEmbedded set emb = {  \n"
                    + "            \"count\":1,\n"
                    + "            \"testupdate\":\"1441258203385\"\n"
                    + "         }"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestBacktick")).execute();
    db.command(new OCommandSQL("insert into TestBacktick  set foo = 1, bar = 2, `foo-bar` = 10"))
        .execute();

    // /*** from issue #2743
    OSchema schema = db.getMetadata().getSchema();
    if (!schema.existsClass("alphabet")) {
      schema.createClass("alphabet");
    }

    ORecordIteratorClass<ODocument> iter = db.browseClass("alphabet");
    while (iter.hasNext()) {
      iter.next().delete();
    }

    // add 26 entries: { "letter": "A", "number": 0 }, ... { "letter": "Z", "number": 25 }

    String rowModel = "{\"letter\": \"%s\", \"number\": %d}";
    for (int i = 0; i < 26; ++i) {
      String l = String.valueOf((char) ('A' + i));
      String json = String.format(rowModel, l, i);
      ODocument doc = db.newInstance("alphabet");
      doc.fromJSON(json);
      doc.save();
    }

    db.command(new OCommandSQL("create class OCommandExecutorSQLSelectTest_aggregations"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into OCommandExecutorSQLSelectTest_aggregations set data = [{\"size\": 0}, {\"size\": 0}, {\"size\": 30}, {\"size\": 50}, {\"size\": 50}]"))
        .execute();

    initExpandSkipLimit(db);

    initMassiveOrderSkipLimit(db);
    initDatesSet(db);

    initMatchesWithRegex(db);
    initDistinctLimit(db);
  }
コード例 #3
0
ファイル: UserService.java プロジェクト: neshte/baasbox
  public static ODocument signUp(
      String username,
      String password,
      Date signupDate,
      String role,
      JsonNode nonAppUserAttributes,
      JsonNode privateAttributes,
      JsonNode friendsAttributes,
      JsonNode appUsersAttributes,
      boolean generated)
      throws OSerializationException, Exception {

    ODatabaseRecordTx db = DbHelper.getConnection();
    ODocument profile = null;
    UserDao dao = UserDao.getInstance();
    try {
      // because we have to create an OUser record and a User Object, we need a transaction

      DbHelper.requestTransaction();

      if (role == null) profile = dao.create(username, password);
      else profile = dao.create(username, password, role);

      ORID userRid = ((ODocument) profile.field("user")).getIdentity();
      ORole friendRole = RoleDao.createFriendRole(username);
      friendRole.getDocument().field(RoleService.FIELD_ASSIGNABLE, true);
      friendRole.getDocument().field(RoleService.FIELD_MODIFIABLE, false);
      friendRole.getDocument().field(RoleService.FIELD_INTERNAL, true);
      friendRole
          .getDocument()
          .field(RoleService.FIELD_DESCRIPTION, "These are friends of " + username);

      /*    these attributes are visible by:
       *    Anonymous users
       *    Registered user
       *    Friends
       *    User
       */

      // anonymous
      {
        ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
        try {
          if (nonAppUserAttributes != null) attrObj.fromJSON(nonAppUserAttributes.toString());
          else attrObj.fromJSON("{}");
        } catch (OSerializationException e) {
          throw new OSerializationException(
              dao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER + " is not a valid JSON object", e);
        }
        PermissionsHelper.grantRead(
            attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
        PermissionsHelper.grantRead(
            attrObj, RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString()));
        PermissionsHelper.grantRead(attrObj, friendRole);
        PermissionsHelper.changeOwner(attrObj, userRid);
        profile.field(dao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER, attrObj);
        attrObj.save();
      }

      /*    these attributes are visible by:
       *    User
       */
      {
        ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
        try {
          if (privateAttributes != null) attrObj.fromJSON(privateAttributes.toString());
          else attrObj.fromJSON("{}");
        } catch (OSerializationException e) {
          throw new OSerializationException(
              dao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER + " is not a valid JSON object", e);
        }
        profile.field(dao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER, attrObj);
        PermissionsHelper.changeOwner(attrObj, userRid);
        attrObj.save();
      }

      /*    these attributes are visible by:
       *    Friends
       *    User
       */
      {
        ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
        try {
          if (friendsAttributes != null) attrObj.fromJSON(friendsAttributes.toString());
          else attrObj.fromJSON("{}");
        } catch (OSerializationException e) {
          throw new OSerializationException(
              dao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER + " is not a valid JSON object", e);
        }
        PermissionsHelper.grantRead(attrObj, friendRole);
        PermissionsHelper.changeOwner(attrObj, userRid);
        profile.field(dao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER, attrObj);
        attrObj.save();
      }

      /*    these attributes are visible by:
       *    Registered user
       *    Friends
       *    User
       */
      {
        ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
        try {
          if (appUsersAttributes != null) attrObj.fromJSON(appUsersAttributes.toString());
          else attrObj.fromJSON("{}");
        } catch (OSerializationException e) {
          throw new OSerializationException(
              dao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER + " is not a valid JSON object", e);
        }
        PermissionsHelper.grantRead(
            attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
        PermissionsHelper.changeOwner(attrObj, userRid);
        profile.field(dao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER, attrObj);
        attrObj.save();
      }

      ODocument attrObj = new ODocument(dao.USER_ATTRIBUTES_CLASS);
      attrObj.field(dao.USER_LOGIN_INFO, new ArrayList());
      attrObj.field(UserDao.GENERATED_USERNAME, generated);
      PermissionsHelper.grantRead(
          attrObj, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
      PermissionsHelper.changeOwner(attrObj, userRid);
      profile.field(dao.ATTRIBUTES_SYSTEM, attrObj);

      PermissionsHelper.grantRead(
          profile, RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString()));
      PermissionsHelper.grantRead(profile, RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString()));
      PermissionsHelper.changeOwner(profile, userRid);

      profile.field(dao.USER_SIGNUP_DATE, signupDate == null ? new Date() : signupDate);
      profile.save();

      DbHelper.commitTransaction();
    } catch (OSerializationException e) {
      DbHelper.rollbackTransaction();
      throw e;
    } catch (Exception e) {
      DbHelper.rollbackTransaction();
      throw e;
    }
    return profile;
  } // signUp