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);
}
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();
}
Aggregations