Search in sources :

Example 6 with GenericResponse

use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.

the class I18nApi method post.

@Post
public static GenericResponse post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
    if (!UserAccessUtil.hasUserAccess(AccessTokenFilter.getAccessToken().getUserId(), request.language, AccessType.I18N_UPDATE))
        throw new InsufficientAccessException();
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<I18n> i18nList = new ArrayList<>();
    for (Entry<String, String> entry : request.keyValues.entrySet()) {
        I18n i18n = dataAccessor.getI18n(entry.getKey());
        if (i18n == null)
            i18n = dataAccessor.newI18n(entry.getKey());
        // Resetting the group if its already set
        i18n.setGroup(request.group);
        i18n.setI18nString(request.language, entry.getValue());
        i18nList.add(i18n);
    }
    i18nList = dataAccessor.createOrUpdateI18nList(i18nList);
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) I18n(com.pratilipi.data.type.I18n) Post(com.pratilipi.api.annotation.Post)

Example 7 with GenericResponse

use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.

the class AuthorImageApi method post.

@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().newBlob(request.getName());
    blobEntry.setData(request.getData());
    blobEntry.setMimeType(request.getMimeType());
    blobEntry.setMetaName(request.getName());
    String profileImageUrl = AuthorDataUtil.saveAuthorImage(request.authorId, blobEntry);
    return new Response(profileImageUrl);
}
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 8 with GenericResponse

use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.

the class PratilipiContentV1Api method post.

@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    PratilipiDocUtil.saveContentPage(request.pratilipiId, request.chapterNo, request.chapterTitle, request.pageNo == null ? 1 : request.pageNo, request.content);
    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)

Example 9 with GenericResponse

use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.

the class EventBannerApi 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());
    EventDataUtil.saveEventBanner(request.eventId, blobEntry);
    return new GenericResponse();
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) BlobEntry(com.pratilipi.data.type.BlobEntry) Post(com.pratilipi.api.annotation.Post)

Example 10 with GenericResponse

use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.

the class PratilipiProcessApi method postPratilipiProcess.

