Search in sources :

Example 16 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class PratilipiDocUtil method getContentImage.

public static BlobEntry getContentImage(long pratilipiId, String name, Integer width) throws InsufficientAccessException, UnexpectedServerException {
    Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/" + pratilipiId + "/images/" + name);
    if (width != null)
        blobEntry = ImageUtil.resize(blobEntry, width);
    return blobEntry;
}
Also used : BlobEntry(com.pratilipi.data.type.BlobEntry) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Example 17 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method saveUserAuthorFollow.

public static UserAuthorData saveUserAuthorFollow(Long userId, Long authorId, UserFollowState followState) throws InvalidArgumentException, InsufficientAccessException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserAuthor userAuthor = dataAccessor.getUserAuthor(userId, authorId);
    if (userAuthor == null) {
        userAuthor = dataAccessor.newUserAuthor();
        userAuthor.setUserId(userId);
        userAuthor.setAuthorId(authorId);
    }
    if (!hasAccessToUpdateUserAuthorData(userAuthor, AccessType.USER_AUTHOR_FOLLOWING))
        throw new InsufficientAccessException();
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    AuditLog auditLog = dataAccessor.newAuditLog(accessToken, AccessType.USER_AUTHOR_FOLLOWING, userAuthor);
    userAuthor.setFollowState(followState);
    userAuthor.setFollowDate(new Date());
    userAuthor = dataAccessor.createOrUpdateUserAuthor(userAuthor, auditLog);
    return createUserAuthorData(userAuthor);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) AccessToken(com.pratilipi.data.type.AccessToken) UserAuthor(com.pratilipi.data.type.UserAuthor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 18 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class UserDataUtil method _loginFederatedUser.

private static UserData _loginFederatedUser(UserData apiUserData, User user, UserSignUpSource signUpSource) throws InsufficientAccessException {
    // Do nothing if a user is already logged in
    if (!AccessTokenFilter.getAccessToken().getUserId().equals(0L))
        return getCurrentUser();
    // Note: Users having Facebook or Google Id can never be in GUEST or REFERRAL state.
    // Note: No action required for REGISTERED or ACTIVE users.
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    boolean isNew = false;
    if (user == null || user.getState() == UserState.DELETED) {
        if (apiUserData.getEmail() != null)
            user = dataAccessor.getUserByEmail(apiUserData.getEmail());
        AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), null, null);
        if (user == null || user.getState() == UserState.DELETED) {
            user = dataAccessor.newUser();
            auditLog.setAccessType(AccessType.USER_ADD);
            auditLog.setEventDataOld(user);
            user.setEmail(apiUserData.getEmail());
            // Counting on Facebook / Google for e-mail/user verification
            user.setState(UserState.ACTIVE);
            user.setSignUpDate(new Date());
            user.setSignUpSource(signUpSource);
            isNew = true;
        } else if (user.getState() == UserState.REFERRAL) {
            auditLog.setAccessType(AccessType.USER_ADD);
            auditLog.setEventDataOld(user);
            // Counting on Facebook / Google for e-mail/user verification
            user.setState(UserState.ACTIVE);
            user.setSignUpDate(new Date());
            user.setSignUpSource(signUpSource);
            isNew = true;
        } else if (user.getState() == UserState.REGISTERED) {
            auditLog.setAccessType(AccessType.USER_UPDATE);
            auditLog.setEventDataOld(user);
            // Counting on Facebook / google for e-mail/user verification
            user.setState(UserState.ACTIVE);
        } else {
            // user.getState() == UserState.ACTIVE || user.getState() == UserState.BLOCKED
            auditLog.setAccessType(AccessType.USER_UPDATE);
            auditLog.setEventDataOld(user);
        }
        if (apiUserData.getFacebookId() != null)
            user.setFacebookId(apiUserData.getFacebookId());
        if (apiUserData.getGoogleId() != null)
            user.setGoogleId(apiUserData.getGoogleId());
        user.setLastUpdated(new Date());
        user = dataAccessor.createOrUpdateUser(user, auditLog);
    }
    if (user.getState() == UserState.BLOCKED)
        throw new InsufficientAccessException(GenericRequest.ERR_ACCOUNT_BLOCKED);
    _loginUser(AccessTokenFilter.getAccessToken(), user);
    UserData userData = createUserData(user);
    if (isNew) {
        userData.setFirstName(apiUserData.getFirstName());
        userData.setLastName(apiUserData.getLastName());
        userData.setGender(apiUserData.getGender());
        userData.setDateOfBirth(apiUserData.getDateOfBirth());
    }
    return userData;
}
Also used : UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 19 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class PratilipiDataUtil method updatePratilipiTags.

public static boolean updatePratilipiTags(long pratilipiId, PratilipiType pratilipiType, List<Long> tagIds, List<String> suggestedTags) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (pratilipi == null)
        return false;
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
    PratilipiData pratilipiData = createPratilipiData(pratilipi);
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    logger.log(Level.INFO, "User Id : " + accessToken.getUserId());
    if (!hasAccessToUpdatePratilipiData(pratilipi, pratilipiData)) {
        throw new InsufficientAccessException();
    }
    if (pratilipiType != null)
        pratilipi.setType(pratilipiType);
    if (tagIds != null)
        pratilipi.setTagIds(tagIds);
    if (suggestedTags != null)
        pratilipi.setSuggestedTags(suggestedTags);
    dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
    return true;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) PratilipiData(com.pratilipi.data.client.PratilipiData) AccessToken(com.pratilipi.data.type.AccessToken) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog)

Example 20 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class DeleteTagsApi method addTags.

@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (accessToken.getUserId() != 5073076857339904L) {
        Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "AccessToken : " + accessToken.getId());
        Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "User Id : " + accessToken.getUserId());
        throw new InsufficientAccessException();
    }
    TagDataUtil.removeTags(request.getIds());
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) AccessToken(com.pratilipi.data.type.AccessToken) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Post(com.pratilipi.api.annotation.Post)

Aggregations

InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)48 DataAccessor (com.pratilipi.data.DataAccessor)37 Date (java.util.Date)21 AuditLog (com.pratilipi.data.type.AuditLog)19 UserPratilipi (com.pratilipi.data.type.UserPratilipi)18 Pratilipi (com.pratilipi.data.type.Pratilipi)14 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)11 BlobAccessor (com.pratilipi.data.BlobAccessor)7 DocAccessor (com.pratilipi.data.DocAccessor)7 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)7 JsonObject (com.google.gson.JsonObject)5 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)5 AccessToken (com.pratilipi.data.type.AccessToken)5 Author (com.pratilipi.data.type.Author)5 Gson (com.google.gson.Gson)4 UserData (com.pratilipi.data.client.UserData)4 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)4 User (com.pratilipi.data.type.User)4 HashMap (java.util.HashMap)4