use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class BlogPostDataUtil method saveBlogPostData.
public static BlogPostData saveBlogPostData(BlogPostData blogPostData) throws InvalidArgumentException, InsufficientAccessException {
_validateBlogPostDataForSave(blogPostData);
boolean isNew = blogPostData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BlogPost blogPost = isNew ? dataAccessor.newBlogPost() : dataAccessor.getBlogPost(blogPostData.getId());
if (isNew && !hasAccessToAddBlogPostData(blogPostData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateBlogPostData(blogPost, blogPostData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.BLOG_POST_ADD : AccessType.BLOG_POST_UPDATE, blogPost);
if (// Changing blog id is not allowed
isNew && blogPostData.hasBlogId())
blogPost.setBlogId(blogPostData.getBlogId());
if (blogPostData.hasTitle())
blogPost.setTitle(blogPostData.getTitle());
if (blogPostData.hasTitleEn())
blogPost.setTitleEn(blogPostData.getTitleEn());
if (blogPostData.hasContent())
blogPost.setContent(blogPostData.getContent());
if (blogPostData.hasLanguage())
blogPost.setLanguage(blogPostData.getLanguage());
if (blogPostData.hasState())
blogPost.setState(blogPostData.getState());
if (isNew) {
blogPost.setCreatedBy(AccessTokenFilter.getAccessToken().getUserId());
blogPost.setCreationDate(new Date());
} else if (blogPost.getCreatedBy() == null) {
blogPost.setCreatedBy(AccessTokenFilter.getAccessToken().getUserId());
}
blogPost.setLastUpdated(new Date());
blogPost = dataAccessor.createOrUpdateBlogPost(blogPost, auditLog);
_updateBlogPostPageUrl(blogPost);
return createBlogPostData(blogPost);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class EventDataUtil method saveEventData.
public static EventData saveEventData(EventData eventData) throws InvalidArgumentException, InsufficientAccessException {
_validateEventDataForSave(eventData);
boolean isNew = eventData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Event event = isNew ? dataAccessor.newEvent() : dataAccessor.getEvent(eventData.getId());
if (isNew && !hasAccessToAddEventData(eventData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateEventData(event, eventData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.EVENT_ADD : AccessType.EVENT_UPDATE, event);
if (eventData.hasName())
event.setName(eventData.getName());
if (eventData.hasNameEn())
event.setNameEn(eventData.getNameEn());
if (eventData.hasLanguage())
event.setLanguage(eventData.getLanguage());
if (eventData.hasDescription())
event.setDescription(eventData.getDescription());
if (eventData.hasPratilipiUrlList()) {
if (eventData.getPratilipiUrlList() == null) {
eventData.setPratilipiIdList(null);
} else {
List<Long> pratilipiIdList = new LinkedList<>();
Map<String, Page> map = dataAccessor.getPages(eventData.getPratilipiUrlList());
for (String pratilipiUrl : eventData.getPratilipiUrlList()) {
Page page = map.get(pratilipiUrl);
if (page != null && page.getType() == PageType.PRATILIPI)
pratilipiIdList.add(page.getPrimaryContentId());
}
event.setPratilipiIdList(pratilipiIdList);
}
}
if (isNew)
event.setCreationDate(new Date());
event.setLastUpdated(new Date());
if (isNew) {
event = dataAccessor.createOrUpdateEvent(event, auditLog);
dataAccessor.createOrUpdatePage(_updateEventPageUrl(event));
} else {
event = dataAccessor.createOrUpdateEvent(event, _updateEventPageUrl(event), auditLog);
}
return createEventData(event, true);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class AuthorDataUtil method getAuthorDataList.
public static DataListCursorTuple<AuthorData> getAuthorDataList(String searchQuery, AuthorFilter authorFilter, String cursor, Integer resultCount) throws InsufficientAccessException {
if (!hasAccessToListAuthorData(authorFilter.getLanguage()))
throw new InsufficientAccessException();
// Processing search query
if (searchQuery != null)
searchQuery = searchQuery.toLowerCase().trim().replaceAll(",|\\sor\\s", " ").replaceAll("[\\s]+", " OR ");
DataListCursorTuple<Long> authorIdListCursorTuple = DataAccessorFactory.getSearchAccessor().searchAuthor(searchQuery, authorFilter, cursor, null, resultCount);
List<AuthorData> authorDataList = createAuthorDataList(authorIdListCursorTuple.getDataList(), true);
return new DataListCursorTuple<AuthorData>(authorDataList, authorIdListCursorTuple.getCursor());
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class AuthorDataUtil method saveAuthorImage.
public static String saveAuthorImage(Long authorId, BlobEntry blobEntry) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
if (blobEntry.getData() == null || blobEntry.getData().length == 0)
throw new InvalidArgumentException("Image data is missing.");
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(authorId);
if (!hasAccessToUpdateAuthorData(author, null))
throw new InsufficientAccessException();
String profileImageName = new Date().getTime() + "";
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
blobEntry.setName("author/" + authorId + "/images/profile/" + profileImageName);
blobAccessor.createOrUpdateBlob(blobEntry);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.AUTHOR_UPDATE, author);
author.setProfileImage(profileImageName);
author.setLastUpdated(new Date());
author = dataAccessor.createOrUpdateAuthor(author, auditLog);
return createAuthorProfileImageUrl(author);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class AuthorDataUtil method removeAuthorImage.
public static void removeAuthorImage(Long authorId, boolean coverImage, boolean profileImage) throws InsufficientAccessException {
if (!coverImage && !profileImage)
return;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(authorId);
if (!hasAccessToUpdateAuthorData(author, null))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.AUTHOR_UPDATE, author);
if (coverImage)
author.setCoverImage(null);
if (profileImage)
author.setProfileImage(null);
author.setLastUpdated(new Date());
author = dataAccessor.createOrUpdateAuthor(author, auditLog);
}
Aggregations