Search in sources :

Example 21 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method createUserPratilipiData.

private static UserPratilipiData createUserPratilipiData(UserPratilipiDoc userPratilipiDoc) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUser(userPratilipiDoc.getUserId());
    UserData userData = UserDataUtil.createUserData(user);
    UserPratilipiData userPratilipiData = new UserPratilipiData();
    userPratilipiData.setId(userPratilipiDoc.getId());
    userPratilipiData.setUserId(userPratilipiDoc.getUserId());
    userPratilipiData.setUser(userData);
    userPratilipiData.setUserName(userData.getDisplayName());
    userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
    userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
    userPratilipiData.setRating(userPratilipiDoc.getRating());
    userPratilipiData.setReview(processReview(userPratilipiDoc.getReviewTitle(), userPratilipiDoc.getReview()));
    userPratilipiData.setReviewDate(userPratilipiDoc.getReviewDate());
    userPratilipiData.setLikeCount(userPratilipiDoc.getLikeCount());
    userPratilipiData.setCommentCount(userPratilipiDoc.getCommentCount());
    userPratilipiData.setLiked(userPratilipiDoc.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
    return userPratilipiData;
}
Also used : User(com.pratilipi.data.type.User) UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData)

Example 22 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class UserDataUtil method registerUser.

public static UserData registerUser(String firstName, String lastName, String email, String password, UserSignUpSource signUpSource) throws InvalidArgumentException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUserByEmail(email.toLowerCase());
    if (user == null || user.getState() == UserState.DELETED) {
        user = dataAccessor.newUser();
    } else if (user.getState() != UserState.REFERRAL) {
        JsonObject errorMessages = new JsonObject();
        errorMessages.addProperty("email", GenericRequest.ERR_EMAIL_REGISTERED_ALREADY);
        throw new InvalidArgumentException(errorMessages);
    }
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_ADD, user);
    user.setPassword(PasswordUtil.getSaltedHash(password));
    user.setEmail(email.toLowerCase());
    user.setState(UserState.REGISTERED);
    user.setSignUpDate(new Date());
    user.setSignUpSource(signUpSource);
    user = dataAccessor.createOrUpdateUser(user, auditLog);
    UserData userData = createUserData(user);
    userData.setFirstName(firstName);
    userData.setLastName(lastName);
    return userData;
}
Also used : User(com.pratilipi.data.type.User) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) JsonObject(com.google.gson.JsonObject) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 23 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class UserDataUtil method verifyUserEmail.

public static void verifyUserEmail(String email, String verificationToken) throws InvalidArgumentException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUserByEmail(email.toLowerCase());
    if (user == null || user.getState() != UserState.REGISTERED)
        return;
    if (!_verifyToken(user, verificationToken))
        throw new InvalidArgumentException(GenericRequest.ERR_VERIFICATION_TOKEN_INVALID_OR_EXPIRED);
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
    user.setState(UserState.ACTIVE);
    // Note: Do not clear VerificationToken
    user = dataAccessor.createOrUpdateUser(user, auditLog);
}
Also used : User(com.pratilipi.data.type.User) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) DataAccessor(com.pratilipi.data.DataAccessor) AuditLog(com.pratilipi.data.type.AuditLog)

Example 24 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class EmailProcessApi method get.