@Post
public GenericResponse postPratilipiProcess(PostPratilipiProcessRequest request) throws InvalidArgumentException, UnexpectedServerException, InsufficientAccessException {
    List<Long> pratilipiIdList = request.getPratilipiIdList() != null ? request.getPratilipiIdList() : new ArrayList<Long>(1);
    if (request.getPratilipiId() != null)
        pratilipiIdList.add(request.getPratilipiId());
    if (pratilipiIdList.size() == 0) {
        logger.log(Level.SEVERE, "0 pratilipiId found.");
        throw new InvalidArgumentException("'pratilipiId' or 'pratilipiIdList' must be set/non-empty.");
    }
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    if (request.validateData()) {
        for (Long pratilipiId : pratilipiIdList) {
            Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
            Author author = dataAccessor.getAuthor(pratilipi.getAuthorId());
            Page pratilipiPage = dataAccessor.getPage(PageType.PRATILIPI, pratilipiId);
            if (pratilipi.getLanguage() == null)
                throw new InvalidArgumentException("Language is null.");
            if (pratilipi.getAuthorId() != null && author == null)
                throw new InvalidArgumentException("Invalid Author id.");
            if (pratilipi.getState() == PratilipiState.PUBLISHED && author != null && author.getState() == AuthorState.DELETED)
                throw new InvalidArgumentException("Linked Author entity is DELETED.");
            if (pratilipi.getState() == PratilipiState.DELETED && pratilipiPage != null)
                throw new InvalidArgumentException("DELETED Pratilipi has non-deleted Page entity.");
            if (pratilipi.getState() != PratilipiState.DELETED && pratilipiPage == null)
                throw new InvalidArgumentException("Page entity is missing for the Pratilipi.");
            if (pratilipi.getState() == PratilipiState.DELETED)
                continue;
            if (pratilipi.getTitle() == null && pratilipi.getTitleEn() == null)
                throw new InvalidArgumentException("Title is missing for the Pratilipi.");
            if ((pratilipi.getTitle() != null && pratilipi.getTitle().trim().isEmpty()) || (pratilipi.getTitleEn() != null && pratilipi.getTitleEn().trim().isEmpty()))
                throw new InvalidArgumentException("Title has empty string.");
        }
    }
    if (request.processData()) {
        PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiIdList);
        PratilipiDataUtil.updateFacebookScrape(pratilipiIdList);
    }
    if (request.processContent()) {
        for (Long pratilipiId : pratilipiIdList) {
            PratilipiDocUtil.updatePratilipiContent(pratilipiId);
            PratilipiDataUtil.updatePratilipiIndex(pratilipiId);
            boolean changed = PratilipiDocUtil.updateMeta(pratilipiId);
            if (changed)
                PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiId, null);
        }
    }
    if (request.processContentDoc()) {
        for (Long pratilipiId : pratilipiIdList) {
            boolean changed = PratilipiDocUtil.updateMeta(pratilipiId);
            if (changed)
                PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiId, null);
        }
    }
    if (request.updateReviewsDoc()) {
        for (long pratilipiId : pratilipiIdList) PratilipiDocUtil.updatePratilipiReviews(pratilipiId);
    }
    if (request.updateStats()) {
        List<Task> taskList = new ArrayList<>(pratilipiIdList.size());
        List<Pratilipi> pratilipiList = DataAccessorFactory.getDataAccessor().getPratilipiList(pratilipiIdList);
        for (int i = 0; i < pratilipiIdList.size(); i++) {
            Pratilipi pratilipi = pratilipiList.get(i);
            if (pratilipi == null || pratilipi.getState() != PratilipiState.PUBLISHED) {
                pratilipiList.remove(i);
                pratilipiIdList.remove(i);
                i--;
                continue;
            }
            PratilipiDataUtil.updatePratilipiStats(pratilipi.getId());
            if (pratilipi.getAuthorId() != null) {
                // Creating tasks to update author entities
                Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", pratilipi.getAuthorId().toString()).addParam("updateStats", "true");
                taskList.add(task);
            }
        }
        PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiIdList);
        TaskQueueFactory.getAuthorOfflineTaskQueue().addAll(taskList);
    }
    if (request.updateUserPratilipiStats()) {
        for (long pratilipiId : pratilipiIdList) PratilipiDataUtil.updateUserPratilipiStats(pratilipiId);
    }
    return new GenericResponse();
}
Also used : Task(com.pratilipi.taskqueue.Task) GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Page(com.pratilipi.data.type.Page) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) Author(com.pratilipi.data.type.Author) Pratilipi(com.pratilipi.data.type.Pratilipi) Post(com.pratilipi.api.annotation.Post)

Aggregations

GenericResponse (com.pratilipi.api.shared.GenericResponse)29 DataAccessor (com.pratilipi.data.DataAccessor)17 Post (com.pratilipi.api.annotation.Post)15 Get (com.pratilipi.api.annotation.Get)12 Task (com.pratilipi.taskqueue.Task)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)8 Gson (com.google.gson.Gson)7 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)6 BlobEntry (com.pratilipi.data.type.BlobEntry)6 AppProperty (com.pratilipi.data.type.AppProperty)5 Pratilipi (com.pratilipi.data.type.Pratilipi)5 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)4 Author (com.pratilipi.data.type.Author)4 SimpleDateFormat (java.text.SimpleDateFormat)4 GsonBuilder (com.google.gson.GsonBuilder)3 JsonObject (com.google.gson.JsonObject)3 GenericFileDownloadResponse (com.pratilipi.api.shared.GenericFileDownloadResponse)3 AuthorFilter (com.pratilipi.common.util.AuthorFilter)3 BlobAccessor (com.pratilipi.data.BlobAccessor)3