Search in sources :

Example 16 with TransientObject

use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.

the class ObjectifyDAO method save.

@Override
public void save(TransientObject... objects) throws DAOException {
    logger.info("save(): " + ObjectUtils.v2c(objects));
    try {
        for (TransientObject bo : objects) {
            ofy().save().entities(BackendToOfy.getOfy(bo)).now();
        }
    } catch (Exception e) {
        throw new DAOException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    logger.info("Save Complete.");
}
Also used : TransientObject(io.divide.shared.transitory.TransientObject) NotImplementedException(sun.reflect.generics.reflectiveObjects.NotImplementedException)

Example 17 with TransientObject

use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.

the class ObjectifyDAO method exists.

@Override
public boolean exists(TransientObject... objects) {
    logger.info("exists: " + ObjectUtils.v2c(objects));
    boolean exists = true;
    for (TransientObject bo : objects) {
        if (!exists(bo.getObjectKey()))
            exists = false;
    }
    return exists;
}
Also used : TransientObject(io.divide.shared.transitory.TransientObject)

Example 18 with TransientObject

use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.

the class PushEndpointTest method testUnregister.

//
@Test
public void testUnregister() throws Exception {
    Credentials user = AuthenticationEndpointTest.signUpUser(this);
    PublicKey key = AuthenticationEndpointTest.getPublicKey(this);
    Response tokenResponse = registerToken(user, key, this);
    String newAuthToken = tokenResponse.getHeaderString("Authorization");
    Response response = target("/push").request().header(ContainerRequest.AUTHORIZATION, "CUSTOM " + newAuthToken).delete();
    int statusCode = response.getStatus();
    assertEquals(200, statusCode);
    Collection<TransientObject> list = container.serverDao.get(Query.safeTable(Credentials.class), user.getObjectKey());
    TransientObject o = ObjectUtils.get1stOrNull(list);
    user = TestUtils.convert(o, Credentials.class);
    assertNotNull(user);
    // check the token was actually saved
    assertEquals("", user.getPushMessagingKey());
}
Also used : Response(javax.ws.rs.core.Response) PublicKey(java.security.PublicKey) TransientObject(io.divide.shared.transitory.TransientObject) Credentials(io.divide.shared.transitory.Credentials) ServerTest(io.divide.server.ServerTest) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 19 with TransientObject

use of io.divide.shared.transitory.TransientObject 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)

Example 20 with TransientObject

use of io.divide.shared.transitory.TransientObject 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)

Aggregations

TransientObject (io.divide.shared.transitory.TransientObject)21 QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)10 Query (io.divide.shared.transitory.query.Query)9 Test (org.junit.Test)6 OTransaction (com.orientechnologies.orient.core.tx.OTransaction)3 NotImplementedException (sun.reflect.generics.reflectiveObjects.NotImplementedException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ServerTest (io.divide.server.ServerTest)2 DAOException (io.divide.shared.server.DAO.DAOException)2 Credentials (io.divide.shared.transitory.Credentials)2 AuthTokenUtils (io.divide.shared.util.AuthTokenUtils)2 PublicKey (java.security.PublicKey)2 ArrayList (java.util.ArrayList)2 JerseyTest (org.glassfish.jersey.test.JerseyTest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeLiteral (com.google.inject.TypeLiteral)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 CommitExpection (iBoxDB.LocalServer.E.CommitExpection)1 MockKeyManager (io.divide.client.auth.MockKeyManager)1