Search in sources :

Example 6 with PratilipiContentDoc

use of com.pratilipi.data.type.PratilipiContentDoc in project pratilipi by Pratilipi.

the class PratilipiDocUtil method getContent.

@Deprecated
public static Object getContent(Long pratilipiId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, 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);
    if (pcDoc == null)
        return null;
    else if (chapterNo == null)
        return _processContent(pratilipi, pcDoc);
    Chapter chapter = pcDoc.getChapter(chapterNo);
    if (chapter == null)
        return null;
    else if (pageNo == null)
        return _processContent(pratilipi, chapter);
    PratilipiContentDoc.Page page = chapter.getPage(pageNo);
    if (page == null)
        return null;
    else
        return _processContent(pratilipi, chapter.getPage(pageNo));
}
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 7 with PratilipiContentDoc

use of com.pratilipi.data.type.PratilipiContentDoc in project pratilipi by Pratilipi.

the class PratilipiDocUtil method addContentChapter.

public static JsonArray addContentChapter(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)
        pcDoc = docAccessor.newPratilipiContentDoc();
    pcDoc.addChapter(chapterNo, null);
    docAccessor.save(pratilipiId, pcDoc);
    return 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 8 with PratilipiContentDoc

use of com.pratilipi.data.type.PratilipiContentDoc 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 9 with PratilipiContentDoc

use of com.pratilipi.data.type.PratilipiContentDoc 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 10 with PratilipiContentDoc

use of com.pratilipi.data.type.PratilipiContentDoc 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)

Aggregations

PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)13 DataAccessor (com.pratilipi.data.DataAccessor)12 DocAccessor (com.pratilipi.data.DocAccessor)12 Pratilipi (com.pratilipi.data.type.Pratilipi)11 UserPratilipi (com.pratilipi.data.type.UserPratilipi)9 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)7 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)7 PratilipiData (com.pratilipi.data.client.PratilipiData)4 Get (com.pratilipi.api.annotation.Get)3 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 HashMap (java.util.HashMap)3 JsonObject (com.google.gson.JsonObject)2 PratilipiFilter (com.pratilipi.common.util.PratilipiFilter)2 LinkedList (java.util.LinkedList)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 PratilipiContentIndexApi (com.pratilipi.api.impl.pratilipi.PratilipiContentIndexApi)1 PratilipiContentV1Api (com.pratilipi.api.impl.pratilipi.PratilipiContentV1Api)1 PratilipiContentV2Api (com.pratilipi.api.impl.pratilipi.PratilipiContentV2Api)1