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