Search in sources :

Example 1 with InsufficientAccessException

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

Example 2 with InsufficientAccessException

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

Example 3 with InsufficientAccessException

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

Example 4 with InsufficientAccessException

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

Example 5 with InsufficientAccessException

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

Aggregations

InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)48 DataAccessor (com.pratilipi.data.DataAccessor)37 Date (java.util.Date)21 AuditLog (com.pratilipi.data.type.AuditLog)19 UserPratilipi (com.pratilipi.data.type.UserPratilipi)18 Pratilipi (com.pratilipi.data.type.Pratilipi)14 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)11 BlobAccessor (com.pratilipi.data.BlobAccessor)7 DocAccessor (com.pratilipi.data.DocAccessor)7 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)7 JsonObject (com.google.gson.JsonObject)5 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)5 AccessToken (com.pratilipi.data.type.AccessToken)5 Author (com.pratilipi.data.type.Author)5 Gson (com.google.gson.Gson)4 UserData (com.pratilipi.data.client.UserData)4 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)4 User (com.pratilipi.data.type.User)4 HashMap (java.util.HashMap)4