use of com.pratilipi.data.type.AuditLog 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.AuditLog 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;
}
use of com.pratilipi.data.type.AuditLog in project pratilipi by Pratilipi.
the class PratilipiDocUtil method saveContentPageBatch.
public static PratilipiContentDoc saveContentPageBatch(Long pratilipiId, JsonObject chapters) 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.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()) {
String chapterId = 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(chapterId);
if (chapter == null) {
chapter = pcDoc.addChapter(pcDoc.getChapterCount() + 1, chapterTitle);
chapter.setId(chapterId);
} else if (chapterTitle != null) {
chapter.setTitle(chapterTitle);
}
chapter.setLastUpdated(UxModeFilter.getClientType());
// Page
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
page = chapter.addPage(pageNo);
_setPage(pratilipiId, page, content);
}
// Save
docAccessor.save(pratilipiId, pcDoc);
// AuditLog
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE_CONTENT, null);
auditLog.setEventDataNew(chapters);
auditLog.setPrimaryContentId(pratilipiId);
auditLog.setCreationDate(new Date());
dataAccessor.createOrUpdateAuditLog(auditLog);
return pcDoc;
}
use of com.pratilipi.data.type.AuditLog in project pratilipi by Pratilipi.
the class TestApi method get.
@Get
public static GenericResponse get(GenericRequest request) throws UnexpectedServerException {
String primaryContentId = 4920371378651136L + "";
Query<AuditLogEntity> query = ObjectifyService.ofy().load().type(AuditLogEntity.class).filter("PRIMARY_CONTENT_ID", primaryContentId).filter("CREATION_DATE >=", new Date(new Date().getTime() - TimeUnit.DAYS.toMillis(1))).order("CREATION_DATE").chunk(100).limit(100);
List<AuditLog> responseList = new ArrayList<AuditLog>();
QueryResultIterator<AuditLogEntity> iterator = query.iterator();
while (iterator.hasNext()) responseList.add(iterator.next());
System.out.println(responseList.size());
return new GenericResponse();
}
Aggregations