Search in sources :

Example 91 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserDataUtil method sendPasswordResetMail.

public static void sendPasswordResetMail(String email, Language language) throws InvalidArgumentException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUserByEmail(email.toLowerCase());
    if (user == null)
        throw new InvalidArgumentException(GenericRequest.ERR_EMAIL_NOT_REGISTERED);
    String verificationToken = _getNextToken(user.getVerificationToken());
    if (!verificationToken.equals(user.getVerificationToken())) {
        user.setVerificationToken(verificationToken);
        user = dataAccessor.createOrUpdateUser(user);
    }
    Map<String, String> dataModel = new HashMap<>();
    String passwordResetUrl = "/" + "?" + "email=" + user.getEmail() + "&" + "token=" + verificationToken.substring(0, verificationToken.indexOf("|")) + "&" + "passwordReset=" + Boolean.TRUE;
    dataModel.put("passwordResetUrl", passwordResetUrl);
    EmailUtil.sendMail(createUserData(user).getDisplayName(), user.getEmail(), "password-reset", language, dataModel);
}
Also used : User(com.pratilipi.data.type.User) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor)

Example 92 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserDataUtil method saveUserData.

public static UserData saveUserData(UserData userData) throws InvalidArgumentException, InsufficientAccessException {
    _validateUserDataForSave(userData);
    boolean isNew = userData.getId() == null;
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = isNew ? dataAccessor.newUser() : dataAccessor.getUser(userData.getId());
    if (isNew && !hasAccessToAddUserData(userData))
        throw new InsufficientAccessException();
    if (!isNew && !hasAccessToUpdateUserData(user, userData))
        throw new InsufficientAccessException();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.USER_ADD : AccessType.USER_UPDATE, user);
    if (userData.hasEmail() && !userData.getEmail().equals(user.getEmail())) {
        user.setEmail(userData.getEmail());
        if (user.getState() == UserState.ACTIVE)
            user.setState(UserState.REGISTERED);
        user.setVerificationToken(null);
    }
    if (userData.hasPhone())
        user.setPhone(userData.getPhone());
    if (userData.hasLanguage())
        user.setLanguage(userData.getLanguage());
    if (isNew) {
        // Assuming only AEEs have USER_ADD access.
        user.setState(UserState.REFERRAL);
        user.setCampaign(UserCampaign.AEE_TEAM);
        user.setReferrer(AccessTokenFilter.getAccessToken().getUserId().toString());
        user.setSignUpDate(new Date());
        user.setSignUpSource(getUserSignUpSource(false, false));
    }
    user.setLastUpdated(new Date());
    user = dataAccessor.createOrUpdateUser(user, auditLog);
    if (isNew) {
        String firstName = userData.getFirstName();
        String lastName = userData.getLastName();
        userData = createUserData(user, null);
        userData.setFirstName(firstName);
        userData.setLastName(lastName);
    } else {
        userData = createUserData(user);
    }
    return userData;
}
Also used : User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 93 with DataAccessor

use of com.pratilipi.data.DataAccessor 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 94 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method getUserLibrary.

public static DataListCursorTuple<PratilipiData> getUserLibrary(Long userId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    DataListCursorTuple<Long> pratilipiIdListCursorTuple = dataAccessor.getUserLibrary(userId, cursor, offset, resultCount);
    return new DataListCursorTuple<PratilipiData>(PratilipiDataUtil.createPratilipiDataList(pratilipiIdListCursorTuple.getDataList(), true), pratilipiIdListCursorTuple.getCursor());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DataAccessor(com.pratilipi.data.DataAccessor)

Example 95 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method saveUserPratilipiAddToLibrary.

public static UserPratilipiData saveUserPratilipiAddToLibrary(Long userId, Long pratilipiId, String lastOpenedPage, Boolean addedToLibrary) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
    if (userPratilipi == null) {
        userPratilipi = dataAccessor.newUserPratilipi();
        userPratilipi.setUserId(userId);
        userPratilipi.setPratilipiId(pratilipiId);
    }
    if (lastOpenedPage == null && addedToLibrary == null)
        return createUserPratilipiData(userPratilipi);
    if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_LIBRARY))
        throw new InsufficientAccessException();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_LIBRARY, userPratilipi);
    if (lastOpenedPage != null) {
        userPratilipi.setLastOpenedPage(lastOpenedPage);
        userPratilipi.setLastOpenedDate(new Date());
    }
    if (addedToLibrary != null) {
        userPratilipi.setAddedToLib(addedToLibrary);
        userPratilipi.setAddedToLibDate(new Date());
    }
    userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
    return createUserPratilipiData(userPratilipi);
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12