use of com.pratilipi.data.type.BlobEntry in project pratilipi by Pratilipi.
the class PratilipiDataUtil method getPratilipiCover.
public static BlobEntry getPratilipiCover(Long pratilipiId, Integer width) throws UnexpectedServerException {
Pratilipi pratilipi = pratilipiId == null ? null : DataAccessorFactory.getDataAccessor().getPratilipi(pratilipiId);
BlobEntry blobEntry = null;
if (pratilipi == null || pratilipi.getCoverImage() == null) {
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/default/images/cover");
} else {
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/" + pratilipiId + "/images/" + pratilipi.getCoverImage());
if (blobEntry == null)
blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi-cover/original/" + pratilipiId);
}
if (width != null)
blobEntry = ImageUtil.resize(blobEntry, width, (int) (1.5 * width));
return blobEntry;
}
use of com.pratilipi.data.type.BlobEntry 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.type.BlobEntry in project pratilipi by Pratilipi.
the class InitDataUtil method getInitBanner.
public static BlobEntry getInitBanner(Language language, String name, Integer width) throws InvalidArgumentException, UnexpectedServerException {
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("init/banners/" + language.getCode() + "/" + name);
if (blobEntry == null) {
JsonObject errorMessages = new JsonObject();
errorMessages.addProperty("name", "Invalid banner name.");
throw new InvalidArgumentException(errorMessages);
}
if (width != null)
blobEntry.setData(ImageUtil.resize(blobEntry.getData(), width));
return blobEntry;
}
use of com.pratilipi.data.type.BlobEntry in project pratilipi by Pratilipi.
the class BlobAccessorWithMemcache method memcacheGet.
private BlobEntry memcacheGet(String fileName) {
BlobEntry blobEntry = memcache.get(PREFIX + fileName);
if (blobEntry == null)
return null;
if (blobEntry.getData().length == blobEntry.getDataLength())
return blobEntry;
int dataLength = (int) blobEntry.getDataLength();
List<String> keyList = new ArrayList<String>((int) Math.ceil((double) dataLength / SEGMENT_SIZE));
for (int i = 1; i < (int) Math.ceil((double) dataLength / SEGMENT_SIZE); i++) keyList.add(PREFIX + fileName + "?" + i);
Map<String, Serializable> keySegmentMap = memcache.getAll(keyList);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write(blobEntry.getData());
for (String key : keyList) {
byte[] dataSegment = (byte[]) keySegmentMap.get(key);
if (dataSegment == null)
return null;
baos.write(dataSegment);
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load and stitch blob data.", e);
return null;
}
byte[] blobData = baos.toByteArray();
if (blobData.length != dataLength) {
logger.log(Level.SEVERE, "Blob size (" + blobData.length + ") did not match expected size (" + dataLength + ")");
return null;
}
blobEntry.setData(blobData);
return blobEntry;
}
use of com.pratilipi.data.type.BlobEntry in project pratilipi by Pratilipi.
the class BlobAccessorWithMemcache method getBlob.
@Override
public BlobEntry getBlob(String fileName) throws UnexpectedServerException {
BlobEntry blobEntry = memcacheGet(fileName);
if (blobEntry == null) {
blobEntry = blobAccessor.getBlob(fileName);
memcachePut(blobEntry);
}
return blobEntry;
}
Aggregations