Search in sources :

Example 16 with BlobAccessor

use of com.pratilipi.data.BlobAccessor 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)

Example 17 with BlobAccessor

use of com.pratilipi.data.BlobAccessor in project pratilipi by Pratilipi.

the class PratilipiDataUtil method updatePratilipiIndex.

public static void updatePratilipiIndex(Long pratilipiId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
    if (pratilipi.isOldContent() && pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
        BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
        BlobEntry blobEntry = blobAccessor.getBlob(CONTENT_FOLDER + "/" + pratilipiId);
        String index = null;
        Integer pageCount = 0;
        if (blobEntry != null) {
            String content = new String(blobEntry.getData(), Charset.forName("UTF-8"));
            PratilipiContentUtil pratilipiContentUtil = new PratilipiContentUtil(content);
            index = pratilipiContentUtil.generateIndex();
            pageCount = pratilipiContentUtil.getPageCount();
        }
        AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
        boolean isChanged = false;
        if ((pratilipi.getIndex() == null && index != null) || (pratilipi.getIndex() != null && index == null) || (pratilipi.getIndex() != null && index != null && !pratilipi.getIndex().equals(index))) {
            pratilipi.setIndex(index);
            isChanged = true;
        }
        if (pratilipi.getPageCount() != pageCount) {
            pratilipi.setPageCount(pageCount);
            isChanged = true;
        }
        if (isChanged)
            pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
    } else {
    // throw new InvalidArgumentException( "Index generation for " + pratilipi.getContentType() + " content type is not yet supported." );
    }
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) BlobEntry(com.pratilipi.data.type.BlobEntry) BlobAccessor(com.pratilipi.data.BlobAccessor) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi) AuditLog(com.pratilipi.data.type.AuditLog)

Example 18 with BlobAccessor

use of com.pratilipi.data.BlobAccessor in project pratilipi by Pratilipi.

the class AuthorDataUtil method saveAuthorImage.

public static String saveAuthorImage(Long authorId, BlobEntry blobEntry) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    if (blobEntry.getData() == null || blobEntry.getData().length == 0)
        throw new InvalidArgumentException("Image data is missing.");
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(authorId);
    if (!hasAccessToUpdateAuthorData(author, null))
        throw new InsufficientAccessException();
    String profileImageName = new Date().getTime() + "";
    BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
    blobEntry.setName("author/" + authorId + "/images/profile/" + profileImageName);
    blobAccessor.createOrUpdateBlob(blobEntry);
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.AUTHOR_UPDATE, author);
    author.setProfileImage(profileImageName);
    author.setLastUpdated(new Date());
    author = dataAccessor.createOrUpdateAuthor(author, auditLog);
    return createAuthorProfileImageUrl(author);
}
Also used : InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) DataAccessor(com.pratilipi.data.DataAccessor) BlobAccessor(com.pratilipi.data.BlobAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Example 19 with BlobAccessor

use of com.pratilipi.data.BlobAccessor 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);
    // Auth Service will be taking care of it - Move it to gamma and prod asap
    if (_shouldAuth()) {
        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)

Aggregations

BlobAccessor (com.pratilipi.data.BlobAccessor)19 DataAccessor (com.pratilipi.data.DataAccessor)13 BlobEntry (com.pratilipi.data.type.BlobEntry)12 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)7 Date (java.util.Date)7 Pratilipi (com.pratilipi.data.type.Pratilipi)6 SimpleDateFormat (java.text.SimpleDateFormat)6 UserPratilipi (com.pratilipi.data.type.UserPratilipi)5 DateFormat (java.text.DateFormat)5 AuditLog (com.pratilipi.data.type.AuditLog)4 Gson (com.google.gson.Gson)3 JsonObject (com.google.gson.JsonObject)3 Get (com.pratilipi.api.annotation.Get)3 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 GsonBuilder (com.google.gson.GsonBuilder)2 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)2 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)2 DocAccessor (com.pratilipi.data.DocAccessor)2 Author (com.pratilipi.data.type.Author)2 Page (com.pratilipi.data.type.Page)2