Search in sources :

Example 26 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserAuthorFollowV1Api method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    Long userId = AccessTokenFilter.getAccessToken().getUserId();
    UserAuthorData userAuthorData = UserAuthorDataUtil.saveUserAuthorFollow(userId, request.authorId, request.following ? UserFollowState.FOLLOWING : UserFollowState.UNFOLLOWED);
    Task task_1 = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", request.authorId.toString()).addParam("updateUserAuthorStats", "true");
    Task task_2 = TaskQueueFactory.newTask().setUrl("/user/process").addParam("userId", userId.toString()).addParam("updateFollowsDoc", "true").addParam("updateUserAuthorStats", "true");
    TaskQueueFactory.getUserAuthorTaskQueue().addAll(task_1, task_2);
    return new Response(userAuthorData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Task(com.pratilipi.taskqueue.Task) UserAuthorData(com.pratilipi.data.client.UserAuthorData) Post(com.pratilipi.api.annotation.Post)

Example 27 with Post

use of com.pratilipi.api.annotation.Post 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 28 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class VoteApi method post.

@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    VoteData voteData = VoteDataUtil.saveVoteData(AccessTokenFilter.getAccessToken().getUserId(), request.parentType, request.parentId, request.type);
    if (voteData.getReferenceType() == ReferenceType.PRATILIPI) {
        Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", voteData.getReferenceId()).addParam("updateReviewsDoc", "true");
        TaskQueueFactory.getPratilipiTaskQueue().add(task);
    }
    return new GenericResponse();
}
Also used : Task(com.pratilipi.taskqueue.Task) GenericResponse(com.pratilipi.api.shared.GenericResponse) VoteData(com.pratilipi.data.client.VoteData) Post(com.pratilipi.api.annotation.Post)

Example 29 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class UserV1Api method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    UserData userData = request.userId == null ? new UserData(AccessTokenFilter.getAccessToken().getUserId()) : new UserData(request.userId.equals(0L) ? null : request.userId);
    if (request.hasName) {
        String firstName = request.name.trim();
        String lastName = null;
        if (firstName.lastIndexOf(' ') != -1) {
            lastName = firstName.substring(firstName.lastIndexOf(' ') + 1);
            firstName = firstName.substring(0, firstName.lastIndexOf(' '));
        }
        userData.setFirstName(firstName);
        userData.setLastName(lastName);
    }
    if (request.hasEmail)
        userData.setEmail(request.email);
    if (request.hasPhone)
        userData.setPhone(request.phone);
    if (request.hasLanguage)
        userData.setLanguage(request.language);
    // Save UserData
    userData = UserDataUtil.saveUserData(userData);
    // New User (added by AEE)
    if (request.userId != null && request.userId.equals(0L)) {
        // Create Author profile for the User
        Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
        userData.setAuthor(new AuthorData(authorId));
        userData.setProfilePageUrl("/author/" + authorId);
        // Send welcome mail to the user
        Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", request.language == null ? UxModeFilter.getDisplayLanguage().toString() : request.language.toString()).addParam("sendWelcomeMail", "true");
        TaskQueueFactory.getUserTaskQueue().add(task);
    }
    // Send verification mail if user updates his email and state is REGISTERED
    if (request.hasEmail && userData.getState() == UserState.REGISTERED) {
        Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", (userData.getLanguage() == null ? Language.ENGLISH : userData.getLanguage()).toString()).addParam("sendEmailVerificationMail", "true");
        TaskQueueFactory.getUserTaskQueue().add(task);
    }
    // Process Author data
    Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", userData.getAuthor().getId().toString()).addParam("processData", "true");
    TaskQueueFactory.getAuthorTaskQueue().add(task);
    return new Response(userData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Task(com.pratilipi.taskqueue.Task) UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData) Post(com.pratilipi.api.annotation.Post)

Example 30 with Post

use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.

the class PratilipiTagsUpdateApi method updatePratilipiTags.

@Post
public PostResponse updatePratilipiTags(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
    List<Long> tagIds = request.getTagIds();
    List<String> suggestedTags = request.getSuggestedTags();
    PratilipiType pratilipiType = request.getPratilipiType();
    Long pratilipiId = request.getPratilipiId();
    Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "TagIds : " + tagIds);
    Logger.getLogger(PratilipiTagsUpdateApi.class.getSimpleName()).log(Level.INFO, "SuggestedTags : " + suggestedTags);
    if (tagIds == null && suggestedTags == null)
        throw new UnexpectedServerException("Both tagIds and suggestedTags cannot be null");
    boolean isUpdated = PratilipiDataUtil.updatePratilipiTags(pratilipiId, pratilipiType, tagIds, suggestedTags);
    return new PostResponse(isUpdated);
}
Also used : UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) PratilipiType(com.pratilipi.common.type.PratilipiType) Post(com.pratilipi.api.annotation.Post)

Aggregations

Post (com.pratilipi.api.annotation.Post)32 GenericResponse (com.pratilipi.api.shared.GenericResponse)22 Task (com.pratilipi.taskqueue.Task)15 DataAccessor (com.pratilipi.data.DataAccessor)6 UserData (com.pratilipi.data.client.UserData)6 Gson (com.google.gson.Gson)5 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)5 BlobEntry (com.pratilipi.data.type.BlobEntry)5 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)3 Author (com.pratilipi.data.type.Author)3 Page (com.pratilipi.data.type.Page)3 Pratilipi (com.pratilipi.data.type.Pratilipi)3 Date (java.util.Date)3 JsonObject (com.google.gson.JsonObject)2 GenericFileDownloadResponse (com.pratilipi.api.shared.GenericFileDownloadResponse)2 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)2 AuthorData (com.pratilipi.data.client.AuthorData)2 UserAuthorData (com.pratilipi.data.client.UserAuthorData)2 AccessToken (com.pratilipi.data.type.AccessToken)2 ArrayList (java.util.ArrayList)2