Search in sources :

Example 6 with UserEntity

use of com.pratilipi.data.type.gae.UserEntity in project pratilipi by Pratilipi.

the class UserProcessApi method get.

@Get
public GenericResponse get(GenericRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    // Fetching AppProperty
    AppProperty appProperty = dataAccessor.getAppProperty(appPropertyId);
    if (appProperty == null) {
        appProperty = dataAccessor.newAppProperty(appPropertyId);
        appProperty.setValue(new Date(0));
    }
    List<Key<UserEntity>> keyList = ObjectifyService.ofy().load().type(UserEntity.class).filter("SIGN_UP_DATE >", appProperty.getValue()).order("SIGN_UP_DATE").limit(10000).keys().list();
    // Creating task for each user.
    List<Task> taskList = new ArrayList<>(keyList.size());
    for (Key<UserEntity> key : keyList) {
        Task task = TaskQueueFactory.newTask().setUrl("/user/process").addParam("userId", key.getId() + "").addParam("validateData", "true");
        taskList.add(task);
    }
    TaskQueueFactory.getUserOfflineTaskQueue().addAll(taskList);
    logger.log(Level.INFO, "Added " + taskList.size() + " tasks.");
    // Updating AppProperty.
    if (taskList.size() > 0) {
        appProperty.setValue(dataAccessor.getUser(keyList.get(keyList.size() - 1).getId()).getSignUpDate());
        dataAccessor.createOrUpdateAppProperty(appProperty);
    }
    return new GenericResponse();
}
Also used : Task(com.pratilipi.taskqueue.Task) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) AppProperty(com.pratilipi.data.type.AppProperty) Date(java.util.Date) UserEntity(com.pratilipi.data.type.gae.UserEntity) Key(com.googlecode.objectify.Key) Get(com.pratilipi.api.annotation.Get)

Aggregations

UserEntity (com.pratilipi.data.type.gae.UserEntity)6 User (com.pratilipi.data.type.User)4 Key (com.googlecode.objectify.Key)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 DataAccessor (com.pratilipi.data.DataAccessor)2 ConversationUserEntity (com.pratilipi.data.type.gae.ConversationUserEntity)2 Cursor (com.google.appengine.api.datastore.Cursor)1 Get (com.pratilipi.api.annotation.Get)1 Post (com.pratilipi.api.annotation.Post)1 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)1 BlobAccessor (com.pratilipi.data.BlobAccessor)1 AppProperty (com.pratilipi.data.type.AppProperty)1 Author (com.pratilipi.data.type.Author)1 BlobEntry (com.pratilipi.data.type.BlobEntry)1 ConversationUser (com.pratilipi.data.type.ConversationUser)1 AuthorEntity (com.pratilipi.data.type.gae.AuthorEntity)1 Task (com.pratilipi.taskqueue.Task)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1