use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method saveUserPratilipiAddToLibrary.
public static UserPratilipiData saveUserPratilipiAddToLibrary(Long userId, Long pratilipiId, String lastOpenedPage, Boolean addedToLibrary) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
if (lastOpenedPage == null && addedToLibrary == null)
return createUserPratilipiData(userPratilipi);
if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_LIBRARY))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_LIBRARY, userPratilipi);
if (lastOpenedPage != null) {
userPratilipi.setLastOpenedPage(lastOpenedPage);
userPratilipi.setLastOpenedDate(new Date());
}
if (addedToLibrary != null) {
userPratilipi.setAddedToLib(addedToLibrary);
userPratilipi.setAddedToLibDate(new Date());
}
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
return createUserPratilipiData(userPratilipi);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class NotificationDataUtil method saveNotificationState.
public static void saveNotificationState(Map<Long, NotificationState> notificationStates) throws InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Map<Long, Notification> notifications = dataAccessor.getNotifications(notificationStates.keySet());
for (Map.Entry<Long, NotificationState> entry : notificationStates.entrySet()) {
Notification notification = notifications.get(entry.getKey());
if (notification.getState() == entry.getValue())
continue;
if (!hasAccessToUpdateData(notification))
throw new InsufficientAccessException();
notification.setState(entry.getValue());
}
dataAccessor.createOrUpdateNotificationList(new ArrayList<Notification>(notifications.values()));
}
use of com.pratilipi.common.exception.InsufficientAccessException 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.common.exception.InsufficientAccessException 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.common.exception.InsufficientAccessException 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);
}
Aggregations