Search in sources :

Example 36 with InsufficientAccessException

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

the class PratilipiDocUtil method saveContentPageBatch.

public static void saveContentPageBatch(Long pratilipiId, JsonObject chapters) 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();
    for (Map.Entry<String, JsonElement> chapterEntry : chapters.entrySet()) {
        Integer chapterNo = Integer.parseInt(chapterEntry.getKey());
        // chapterTitle
        String chapterTitle = null;
        if (chapterEntry.getValue().getAsJsonObject().has("chapterTitle"))
            chapterTitle = chapterEntry.getValue().getAsJsonObject().get("chapterTitle").getAsString();
        // content
        String content = null;
        if (chapterEntry.getValue().getAsJsonObject().has("content"))
            content = chapterEntry.getValue().getAsJsonObject().get("content").getAsString();
        // pageNo
        if (!chapterEntry.getValue().getAsJsonObject().has("pageNo"))
            throw new InvalidArgumentException(GenericRequest.ERR_PRATILIPI_PAGE_NO_REQUIRED);
        Integer pageNo = chapterEntry.getValue().getAsJsonObject().get("pageNo").getAsInt();
        // Chapter
        Chapter chapter = pcDoc.getChapter(chapterNo);
        if (chapter == null)
            chapter = pcDoc.addChapter(chapterNo, chapterTitle);
        else if (chapterTitle != null)
            chapter.setTitle(chapterTitle);
        // Page
        PratilipiContentDoc.Page page = chapter.getPage(pageNo);
        if (page == null)
            page = chapter.addPage(pageNo);
        _setPage(pratilipiId, page, content);
    }
    // Save
    docAccessor.save(pratilipiId, pcDoc);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) JsonElement(com.google.gson.JsonElement) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with InsufficientAccessException

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

the class PratilipiDocUtil method getContentIndex.

// Content doc
public static JsonArray getContentIndex(Long pratilipiId) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
    return pcDoc == null ? null : pcDoc.getIndex();
}
Also used : 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 38 with InsufficientAccessException

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

the class PratilipiDocUtil method saveContentImage.

public static String saveContentImage(Long pratilipiId, BlobEntry blobEntry) throws InsufficientAccessException, UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
        throw new InsufficientAccessException();
    String contentImageName = new Date().getTime() + "";
    BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
    blobEntry.setName(_createImageFullName(pratilipiId, contentImageName));
    blobAccessor.createOrUpdateBlob(blobEntry);
    return contentImageName;
}
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)

Example 39 with InsufficientAccessException

use of com.pratilipi.common.exception.InsufficientAccessException 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) Date(java.util.Date)

Example 40 with InsufficientAccessException

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

the class InitDataUtil method saveInitBanner.

public static String saveInitBanner(Language language, BlobEntry blobEntry) throws InsufficientAccessException, UnexpectedServerException {
    if (!hasAccessToUpdateInit(language))
        throw new InsufficientAccessException();
    String name = new Date().getTime() + "";
    BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
    blobEntry.setName("init/banners/" + language.getCode() + "/" + name);
    blobAccessor.createOrUpdateBlob(blobEntry);
    return name;
}
Also used : BlobAccessor(com.pratilipi.data.BlobAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Date(java.util.Date)

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