Search in sources :

Example 1 with PratilipiContentDoc

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

the class PratilipiDocUtil method getContent_v3.

public static Object getContent_v3(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_v3(pratilipi, pcDoc);
    Chapter chapter = pcDoc.getChapter(chapterNo);
    if (chapter == null)
        return null;
    else if (pageNo == null)
        return _processContent_v3(pratilipi, chapter);
    PratilipiContentDoc.Page page = chapter.getPage(pageNo);
    if (page == null)
        return null;
    else
        return _processContent_v3(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 2 with PratilipiContentDoc

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

the class PratilipiDocUtil method updatePratilipiContent.

public static void updatePratilipiContent(Long pratilipiId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = DataAccessorFactory.getDocAccessor().newPratilipiContentDoc();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!pratilipi.isOldContent()) {
        return;
    } else if (pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
        BlobEntry blobEntry = blobAccessor.getBlob("pratilipi-content/pratilipi/" + pratilipiId);
        if (blobEntry == null)
            return;
        String contentHtml = new String(blobEntry.getData(), Charset.forName("UTF-8"));
        List<Object[]> pageletList = _createPageletList(pratilipi, Jsoup.parse(contentHtml).body());
        if (pageletList.size() > 0) {
            PratilipiContentDoc.Chapter chapter = null;
            if (pageletList.get(0)[0] != PratilipiContentDoc.PageletType.HEAD)
                chapter = pcDoc.addChapter(pratilipi.getTitle() == null ? pratilipi.getTitleEn() : pratilipi.getTitle());
            for (Object[] pagelet : pageletList) {
                if (pagelet[0] == PratilipiContentDoc.PageletType.HEAD) {
                    chapter = pcDoc.addChapter((String) pagelet[1]);
                } else {
                    PratilipiContentDoc.Page page = chapter.getPage(1);
                    if (page == null)
                        page = chapter.addPage();
                    page.addPagelet((PratilipiContentDoc.PageletType) pagelet[0], pagelet[1], (PratilipiContentDoc.AlignmentType) pagelet[2]);
                }
            }
        }
    } else if (pratilipi.getContentType() == PratilipiContentType.IMAGE) {
        for (int i = 1; i <= pratilipi.getPageCount(); i++) {
            BlobEntry blobEntry = blobAccessor.getBlob("pratilipi/" + pratilipiId + "/images/" + i);
            if (pratilipi.getId() == 5639838220943360L && i <= 5)
                // Skipping first 5 pages as per Shally's request
                continue;
            else if (pratilipi.getId() == 5749258686824448L && i <= 4)
                // Skipping first 4 pages as per Shally's request
                continue;
            else if (pratilipi.getId() == 5486454792781824L && i <= 1)
                // Skipping first page as per Shally's request
                continue;
            else if (blobEntry == null && pratilipi.getId() == 5768181499035648L)
                // Skipping missing pages as per Dileepan's request
                continue;
            JsonObject imgData = new JsonObject();
            imgData.addProperty("name", i + "");
            imgData.addProperty("height", ImageUtil.getHeight(blobEntry));
            imgData.addProperty("width", ImageUtil.getWidth(blobEntry));
            pcDoc.addChapter(null).addPage().addPagelet(PratilipiContentDoc.PageletType.IMAGE, imgData);
        }
    } else {
        throw new UnexpectedServerException("ContentType " + pratilipi.getContentType() + " is not supported !");
    }
    docAccessor.save(pratilipiId, pcDoc);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) BlobEntry(com.pratilipi.data.type.BlobEntry) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) JsonObject(com.google.gson.JsonObject) Page(com.pratilipi.data.type.Page) AlignmentType(com.pratilipi.data.type.PratilipiContentDoc.AlignmentType) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) PageletType(com.pratilipi.data.type.PratilipiContentDoc.PageletType) BlobAccessor(com.pratilipi.data.BlobAccessor) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JsonObject(com.google.gson.JsonObject) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 3 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 4 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 5 with PratilipiContentDoc

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

the class PratilipiListV1Api method get.

@Get
public Response get(GetRequest request) throws InsufficientAccessException, UnexpectedServerException {
    PratilipiFilter pratilipiFilter = new PratilipiFilter();
    pratilipiFilter.setAuthorId(request.authorId);
    pratilipiFilter.setLanguage(request.language);
    pratilipiFilter.setType(request.type);
    pratilipiFilter.setListName(request.listName);
    pratilipiFilter.setState(request.state);
    pratilipiFilter.setOrderByLastUpdate(request.orderByLastUpdated);
    DataListCursorTuple<PratilipiData> pratilipiListCursorTuple = PratilipiDataUtil.getPratilipiDataList(request.searchQuery, request.eventId, pratilipiFilter, request.cursor, request.offset, request.resultCount == null ? 20 : request.resultCount);
    if (UxModeFilter.isAndroidApp()) {
        DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
        for (PratilipiData pratilipiData : pratilipiListCursorTuple.getDataList()) {
            PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiData.getId());
            if (pcDoc == null)
                continue;
            pratilipiData.setIndex(pcDoc.getIndex());
        }
    }
    Response response = new Response(pratilipiListCursorTuple.getDataList(), pratilipiListCursorTuple.getCursor(), pratilipiListCursorTuple.getNumberFound());
    if (UxModeFilter.isAndroidApp() && request.eventId != null && request.cursor == null) {
        Event event = DataAccessorFactory.getDataAccessor().getEvent(request.eventId);
        response.setBannerUrl(EventDataUtil.createEventBannerUrl(event));
        response.setDescription(event.getDescription());
    }
    return response;
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) PratilipiData(com.pratilipi.data.client.PratilipiData) DocAccessor(com.pratilipi.data.DocAccessor) Event(com.pratilipi.data.type.Event) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc) Get(com.pratilipi.api.annotation.Get)

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