Search in sources :

Example 31 with Post

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

the class PratilipiV1Api method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    Gson gson = new Gson();
    // Creating PratilipiData object.
    PratilipiData pratilipiData = gson.fromJson(gson.toJson(request), PratilipiData.class);
    // If not set already, setting AuthorId for new content.
    if (pratilipiData.getId() == null && !pratilipiData.hasAuthorId()) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        Author author = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
        pratilipiData.setAuthorId(author.getId());
    }
    // Saving PratilipiData object.
    pratilipiData = PratilipiDataUtil.savePratilipiData(pratilipiData);
    // Creating PratilipiProcess task to process the data.
    Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", pratilipiData.getId().toString()).addParam("processData", "true");
    TaskQueueFactory.getPratilipiTaskQueue().add(task);
    // If PratilipiState has changed, creating AuthorProcess task to update Author stats.
    if (request.hasState && pratilipiData.getAuthorId() != null) {
        Task authorTask = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", pratilipiData.getAuthorId().toString()).addParam("updateStats", "true");
        TaskQueueFactory.getAuthorTaskQueue().add(authorTask);
    }
    return new Response(pratilipiData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Task(com.pratilipi.taskqueue.Task) PratilipiData(com.pratilipi.data.client.PratilipiData) DataAccessor(com.pratilipi.data.DataAccessor) Gson(com.google.gson.Gson) Author(com.pratilipi.data.type.Author) Post(com.pratilipi.api.annotation.Post)

Example 32 with Post

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

the class PratilipiContentBatchApi method get.

@Post
public static GenericResponse get(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    PratilipiDocUtil.saveContentPageBatch(request.pratilipiId, request.jsonObject);
    Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", request.pratilipiId.toString()).addParam("processContentDoc", "true");
    TaskQueueFactory.getPratilipiTaskQueue().add(task);
    return new GenericResponse();
}
Also used : Task(com.pratilipi.taskqueue.Task) GenericResponse(com.pratilipi.api.shared.GenericResponse) 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