Search in sources :

Example 21 with AuditLog

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) BlogPost(com.pratilipi.data.type.BlogPost) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 22 with AuditLog

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);
}
Also used : User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 23 with 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);
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) DataAccessor(com.pratilipi.data.DataAccessor) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 24 with AuditLog

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Event(com.pratilipi.data.type.Event) Page(com.pratilipi.data.type.Page) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog)

Example 25 with AuditLog

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) BlobAccessor(com.pratilipi.data.BlobAccessor) Event(com.pratilipi.data.type.Event) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog)

Aggregations

AuditLog (com.pratilipi.data.type.AuditLog)29 DataAccessor (com.pratilipi.data.DataAccessor)28 Date (java.util.Date)19 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)17 UserPratilipi (com.pratilipi.data.type.UserPratilipi)15 Pratilipi (com.pratilipi.data.type.Pratilipi)10 User (com.pratilipi.data.type.User)8 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)7 DocAccessor (com.pratilipi.data.DocAccessor)5 BlobAccessor (com.pratilipi.data.BlobAccessor)4 JsonObject (com.google.gson.JsonObject)3 UserData (com.pratilipi.data.client.UserData)3 Comment (com.pratilipi.data.type.Comment)3 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)3 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)3 HashMap (java.util.HashMap)3 Get (com.pratilipi.api.annotation.Get)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 AccessToken (com.pratilipi.data.type.AccessToken)2 BlobEntry (com.pratilipi.data.type.BlobEntry)2