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);
}
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." );
}
}
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);
}
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;
}
Aggregations