use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class CommentApi method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
CommentData commentData = new CommentData(request.commentId);
commentData.setUserId(AccessTokenFilter.getAccessToken().getUserId());
commentData.setParentType(request.parentType);
commentData.setParentId(request.parentId);
if (request.hasContent)
commentData.setContent(request.content);
if (request.hasState)
commentData.setState(request.state);
else
commentData.setState(CommentState.ACTIVE);
commentData = CommentDataUtil.saveCommentData(commentData);
if (commentData.getReferenceType() == ReferenceType.PRATILIPI) {
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", commentData.getReferenceId()).addParam("updateReviewsDoc", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
}
return new Response(commentData);
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class PratilipiBackupApi method post.
@Post
public GenericResponse post(PostRequest request) throws UnexpectedServerException {
Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(request.pratilipiId);
Date dateTime = new Date(pratilipi.getLastUpdated().getTime() + TimeUnit.HOURS.toMillis(1L) - 1);
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd-HH'.00'-z");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
String srcBucket = "static.pratilipi.com";
String dstBucket = "backup.pratilipi.com";
String srcPrefix = "pratilipi/" + request.pratilipiId + "/";
String dstPrefix = srcBucket + "/pratilipi-" + dateTimeFormat.format(dateTime) + "/" + request.pratilipiId + "/";
try {
ListResult result = gcsService.list(srcBucket, new ListOptions.Builder().setPrefix(srcPrefix).build());
while (result.hasNext()) {
String srcName = result.next().getName();
String dstName = dstPrefix + srcName.substring(srcPrefix.length());
gcsService.copy(new GcsFilename(srcBucket, srcName), new GcsFilename(dstBucket, dstName));
}
} catch (IOException e) {
logger.log(Level.SEVERE, "", e);
throw new UnexpectedServerException();
}
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class AuthorCoverApi method post.
@Post
public GenericResponse post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().newBlob(request.getName());
blobEntry.setData(request.getData());
blobEntry.setMimeType(request.getMimeType());
blobEntry.setMetaName(request.getName());
String coverImageUrl = AuthorDataUtil.saveAuthorCoverImage(request.authorId, blobEntry);
return new Response(coverImageUrl);
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class BatchProcessApi method post.
@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
if (request.type == BatchProcessType.NOTIFACTION_BY_AUTHOR_FILTER) {
Page page = null;
JsonObject errorMessages = new JsonObject();
if (request.message == null || request.message.trim().isEmpty())
errorMessages.addProperty("message", "message is required !");
if (request.sourceUri == null || request.sourceUri.trim().isEmpty())
errorMessages.addProperty("sourceUri", "sourceUri is required !");
else if ((page = dataAccessor.getPage(request.sourceUri)) == null)
errorMessages.addProperty("sourceUri", "Invalid url !");
else if (page.getType() != PageType.PRATILIPI)
errorMessages.addProperty("sourceUri", "Must be a content url !");
if (errorMessages.size() != 0)
throw new InvalidArgumentException(errorMessages);
AuthorFilter authorFilter = new AuthorFilter();
authorFilter.setLanguage(request.language);
authorFilter.setState(AuthorState.ACTIVE);
// Creating Init Doc
JsonObject initDoc = new JsonObject();
initDoc.add("authorFilter", new Gson().toJsonTree(authorFilter));
// Creating Exec Doc
JsonObject execDoc = new JsonObject();
execDoc.addProperty("message", request.message);
execDoc.addProperty("sourceId", page.getPrimaryContentId().toString());
execDoc.addProperty("type", NotificationType.PRATILIPI.toString());
BatchProcessDataUtil.createBatchProcess(request.type, initDoc.toString(), execDoc.toString(), request.language);
}
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Post in project pratilipi by Pratilipi.
the class UserVerificationApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
UserDataUtil.verifyUserEmail(request.getEmail(), request.getVerificationToken());
UserData userData = UserDataUtil.loginUser(request.getEmail(), request.getVerificationToken());
return new UserV1Api.Response(userData, UserVerificationApi.class);
}
Aggregations