use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContentImage.
public static BlobEntry getContentImage(long pratilipiId, String name, Integer width) throws InsufficientAccessException, UnexpectedServerException {
Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(pratilipiId);
// Auth Service will be taking care of it - Move it to gamma and prod asap
if (_shouldAuth()) {
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
}
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/" + pratilipiId + "/images/" + name);
if (width != null)
blobEntry = ImageUtil.resize(blobEntry, width);
return blobEntry;
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContent.
@Deprecated
public static Object getContent(Long pratilipiId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, 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.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
}
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
return null;
else if (chapterNo == null)
return _processContent(pratilipi, pcDoc);
Chapter chapter = pcDoc.getChapter(chapterNo);
if (chapter == null)
return null;
else if (pageNo == null)
return _processContent(pratilipi, chapter);
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
return null;
else
return _processContent(pratilipi, chapter.getPage(pageNo));
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiTags.
public static boolean updatePratilipiTags(long pratilipiId, PratilipiType pratilipiType, List<Long> tagIds, List<String> suggestedTags) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi == null)
return false;
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
PratilipiData pratilipiData = createPratilipiData(pratilipi);
AccessToken accessToken = AccessTokenFilter.getAccessToken();
logger.log(Level.INFO, "User Id : " + accessToken.getUserId());
if (!hasAccessToUpdatePratilipiData(pratilipi, pratilipiData)) {
throw new InsufficientAccessException();
}
if (pratilipiType != null)
pratilipi.setType(pratilipiType);
if (tagIds != null)
pratilipi.setTagIds(tagIds);
if (suggestedTags != null)
pratilipi.setSuggestedTags(suggestedTags);
dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
return true;
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method createPratilipiDataList.
public static List<PratilipiData> createPratilipiDataList(List<Long> pratilipiIdList, boolean includeAuthorData, boolean includeMetaData) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiIdList);
Map<Long, Page> pratilipiPages = dataAccessor.getPages(PageType.PRATILIPI, pratilipiIdList);
Map<Long, AuthorData> authorIdToDataMap = null;
if (includeAuthorData) {
List<Long> authorIdList = new LinkedList<>();
for (Pratilipi pratilipi : pratilipiList) if (pratilipi.getAuthorId() != null && !authorIdList.contains(pratilipi.getAuthorId()))
authorIdList.add(pratilipi.getAuthorId());
List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, false);
// List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataListEcs( authorIdList );
authorIdToDataMap = new HashMap<>(authorDataList.size());
for (AuthorData authorData : authorDataList) authorIdToDataMap.put(authorData.getId(), authorData);
}
List<PratilipiData> pratilipiDataList = new ArrayList<>(pratilipiList.size());
for (Pratilipi pratilipi : pratilipiList) {
PratilipiData pratilipiData = createPratilipiData(pratilipi, pratilipiPages.get(pratilipi.getId()), null, includeMetaData);
if (includeAuthorData && pratilipi.getAuthorId() != null)
pratilipiData.setAuthor(authorIdToDataMap.get(pratilipi.getAuthorId()));
pratilipiData.setRelevance(calculateRelevance(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId())));
pratilipiDataList.add(pratilipiData);
}
// Fetching UserPratilipi list from DataStore
List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(AccessTokenFilter.getAccessToken().getUserId(), pratilipiIdList);
// Setting isAddedToLib flag for for each PratilipiData in the list
for (int i = 0; i < userPratilipiList.size(); i++) {
UserPratilipi userPratilipi = userPratilipiList.get(i);
pratilipiDataList.get(i).setAddedToLib(userPratilipi != null && userPratilipi.isAddedToLib());
}
return pratilipiDataList;
}
use of com.pratilipi.data.type.Pratilipi in project pratilipi by Pratilipi.
the class PratilipiDataUtil method savePratilipiData.
public static PratilipiData savePratilipiData(PratilipiData pratilipiData) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
_validatePratilipiDataForSave(pratilipiData);
boolean isNew = pratilipiData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = isNew ? dataAccessor.newPratilipi() : dataAccessor.getPratilipi(pratilipiData.getId());
if (isNew && !hasAccessToAddPratilipiData(pratilipiData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdatePratilipiData(pratilipi, pratilipiData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.PRATILIPI_ADD : AccessType.PRATILIPI_UPDATE, pratilipi);
if (pratilipiData.hasTitle())
pratilipi.setTitle(pratilipiData.getTitle());
if (pratilipiData.hasTitleEn())
pratilipi.setTitleEn(pratilipiData.getTitleEn());
if (pratilipiData.hasLanguage())
pratilipi.setLanguage(pratilipiData.getLanguage());
// Do NOT update Author for existing content pieces.
if (isNew && pratilipiData.hasAuthorId())
pratilipi.setAuthorId(pratilipiData.getAuthorId());
if (pratilipiData.hasSummary())
pratilipi.setSummary(pratilipiData.getSummary());
if (pratilipiData.hasType())
pratilipi.setType(pratilipiData.getType());
if (pratilipiData.hasContentType())
pratilipi.setContentType(pratilipiData.getContentType());
else if (isNew)
pratilipi.setContentType(PratilipiContentType.PRATILIPI);
if (pratilipiData.hasState())
pratilipi.setState(pratilipiData.getState());
else if (isNew)
pratilipi.setState(PratilipiState.DRAFTED);
if (pratilipiData.hasOldContentFlag())
pratilipi.setOldContent(pratilipiData.isOldContent());
if (isNew)
pratilipi.setListingDate(new Date());
pratilipi.setLastUpdated(new Date());
if (isNew) {
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
dataAccessor.createOrUpdatePage(_updatePratilipiPageUrl(pratilipi));
} else {
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, _updatePratilipiPageUrl(pratilipi), auditLog);
}
return createPratilipiData(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId()), hasAccessToReadPratilipiMetaData(pratilipi));
}
Aggregations