Search in sources :

Example 31 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method saveUserPratilipiAddToLibrary.

public static UserPratilipiData saveUserPratilipiAddToLibrary(Long userId, Long pratilipiId, String lastOpenedPage, Boolean addedToLibrary) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
    if (userPratilipi == null) {
        userPratilipi = dataAccessor.newUserPratilipi();
        userPratilipi.setUserId(userId);
        userPratilipi.setPratilipiId(pratilipiId);
    }
    if (lastOpenedPage == null && addedToLibrary == null)
        return createUserPratilipiData(userPratilipi);
    if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_LIBRARY))
        throw new InsufficientAccessException();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_LIBRARY, userPratilipi);
    if (lastOpenedPage != null) {
        userPratilipi.setLastOpenedPage(lastOpenedPage);
        userPratilipi.setLastOpenedDate(new Date());
    }
    if (addedToLibrary != null) {
        userPratilipi.setAddedToLib(addedToLibrary);
        userPratilipi.setAddedToLibDate(new Date());
    }
    userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
    return createUserPratilipiData(userPratilipi);
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 32 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class NotificationDataUtil method saveNotificationState.

public static void saveNotificationState(Map<Long, NotificationState> notificationStates) throws InsufficientAccessException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Map<Long, Notification> notifications = dataAccessor.getNotifications(notificationStates.keySet());
    for (Map.Entry<Long, NotificationState> entry : notificationStates.entrySet()) {
        Notification notification = notifications.get(entry.getKey());
        if (notification.getState() == entry.getValue())
            continue;
        if (!hasAccessToUpdateData(notification))
            throw new InsufficientAccessException();
        notification.setState(entry.getValue());
    }
    dataAccessor.createOrUpdateNotificationList(new ArrayList<Notification>(notifications.values()));
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) HashMap(java.util.HashMap) Map(java.util.Map) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Notification(com.pratilipi.data.type.Notification) NotificationState(com.pratilipi.common.type.NotificationState)

Example 33 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class PratilipiDocUtil method saveContentPage.

public static void saveContentPage(Long pratilipiId, Integer chapterNo, String chapterTitle, Integer pageNo, String html) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    // Doc
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        pcDoc = docAccessor.newPratilipiContentDoc();
    // Chapter
    Chapter chapter = pcDoc.getChapter(chapterNo);
    if (chapter == null)
        chapter = pcDoc.addChapter(chapterNo, chapterTitle);
    else
        chapter.setTitle(chapterTitle);
    // Page
    PratilipiContentDoc.Page page = chapter.getPage(pageNo);
    if (page == null)
        page = chapter.addPage(pageNo);
    _setPage(pratilipiId, page, html);
    // Save
    docAccessor.save(pratilipiId, pcDoc);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 34 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class PratilipiDocUtil method deleteContentChapter.

public static JsonArray deleteContentChapter(Long pratilipiId, Integer chapterNo) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    if (pcDoc == null)
        return new JsonArray();
    pcDoc.deleteChapter(chapterNo);
    docAccessor.save(pratilipiId, pcDoc);
    return pcDoc.getIndex();
}
Also used : JsonArray(com.google.gson.JsonArray) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 35 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.

the class PratilipiDataUtil method getPratilipiContent.

public static String getPratilipiContent(long pratilipiId, Integer chapterNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!hasAccessToReadPratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob(CONTENT_FOLDER + "/" + pratilipiId);
    if (blobEntry == null)
        return null;
    String contentHtml = new String(blobEntry.getData(), Charset.forName("UTF-8"));
    PratilipiContentUtil pratilipiContentUtil = new PratilipiContentUtil(contentHtml);
    return pratilipiContentUtil.getContent(chapterNo);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) BlobEntry(com.pratilipi.data.type.BlobEntry) PratilipiContentUtil(com.pratilipi.common.util.PratilipiContentUtil) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

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