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());
}
}
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;
}
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();
}
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));
}
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;
}
Aggregations