use of com.pratilipi.data.type.AuditLog 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.data.type.AuditLog in project pratilipi by Pratilipi.
the class EmailDataUtil method _updateUserEntity.
private static void _updateUserEntity(Long userId) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUser(userId);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
user.setLastEmailedDate(new Date());
user.setLastUpdated(new Date());
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
use of com.pratilipi.data.type.AuditLog in project pratilipi by Pratilipi.
the class UserPratilipiBackfillApi method updateUserPratilipi.
private UserPratilipiData updateUserPratilipi(Long userId, Long pratilipiId, String lastPageOpened, String lastOpenedDate) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
// CREATE USER PRATILIPI
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
// Creating Auditlog entity
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_REVIEW, userPratilipi);
// update lastPageOpened
userPratilipi.setLastOpenedPage(lastPageOpened);
try {
// update lastPageOpenedDate
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
formatter.setTimeZone(TimeZone.getTimeZone("IST"));
Date date = (Date) formatter.parse(lastOpenedDate);
userPratilipi.setLastOpenedDate(date);
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.log(Level.SEVERE, "Event Date : " + lastOpenedDate);
throw new UnexpectedServerException("Error while parsing date.");
}
return UserPratilipiDataUtil.createUserPratilipiData(userPratilipi);
}
use of com.pratilipi.data.type.AuditLog 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.data.type.AuditLog in project pratilipi by Pratilipi.
the class EventDataUtil method saveEventBanner.
public static void saveEventBanner(Long eventId, BlobEntry blobEntry) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Event event = dataAccessor.getEvent(eventId);
if (!hasAccessToUpdateEventData(event, null))
throw new InsufficientAccessException();
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
blobEntry.setName(BANNER_FOLDER + "/" + eventId);
blobAccessor.createOrUpdateBlob(blobEntry);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.EVENT_UPDATE, event);
event.setLastUpdated(new Date());
auditLog.setEventComment("Uploaded banner image.");
event = dataAccessor.createOrUpdateEvent(event, auditLog);
}
Aggregations