@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    RtdbAccessor rtdbAccessor = DataAccessorFactory.getRtdbAccessor();
    Map<Long, UserPreferenceRtdb> userPreferences = null;
    List<Email> emailList = new ArrayList<>();
    DataListIterator<Email> it = dataAccessor.getEmailListIteratorForStatePending(null, false);
    Set<Long> userIds = new HashSet<>();
    while (it.hasNext()) {
        Email email = it.next();
        emailList.add(email);
        userIds.add(email.getUserId());
    }
    userPreferences = rtdbAccessor.getUserPreferences(userIds);
    Map<Long, User> users = dataAccessor.getUsers(userPreferences.keySet());
    // Re-scheduling for all Emails
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
    for (Email email : emailList) {
        UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
        User user = users.get(email.getUserId());
        if (email.getScheduledDate().before(new Date()))
            continue;
        if (email.getScheduledDate().equals(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())))
            continue;
        logger.log(Level.INFO, "Rescheduling email: " + email.getId() + " from " + dateFormat.format(email.getScheduledDate()) + " to " + dateFormat.format(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())));
        email.setScheduledDate(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate()));
        if (// User changed setting to NEVER -> Scheduled Date will be null
        email.getScheduledDate() == null)
            email.setState(EmailState.DROPPED);
        email.setLastUpdated(new Date());
    }
    // Creating Tasks
    List<Task> taskList = new ArrayList<>();
    Set<Long> userIdTaskSet = new HashSet<>();
    for (Email email : emailList) {
        if (// User changed setting to NEVER -> Email Dropped
        email.getState() != EmailState.PENDING)
            continue;
        if (email.getScheduledDate().after(new Date()))
            continue;
        UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
        if (preference.getEmailFrequency() == EmailFrequency.IMMEDIATELY)
            taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("emailId", email.getId().toString()));
        else
            userIdTaskSet.add(email.getUserId());
        email.setState(EmailState.IN_PROGRESS);
        email.setLastUpdated(new Date());
    }
    for (Long userId : userIdTaskSet) taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("userId", userId.toString()));
    TaskQueueFactory.getEmailHpTaskQueue().addAll(taskList);
    emailList = dataAccessor.createOrUpdateEmailList(emailList);
    return new GenericResponse();
}
Also used : Task(com.pratilipi.taskqueue.Task) Email(com.pratilipi.data.type.Email) User(com.pratilipi.data.type.User) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Date(java.util.Date) RtdbAccessor(com.pratilipi.data.RtdbAccessor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) UserPreferenceRtdb(com.pratilipi.data.type.UserPreferenceRtdb) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) Get(com.pratilipi.api.annotation.Get)

Example 25 with User

use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.

the class BlogPostDataUtil method createBlogPostData.

public static BlogPostData createBlogPostData(BlogPost blogPost, Page blogPostPage) {
    BlogPostData blogPostData = new BlogPostData(blogPost.getId());
    blogPostData.setBlogId(blogPost.getBlogId());
    blogPostData.setTitle(blogPost.getTitle());
    blogPostData.setTitleEn(blogPost.getTitleEn());
    blogPostData.setContent(blogPost.getContent());
    blogPostData.setLanguage(blogPost.getLanguage());
    blogPostData.setState(blogPost.getState());
    User user = DataAccessorFactory.getDataAccessor().getUser(blogPost.getCreatedBy());
    if (user != null) {
        UserData userData = UserDataUtil.createUserData(user);
        blogPostData.setCreatedBy(userData);
    }
    blogPostData.setCreationDate(blogPost.getCreationDate());
    blogPostData.setLastUpdated(blogPost.getLastUpdated());
    blogPostData.setPageUrl(blogPostPage.getUriAlias() == null ? blogPostPage.getUri() : blogPostPage.getUriAlias());
    blogPostData.setAccessToUpdate(hasAccessToUpdateBlogPostData(blogPost, null));
    return blogPostData;
}
Also used : User(com.pratilipi.data.type.User) UserData(com.pratilipi.data.client.UserData) BlogPostData(com.pratilipi.data.client.BlogPostData)

Aggregations

User (com.pratilipi.data.type.User)30 DataAccessor (com.pratilipi.data.DataAccessor)22 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)9 AuditLog (com.pratilipi.data.type.AuditLog)8 UserData (com.pratilipi.data.client.UserData)7 UserEntity (com.pratilipi.data.type.gae.UserEntity)7 Date (java.util.Date)7 Author (com.pratilipi.data.type.Author)6 ConversationUser (com.pratilipi.data.type.ConversationUser)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)4 ConversationUserEntity (com.pratilipi.data.type.gae.ConversationUserEntity)4 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 Get (com.pratilipi.api.annotation.Get)2 BlobAccessor (com.pratilipi.data.BlobAccessor)2 DocAccessor (com.pratilipi.data.DocAccessor)2