Search in sources :

Example 21 with Post

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);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Task(com.pratilipi.taskqueue.Task) CommentData(com.pratilipi.data.client.CommentData) Post(com.pratilipi.api.annotation.Post)

Example 22 with Post

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();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) GcsService(com.google.appengine.tools.cloudstorage.GcsService) ListOptions(com.google.appengine.tools.cloudstorage.ListOptions) IOException(java.io.IOException) Date(java.util.Date) ListResult(com.google.appengine.tools.cloudstorage.ListResult) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Pratilipi(com.pratilipi.data.type.Pratilipi) SimpleDateFormat(java.text.SimpleDateFormat) GcsFilename(com.google.appengine.tools.cloudstorage.GcsFilename) Post(com.pratilipi.api.annotation.Post)

Example 23 with Post

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);
}
Also used : GenericFileDownloadResponse(com.pratilipi.api.shared.GenericFileDownloadResponse) GenericResponse(com.pratilipi.api.shared.GenericResponse) BlobEntry(com.pratilipi.data.type.BlobEntry) Post(com.pratilipi.api.annotation.Post)

Example 24 with Post

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();
}
Also used : InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) AuthorFilter(com.pratilipi.common.util.AuthorFilter) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Page(com.pratilipi.data.type.Page) Post(com.pratilipi.api.annotation.Post)

Example 25 with Post

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);
}
Also used : UserData(com.pratilipi.data.client.UserData) 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