Search in sources :

Example 11 with Pratilipi

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

the class DataStoreCleanupUtil method migratePratilipi.

public static void migratePratilipi(Long fromAuthorId, Long toAuthorId) {
    QueryResultIterator<PratilipiEntity> iterator = ObjectifyService.ofy().load().type(PratilipiEntity.class).filter("AUTHOR_ID", fromAuthorId).chunk(100).iterator();
    while (iterator.hasNext()) {
        Pratilipi pratilipi = iterator.next();
        pratilipi.setAuthorId(toAuthorId);
        ObjectifyService.ofy().save().entity(pratilipi).now();
        Task task1 = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", fromAuthorId.toString()).addParam("processData", "true").addParam("updateStats", "true");
        TaskQueueFactory.getAuthorTaskQueue().add(task1);
        Task task2 = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", pratilipi.getId().toString()).addParam("processData", "true").addParam("updateStats", "true");
        TaskQueueFactory.getPratilipiTaskQueue().add(task2);
        System.out.println("Migrating Pratilipi: " + pratilipi.getId());
    }
}
Also used : Task(com.pratilipi.taskqueue.Task) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity) PratilipiEntity(com.pratilipi.data.type.gae.PratilipiEntity) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi)

Example 12 with Pratilipi

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

the class PratilipiDocUtil method deleteContentChapter.

public static PratilipiContentDoc deleteContentChapter(Long pratilipiId, String chapterId, Integer chapterNo) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    // Auth Service will be taking care of it - Move it to gamma and prod asap
    if (_shouldAuth()) {
        if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
            throw new InsufficientAccessException();
    }
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        return docAccessor.newPratilipiContentDoc();
    if (chapterId != null)
        pcDoc.deleteChapter(chapterId);
    else if (chapterNo != null)
        pcDoc.deleteChapter(chapterNo);
    docAccessor.save(pratilipiId, pcDoc);
    return pcDoc;
}
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 13 with Pratilipi

use of com.pratilipi.data.type.Pratilipi 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);
    // Auth Service will be taking care of it - Move it to gamma and prod asap
    if (_shouldAuth()) {
        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 14 with Pratilipi

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

the class PratilipiDocUtil method getContent_v3.

public static Object getContent_v3(Long pratilipiId, String chapterId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    // Auth Service will be taking care of it - Move it to gamma and prod asap
    if (_shouldAuth()) {
        if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
            throw new InsufficientAccessException();
    }
    PratilipiContentDoc pcDoc = _validateChapterIdInContent(pratilipiId);
    if (pcDoc == null)
        return null;
    else if (chapterId == null && chapterNo == null)
        return _processContent_v3(pratilipi, pcDoc);
    Chapter chapter = chapterId != null ? pcDoc.getChapter(chapterId) : 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) 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 15 with Pratilipi

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

the class PratilipiDocUtil method saveContentIndex.

public static PratilipiContentDoc saveContentIndex(Long pratilipiId, List<String> chapterIdOrder) throws InsufficientAccessException, InvalidArgumentException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    // Auth Service will be taking care of it - Move it to gamma and prod asap
    if (_shouldAuth()) {
        if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
            throw new InsufficientAccessException();
    }
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    // Doc
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        throw new InvalidArgumentException("Invalid PratilipiId!");
    for (String chapterId : chapterIdOrder) if (pcDoc.getChapter(chapterId) == null)
        throw new InvalidArgumentException("Invalid chapterId: " + chapterId);
    PratilipiContentDoc newPcDoc = docAccessor.newPratilipiContentDoc();
    int chapterNo = 1;
    for (String chapterId : chapterIdOrder) {
        Chapter chapter = pcDoc.getChapter(chapterId);
        newPcDoc.setChapter(chapterNo++, chapter);
    }
    // Save
    docAccessor.save(pratilipiId, newPcDoc);
    return newPcDoc;
}
Also used : InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) 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)

Aggregations

Pratilipi (com.pratilipi.data.type.Pratilipi)45 DataAccessor (com.pratilipi.data.DataAccessor)36 UserPratilipi (com.pratilipi.data.type.UserPratilipi)33 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)17 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)14 DocAccessor (com.pratilipi.data.DocAccessor)13 AuditLog (com.pratilipi.data.type.AuditLog)10 Author (com.pratilipi.data.type.Author)9 Page (com.pratilipi.data.type.Page)9 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)9 Date (java.util.Date)9 BlobEntry (com.pratilipi.data.type.BlobEntry)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)6 BlobAccessor (com.pratilipi.data.BlobAccessor)6 Get (com.pratilipi.api.annotation.Get)5 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 PratilipiData (com.pratilipi.data.client.PratilipiData)5 PratilipiEntity (com.pratilipi.data.type.gae.PratilipiEntity)4