use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updateFacebookScrape.
public static void updateFacebookScrape(List<Long> pratilipiIdList) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
for (Long pratilipiId : pratilipiIdList) {
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi.getState() != PratilipiState.PUBLISHED)
continue;
Page page = dataAccessor.getPage(PageType.PRATILIPI, pratilipiId);
String uri = page.getUriAlias() == null ? page.getUri() : page.getUriAlias();
FacebookApi.postScrapeRequest("http://" + pratilipi.getLanguage().getHostName() + uri);
}
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method getPratilipiContent.
public static String getPratilipiContent(long pratilipiId, Integer chapterNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob(CONTENT_FOLDER + "/" + pratilipiId);
if (blobEntry == null)
return null;
String contentHtml = new String(blobEntry.getData(), Charset.forName("UTF-8"));
PratilipiContentUtil pratilipiContentUtil = new PratilipiContentUtil(contentHtml);
return pratilipiContentUtil.getContent(chapterNo);
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiIndex.
public static void updatePratilipiIndex(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi.isOldContent() && pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
BlobEntry blobEntry = blobAccessor.getBlob(CONTENT_FOLDER + "/" + pratilipiId);
String index = null;
Integer pageCount = 0;
if (blobEntry != null) {
String content = new String(blobEntry.getData(), Charset.forName("UTF-8"));
PratilipiContentUtil pratilipiContentUtil = new PratilipiContentUtil(content);
index = pratilipiContentUtil.generateIndex();
pageCount = pratilipiContentUtil.getPageCount();
}
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
boolean isChanged = false;
if ((pratilipi.getIndex() == null && index != null) || (pratilipi.getIndex() != null && index == null) || (pratilipi.getIndex() != null && index != null && !pratilipi.getIndex().equals(index))) {
pratilipi.setIndex(index);
isChanged = true;
}
if (pratilipi.getPageCount() != pageCount) {
pratilipi.setPageCount(pageCount);
isChanged = true;
}
if (isChanged)
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
} else {
// throw new InvalidArgumentException( "Index generation for " + pratilipi.getContentType() + " content type is not yet supported." );
}
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiSearchIndex.
public static void updatePratilipiSearchIndex(Long pratilipiId, Long authorId) throws InvalidArgumentException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Pratilipi> pratilipiList = null;
if (authorId != null) {
PratilipiFilter pratilipiFilter = new PratilipiFilter();
pratilipiFilter.setAuthorId(authorId);
pratilipiList = dataAccessor.getPratilipiList(pratilipiFilter, null, null).getDataList();
} else if (pratilipiId != null) {
pratilipiList = new ArrayList<>(1);
pratilipiList.add(dataAccessor.getPratilipi(pratilipiId));
} else {
logger.log(Level.SEVERE, "Neither AuthorId, nor PratilipiId is provided !");
throw new InvalidArgumentException("Neither AuthorId, nor PratilipiId is provided !");
}
_updatePratilipiSearchIndex(pratilipiList);
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDocUtil method saveContentPage.
public static PratilipiContentDoc saveContentPage(Long pratilipiId, String chapterId, Integer chapterNo, String chapterTitle, Integer pageNo, String html) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
// Auth check
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
// backfill chapterId
PratilipiContentDoc pcDoc = _validateChapterIdInContent(pratilipiId);
// if not present, get a new doc
if (pcDoc == null)
pcDoc = docAccessor.newPratilipiContentDoc();
// Chapter
Chapter chapter = null;
// If chapterNo is not null => web case
if (chapterNo != null) {
// If chapter already present -> editChapter case -> update the chapter and set lastUpdated and lastUpdatedBy
chapter = pcDoc.getChapter(chapterNo);
// If chapter not present -> addChapter case -> add empty chapters (there are 10 chapters already, user is trying to add 15th chapter => so add 4 empty chapters in between)
if (chapter == null) {
/* Add Chapter */
Long aChapterId = new Date().getTime();
while ((chapter = pcDoc.getChapter(chapterNo)) == null) {
Chapter ch = pcDoc.addChapter(null);
ch.setId(generateChapterId(pratilipiId, aChapterId++));
ch.setLastUpdated(UxModeFilter.getClientType());
}
}
// If chapterId is not null => android case
} else if (chapterId != null) {
// If chapter already present -> editChapter case -> update the chapter and set lastUpdated and lastUpdatedBy
chapter = pcDoc.getChapter(chapterId);
// If chapter not present -> addChapter case -> add chapter at the end always
if (chapter == null) {
chapter = pcDoc.addChapter(chapterTitle);
chapter.setId(chapterId);
}
}
// Set lastUpdatedDate and lastUpdatedBy -> WEB / ANDROID
chapter.setLastUpdated(UxModeFilter.getClientType());
// Setting chapterTitle
if (chapterTitle != null)
chapter.setTitle(chapterTitle);
// Page
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
page = chapter.addPage(pageNo);
// Magic
_setPage(pratilipiId, page, html);
// Save
docAccessor.save(pratilipiId, pcDoc);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE_CONTENT, null);
auditLog.setEventDataNew(html);
auditLog.setPrimaryContentId(pratilipiId);
auditLog.setCreationDate(new Date());
dataAccessor.createOrUpdateAuditLog(auditLog);
return pcDoc;
}
Aggregations