Search in sources :

Example 21 with DocAccessor

use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.

the class PratilipiDocUtil method saveContentPage.

public static void saveContentPage(Long pratilipiId, Integer chapterNo, String chapterTitle, Integer pageNo, String html) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    // Doc
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        pcDoc = docAccessor.newPratilipiContentDoc();
    // Chapter
    Chapter chapter = pcDoc.getChapter(chapterNo);
    if (chapter == null)
        chapter = pcDoc.addChapter(chapterNo, chapterTitle);
    else
        chapter.setTitle(chapterTitle);
    // Page
    PratilipiContentDoc.Page page = chapter.getPage(pageNo);
    if (page == null)
        page = chapter.addPage(pageNo);
    _setPage(pratilipiId, page, html);
    // Save
    docAccessor.save(pratilipiId, pcDoc);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 22 with DocAccessor

use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.

the class PratilipiDocUtil method deleteContentChapter.

public static JsonArray deleteContentChapter(Long pratilipiId, Integer chapterNo) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        return new JsonArray();
    pcDoc.deleteChapter(chapterNo);
    docAccessor.save(pratilipiId, pcDoc);
    return pcDoc.getIndex();
}
Also used : JsonArray(com.google.gson.JsonArray) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 23 with DocAccessor

use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.

the class PratilipiDocUtil method saveContentPageBatch.

public static void saveContentPageBatch(Long pratilipiId, JsonObject chapters) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    // Doc
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        pcDoc = docAccessor.newPratilipiContentDoc();
    for (Map.Entry<String, JsonElement> chapterEntry : chapters.entrySet()) {
        Integer chapterNo = Integer.parseInt(chapterEntry.getKey());
        // chapterTitle
        String chapterTitle = null;
        if (chapterEntry.getValue().getAsJsonObject().has("chapterTitle"))
            chapterTitle = chapterEntry.getValue().getAsJsonObject().get("chapterTitle").getAsString();
        // content
        String content = null;
        if (chapterEntry.getValue().getAsJsonObject().has("content"))
            content = chapterEntry.getValue().getAsJsonObject().get("content").getAsString();
        // pageNo
        if (!chapterEntry.getValue().getAsJsonObject().has("pageNo"))
            throw new InvalidArgumentException(GenericRequest.ERR_PRATILIPI_PAGE_NO_REQUIRED);
        Integer pageNo = chapterEntry.getValue().getAsJsonObject().get("pageNo").getAsInt();
        // Chapter
        Chapter chapter = pcDoc.getChapter(chapterNo);
        if (chapter == null)
            chapter = pcDoc.addChapter(chapterNo, chapterTitle);
        else if (chapterTitle != null)
            chapter.setTitle(chapterTitle);
        // Page
        PratilipiContentDoc.Page page = chapter.getPage(pageNo);
        if (page == null)
            page = chapter.addPage(pageNo);
        _setPage(pratilipiId, page, content);
    }
    // Save
    docAccessor.save(pratilipiId, pcDoc);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) JsonElement(com.google.gson.JsonElement) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with DocAccessor

use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.

the class PratilipiDocUtil method getContentIndex.

// Content doc
public static JsonArray getContentIndex(Long pratilipiId) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    return pcDoc == null ? null : pcDoc.getIndex();
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 25 with DocAccessor

use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.

the class PratilipiDocUtil method updatePratilipiGoogleAnalyticsPageViews.

public static void updatePratilipiGoogleAnalyticsPageViews(Long pratilipiId, int year, int month, int day, int pageViews, int readPageViews) throws UnexpectedServerException {
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiGoogleAnalyticsDoc gaDoc = docAccessor.getPratilipiGoogleAnalyticsDoc(pratilipiId);
    gaDoc.setPageViews(year, month, day, pageViews);
    gaDoc.setReadPageViews(year, month, day, readPageViews);
    docAccessor.save(pratilipiId, gaDoc);
}
Also used : DocAccessor(com.pratilipi.data.DocAccessor) PratilipiGoogleAnalyticsDoc(com.pratilipi.data.type.PratilipiGoogleAnalyticsDoc)

Aggregations

DocAccessor (com.pratilipi.data.DocAccessor)28 DataAccessor (com.pratilipi.data.DataAccessor)22 Pratilipi (com.pratilipi.data.type.Pratilipi)12 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)12 UserPratilipi (com.pratilipi.data.type.UserPratilipi)12 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)7 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)6 ArrayList (java.util.ArrayList)6 PratilipiReviewsDoc (com.pratilipi.data.type.PratilipiReviewsDoc)5 BatchProcessDoc (com.pratilipi.data.type.BatchProcessDoc)4 UserPratilipiDoc (com.pratilipi.data.type.UserPratilipiDoc)4 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)3 Get (com.pratilipi.api.annotation.Get)3 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)3 PratilipiData (com.pratilipi.data.client.PratilipiData)3 AuditLog (com.pratilipi.data.type.AuditLog)3 Author (com.pratilipi.data.type.Author)3 Page (com.pratilipi.data.type.Page)3