use of com.pratilipi.data.type.PratilipiMetaDoc in project pratilipi by Pratilipi.
the class PratilipiDataUtil method getPratilipiKeywords.
public static String getPratilipiKeywords(Long pratilipiId) throws UnexpectedServerException {
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiMetaDoc pmDoc = docAccessor.getPratilipiMetaDoc(pratilipiId);
if (pmDoc == null)
return null;
String keywords = "";
for (String str : pmDoc.getWordCounts().keySet()) keywords += str + " ";
keywords = keywords.trim();
return keywords.isEmpty() ? null : keywords;
}
use of com.pratilipi.data.type.PratilipiMetaDoc in project pratilipi by Pratilipi.
the class PratilipiDocUtil method updateMeta.
public static boolean updateMeta(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
PratilipiMetaDoc pmDoc = docAccessor.getPratilipiMetaDoc(pratilipiId);
if (pmDoc == null)
pmDoc = docAccessor.newPratilipiMetaDoc();
int wordCount = 0;
int imageCount = 0;
int chapterCount = 0;
Map<String, Integer> wordCounts = new HashMap<>();
for (PratilipiContentDoc.Chapter chapter : pcDoc.getChapterList()) {
String content = chapter.getTitle() == null ? "" : chapter.getTitle();
for (PratilipiContentDoc.Page page : chapter.getPageList()) {
for (PratilipiContentDoc.Pagelet pagelet : page.getPageletList()) {
if (pagelet.getType() == PratilipiContentDoc.PageletType.IMAGE)
imageCount++;
else
content += " " + pagelet.getDataAsString();
}
}
content = content.trim();
if (content.length() > 1) {
String[] words = content.replaceAll(nonKeywordsPattern, " ").split("[\\s]+");
for (String word : words) {
Integer count = wordCounts.get(word);
count = count == null ? 1 : count++;
wordCounts.put(word, count);
}
wordCount += words.length;
}
chapterCount++;
}
boolean isChanged = wordCounts.size() != pmDoc.getWordCounts().size();
if (!isChanged) {
for (Entry<String, Integer> entry : pmDoc.getWordCounts().entrySet()) {
if (!entry.getValue().equals(wordCounts.get(entry.getKey()))) {
isChanged = true;
break;
}
}
}
if (isChanged) {
// Update & Save Pratilipi Meta Doc
pmDoc.setWordCounts(wordCounts);
docAccessor.save(pratilipiId, pmDoc);
// Update counts in Pratilipi Entity
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
pratilipi.setWordCount(wordCount);
pratilipi.setImageCount(imageCount);
pratilipi.setChapterCount(chapterCount);
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
}
return isChanged;
}
Aggregations