Search in sources :

Example 1 with EntityNotFoundException

use of com.google.appengine.api.datastore.EntityNotFoundException in project spring-security by spring-projects.

the class GaeDatastoreUserRegistry method findUser.

public GaeUser findUser(String userId) {
    Key key = KeyFactory.createKey(USER_TYPE, userId);
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    try {
        Entity user = datastore.get(key);
        long binaryAuthorities = (Long) user.getProperty(USER_AUTHORITIES);
        Set<AppRole> roles = EnumSet.noneOf(AppRole.class);
        for (AppRole r : AppRole.values()) {
            if ((binaryAuthorities & (1 << r.getBit())) != 0) {
                roles.add(r);
            }
        }
        GaeUser gaeUser = new GaeUser(user.getKey().getName(), (String) user.getProperty(USER_NICKNAME), (String) user.getProperty(USER_EMAIL), (String) user.getProperty(USER_FORENAME), (String) user.getProperty(USER_SURNAME), roles, (Boolean) user.getProperty(USER_ENABLED));
        return gaeUser;
    } catch (EntityNotFoundException e) {
        logger.debug(userId + " not found in datastore");
        return null;
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) AppRole(samples.gae.security.AppRole) DatastoreService(com.google.appengine.api.datastore.DatastoreService) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) Key(com.google.appengine.api.datastore.Key)

Example 2 with EntityNotFoundException

use of com.google.appengine.api.datastore.EntityNotFoundException in project iosched by google.

the class ApiKeyInitializer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
    Entity entity;
    try {
        entity = datastore.get(key);
    } catch (EntityNotFoundException e) {
        entity = new Entity(key);
        // NOTE: it's not possible to change entities in the local server, so
        // it will be necessary to hardcode the API key below if you are running
        // it locally.
        entity.setProperty(ACCESS_KEY_FIELD, API_KEY);
        datastore.put(entity);
        mLogger.severe("Created fake key. Please go to App Engine admin " + "console, change its value to your API Key (the entity " + "type is '" + ENTITY_KIND + "' and its field to be changed is '" + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
    String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) DatastoreService(com.google.appengine.api.datastore.DatastoreService) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) Key(com.google.appengine.api.datastore.Key)

Example 3 with EntityNotFoundException

use of com.google.appengine.api.datastore.EntityNotFoundException in project iosched by google.

the class ApiKeyInitializer method getKey.

/**
     * Gets the access key.
     */
protected String getKey() {
    com.google.appengine.api.datastore.DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
    String apiKey = "";
    try {
        Entity entity = datastore.get(key);
        apiKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    } catch (EntityNotFoundException e) {
        mLogger.severe("Exception will retrieving the API Key" + e.toString());
    }
    return apiKey;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) DatastoreService(com.google.appengine.api.datastore.DatastoreService) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) Key(com.google.appengine.api.datastore.Key)

Example 4 with EntityNotFoundException

use of com.google.appengine.api.datastore.EntityNotFoundException in project siena by mandubian.

the class GaePersistenceManager method getByKey.

public <T> T getByKey(Class<T> clazz, Object key) {
    Key gKey = GaeMappingUtils.makeKeyFromId(clazz, key);
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    try {
        Entity entity = ds.get(gKey);
        T obj = null;
        if (entity != null) {
            obj = Util.createObjectInstance(clazz);
            GaeMappingUtils.fillModelAndKey(obj, entity);
            // related fields (Many<T> management mainly)
            if (!info.ownedFields.isEmpty()) {
                mapOwned(obj);
            }
            // aggregated management
            if (!info.aggregatedFields.isEmpty()) {
                mapAggregated(obj);
            }
            // join management
            if (!info.joinFields.isEmpty()) {
                mapJoins(obj);
            }
        }
        return obj;
    } catch (EntityNotFoundException e) {
        return null;
    } catch (Exception e) {
        throw new SienaException(e);
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) SienaException(siena.SienaException) Key(com.google.appengine.api.datastore.Key) SienaException(siena.SienaException) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) ClassInfo(siena.ClassInfo)

Aggregations

Entity (com.google.appengine.api.datastore.Entity)4 EntityNotFoundException (com.google.appengine.api.datastore.EntityNotFoundException)4 Key (com.google.appengine.api.datastore.Key)4 DatastoreService (com.google.appengine.api.datastore.DatastoreService)3 AppRole (samples.gae.security.AppRole)1 ClassInfo (siena.ClassInfo)1 SienaException (siena.SienaException)1