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);
}
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);
}
}
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;
}
}
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");
}
}
Aggregations