Search in sources :

Example 46 with InsufficientAccessException

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

the class AuthorDataUtil method saveAuthorData.

public static AuthorData saveAuthorData(AuthorData authorData) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    _validateAuthorDataForSave(authorData);
    boolean isNew = authorData.getId() == null;
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = isNew ? dataAccessor.newAuthor() : dataAccessor.getAuthor(authorData.getId());
    if (isNew && !hasAccessToAddAuthorData(authorData))
        throw new InsufficientAccessException();
    if (!isNew && !hasAccessToUpdateAuthorData(author, authorData))
        throw new InsufficientAccessException();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.AUTHOR_ADD : AccessType.AUTHOR_UPDATE, author);
    if (authorData.hasFirstName())
        author.setFirstName(authorData.getFirstName());
    if (authorData.hasLastName())
        author.setLastName(authorData.getLastName());
    if (authorData.hasPenName())
        author.setPenName(authorData.getPenName());
    if (authorData.hasFirstNameEn())
        author.setFirstNameEn(authorData.getFirstNameEn());
    if (authorData.hasLastNameEn())
        author.setLastNameEn(authorData.getLastNameEn());
    if (authorData.hasPenNameEn())
        author.setPenNameEn(authorData.getPenNameEn());
    if (authorData.hasGender())
        author.setGender(authorData.getGender());
    if (authorData.hasDateOfBirth())
        author.setDateOfBirth(authorData.getDateOfBirth());
    if (authorData.hasLanguage())
        author.setLanguage(authorData.getLanguage());
    if (authorData.hasLocation())
        author.setLocation(authorData.getLocation());
    if (authorData.hasSummary())
        author.setSummary(authorData.getSummary());
    if (authorData.hasState())
        author.setState(authorData.getState());
    if (isNew)
        author.setRegistrationDate(new Date());
    author.setLastUpdated(new Date());
    author = dataAccessor.createOrUpdateAuthor(author, auditLog);
    if (isNew)
        createOrUpdateAuthorPageUrl(author.getId());
    return createAuthorData(author);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 47 with InsufficientAccessException

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

the class TagsApi method addTags.

@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
    // Security Hack
    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();
    }
    Gson gson = new Gson();
    // Creating TagData object.
    TagData tagData = gson.fromJson(gson.toJson(request), TagData.class);
    tagData = TagDataUtil.saveTag(tagData);
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) AccessToken(com.pratilipi.data.type.AccessToken) Gson(com.google.gson.Gson) TagData(com.pratilipi.data.client.TagData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Post(com.pratilipi.api.annotation.Post)

Example 48 with InsufficientAccessException

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

the class UserV2Api method get.

@Get
public Response get(GetRequest request) throws InsufficientAccessException {
    if (request.userId == null || request.userId.equals(UserDataUtil.getCurrentUser().getId()))
        return new Response(UserDataUtil.getCurrentUser(), UserV2Api.class);
    if (!UserAccessUtil.hasUserAccess(UserDataUtil.getCurrentUser().getId(), UxModeFilter.getWebsite().getFilterLanguage(), AccessType.AUTHOR_ADD))
        throw new InsufficientAccessException();
    UserData userData = UserDataUtil.createUserData(DataAccessorFactory.getDataAccessor().getUser(request.userId), null);
    userData.setAuthor(new AuthorData());
    return new Response(userData, UserV2Api.class);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Get(com.pratilipi.api.annotation.Get)

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