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