Search in sources :

Example 11 with QueryBuilder

use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.

the class DAOTest method testQueryEmbededCollections.

// [TransientObject{
// user_data={players_key=[2]}
// , meta_data={object_type=com.jug6ernaut.tactics.client.web.WGame, getKey()=049d74c7-511c-49ef-a312-3a782f2f41e3, create_date_key=1384732193542, modified_date_key=1384732193543}
// }]
// [TestObject1{
// user_data={players_key=[2]}
// , meta_data={object_type=io.divide.authenticator.se, create_date_key=1384733366530, getKey()=e842d295-cee8-45da-83df-d235f5b1801f, modified_date_key=1384733366530}
// }]
@Test
public void testQueryEmbededCollections() throws Exception {
    TestObject1 t1 = new TestObject1();
    List<String> l1 = Arrays.asList("2");
    t1.put("players_key", l1);
    System.out.println("embeded: " + Arrays.asList(t1));
    TestObject1 t2 = new TestObject1();
    List<String> l2 = Arrays.asList("3", "4", "5");
    t2.put("players_key", l2);
    dao.save(t1, t2);
    Query q = new QueryBuilder().select().from(TestObject1.class).where("players_key", OPERAND.CONTAINS, "2").build();
    List<TransientObject> results = dao.query(q);
    assertNotEquals(null, results);
    assertEquals(1, results.size());
    assertEquals(t1.getObjectKey(), ObjectUtils.get1stOrNull(results).getObjectKey());
    assertEquals(l1, ObjectUtils.get1stOrNull(results).get(l1.getClass(), "players_key"));
    q = new QueryBuilder().select().from(TestObject1.class).where("players_key", OPERAND.CONTAINS, "4").build();
    results = dao.query(q);
    assertNotEquals(null, results);
    assertEquals(1, results.size());
    assertEquals(t2.getObjectKey(), ObjectUtils.get1stOrNull(results).getObjectKey());
    assertEquals(l2, ObjectUtils.get1stOrNull(results).get(l2.getClass(), "players_key"));
    Gson g = new GsonBuilder().create();
    g.fromJson(g.toJson(t1), TransientObject.class);
}
Also used : Query(io.divide.shared.transitory.query.Query) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) TransientObject(io.divide.shared.transitory.TransientObject) Test(org.junit.Test)

Example 12 with QueryBuilder

use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.

the class DaoUtils method getUserById.

/**
 * Convience method to do a Credentials query against an user id.
 * @param serverDao dao object to query against.
 * @param userId user id used in query.
 * @return Credentials object found or null.
 * @throws io.divide.shared.server.DAO.DAOException
 */
public static Credentials getUserById(DAO serverDao, String userId) throws DAO.DAOException {
    Query query = new QueryBuilder().select().from(Credentials.class).where(Credentials.OWNER_ID_KEY, OPERAND.EQ, userId).build();
    TransientObject to = (TransientObject) ObjectUtils.get1stOrNull(serverDao.query(query));
    if (to == null) {
        return null;
    } else {
        return to(Credentials.class, to);
    }
}
Also used : Query(io.divide.shared.transitory.query.Query) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) TransientObject(io.divide.shared.transitory.TransientObject)

Example 13 with QueryBuilder

use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.

the class AuthServerLogic method validateAccount.

/**
 * Validate a user account
 * @param token
 */
public boolean validateAccount(String token) throws DAOException {
    Query q = new QueryBuilder().select().from(Credentials.class).where("validation", OPERAND.EQ, token).build();
    TransientObject to = ObjectUtils.get1stOrNull(dao.query(q));
    if (to != null) {
        ServerCredentials creds = new ServerCredentials(to);
        creds.setValidation("1");
        dao.save(creds);
        return true;
    } else {
        return false;
    }
}
Also used : Query(io.divide.shared.transitory.query.Query) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) TransientObject(io.divide.shared.transitory.TransientObject)

Example 14 with QueryBuilder

use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.

the class AuthServerLogic method getUserFromRecoveryToken.

public Credentials getUserFromRecoveryToken(String token) throws DAOException {
    Query q = new QueryBuilder().select().from(Credentials.class).where(Credentials.RECOVERY_TOKEN_KEY, OPERAND.EQ, token).build();
    TransientObject to = ObjectUtils.get1stOrNull(dao.query(q));
    if (to != null) {
        ServerCredentials sc = new ServerCredentials(to);
        sc.setAuthToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), sc));
        sc.setRecoveryToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), sc));
        dao.save(sc);
        return sc;
    } else {
        throw new DAOException(HttpStatus.SC_BAD_REQUEST, "invalid recovery token");
    }
}
Also used : DAOException(io.divide.shared.server.DAO.DAOException) Query(io.divide.shared.transitory.query.Query) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) TransientObject(io.divide.shared.transitory.TransientObject)

Aggregations

QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)14 Query (io.divide.shared.transitory.query.Query)12 TransientObject (io.divide.shared.transitory.TransientObject)10 Test (org.junit.Test)4 BackendObject (io.divide.client.BackendObject)2 ServerDAO (io.divide.dao.ServerDAO)2 DAOException (io.divide.shared.server.DAO.DAOException)2 AuthTokenUtils (io.divide.shared.util.AuthTokenUtils)2 Collection (java.util.Collection)2 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 OnClick (butterknife.OnClick)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1