use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class BatchProcessDataUtil method createBatchProcess.
public static void createBatchProcess(BatchProcessType type, String initDoc, String execDoc, Language language) throws InsufficientAccessException, InvalidArgumentException {
if (!hasAccessToCreateBatchProcess(language))
throw new InsufficientAccessException();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BatchProcess batchProcess = dataAccessor.newBatchProcess();
batchProcess.setType(type);
batchProcess.setInitDoc(initDoc);
batchProcess.setExecDoc(execDoc);
batchProcess.setCreationDate(new Date());
batchProcess = dataAccessor.createOrUpdateBatchProcess(batchProcess);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDataUtil method savePratilipiData.
public static PratilipiData savePratilipiData(PratilipiData pratilipiData) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
_validatePratilipiDataForSave(pratilipiData);
boolean isNew = pratilipiData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = isNew ? dataAccessor.newPratilipi() : dataAccessor.getPratilipi(pratilipiData.getId());
if (isNew && !hasAccessToAddPratilipiData(pratilipiData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdatePratilipiData(pratilipi, pratilipiData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.PRATILIPI_ADD : AccessType.PRATILIPI_UPDATE, pratilipi);
if (pratilipiData.hasTitle())
pratilipi.setTitle(pratilipiData.getTitle());
if (pratilipiData.hasTitleEn())
pratilipi.setTitleEn(pratilipiData.getTitleEn());
if (pratilipiData.hasLanguage())
pratilipi.setLanguage(pratilipiData.getLanguage());
// Do NOT update Author for existing content pieces.
if (isNew && pratilipiData.hasAuthorId())
pratilipi.setAuthorId(pratilipiData.getAuthorId());
if (pratilipiData.hasSummary())
pratilipi.setSummary(pratilipiData.getSummary());
if (pratilipiData.hasType())
pratilipi.setType(pratilipiData.getType());
if (pratilipiData.hasContentType())
pratilipi.setContentType(pratilipiData.getContentType());
else if (isNew)
pratilipi.setContentType(PratilipiContentType.PRATILIPI);
if (pratilipiData.hasState())
pratilipi.setState(pratilipiData.getState());
else if (isNew)
pratilipi.setState(PratilipiState.DRAFTED);
if (pratilipiData.hasOldContentFlag())
pratilipi.setOldContent(pratilipiData.isOldContent());
if (isNew)
pratilipi.setListingDate(new Date());
pratilipi.setLastUpdated(new Date());
if (isNew) {
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
dataAccessor.createOrUpdatePage(_updatePratilipiPageUrl(pratilipi));
} else {
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, _updatePratilipiPageUrl(pratilipi), auditLog);
}
return createPratilipiData(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId()), hasAccessToReadPratilipiMetaData(pratilipi));
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDataUtil method savePratilipiCover.
public static String savePratilipiCover(Long pratilipiId, BlobEntry blobEntry) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!hasAccessToUpdatePratilipiData(pratilipi, null))
throw new InsufficientAccessException();
String coverImageName = new Date().getTime() + "";
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
blobEntry.setName("pratilipi/" + pratilipiId + "/images/" + coverImageName);
blobAccessor.createOrUpdateBlob(blobEntry);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
pratilipi.setCoverImage(coverImageName);
pratilipi.setLastUpdated(new Date());
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
return createPratilipiCoverUrl(pratilipi);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class CommentDataUtil method saveCommentData.
public static CommentData saveCommentData(CommentData commentData) throws InvalidArgumentException, InsufficientAccessException {
_validateCommentDataForSave(commentData);
boolean isNew = commentData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Comment comment = isNew ? dataAccessor.newComment() : dataAccessor.getComment(commentData.getId());
if (isNew && !hasAccessToAddCommentData(commentData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateCommentData(comment))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.COMMENT_ADD : AccessType.COMMENT_UPDATE, comment);
if (isNew) {
comment.setUserId(commentData.getUserId());
comment.setParentType(commentData.getParentType());
comment.setParentId(commentData.getParentId());
if (commentData.getParentType() == CommentParentType.REVIEW) {
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(commentData.getParentId());
comment.setReferenceType(ReferenceType.PRATILIPI);
comment.setReferenceId(userPratilipi.getPratilipiId());
}
comment.setCreationDate(new Date());
} else {
comment.setLastUpdated(new Date());
}
if (commentData.hasContent())
comment.setContent(commentData.getContent());
if (commentData.hasState())
comment.setState(commentData.getState());
comment = dataAccessor.createOrUpdateComment(comment, auditLog);
User user = dataAccessor.getUser(commentData.getUserId());
UserData userData = UserDataUtil.createUserData(user);
commentData = createCommentData(comment);
commentData.setUser(userData);
return commentData;
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class NotificationDataUtil method getNotificationList.
public static DataListCursorTuple<NotificationData> getNotificationList(Long userId, Language language, String cursor, Integer resultCount) throws InsufficientAccessException, UnexpectedServerException {
if (!hasAccessToListData(userId))
throw new InsufficientAccessException();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Fetching Notification Entities
DataListIterator<Notification> notifListIterator = dataAccessor.getNotificationListIterator(userId, null, (String) null, cursor, null);
List<Notification> notifList = resultCount == null ? new ArrayList<Notification>() : new ArrayList<Notification>(resultCount);
while (notifListIterator.hasNext()) {
Notification notif = notifListIterator.next();
if (notif.getType().isValid(notif))
notifList.add(notif);
if (resultCount != null && notifList.size() == resultCount)
break;
}
// Return
return new DataListCursorTuple<>(createNotificationDataList(notifList, language, false), notifListIterator.getCursor());
}
Aggregations