use of com.pratilipi.data.DocAccessor 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.DocAccessor 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.DocAccessor 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);
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContentIndex.
// Content doc
public static JsonArray getContentIndex(Long pratilipiId) throws 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);
return pcDoc == null ? null : pcDoc.getIndex();
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method updatePratilipiGoogleAnalyticsPageViews.
public static void updatePratilipiGoogleAnalyticsPageViews(Long pratilipiId, int year, int month, int day, int pageViews, int readPageViews) throws UnexpectedServerException {
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiGoogleAnalyticsDoc gaDoc = docAccessor.getPratilipiGoogleAnalyticsDoc(pratilipiId);
gaDoc.setPageViews(year, month, day, pageViews);
gaDoc.setReadPageViews(year, month, day, readPageViews);
docAccessor.save(pratilipiId, gaDoc);
}
Aggregations