use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class I18nApi method post.
@Post
public static GenericResponse post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
if (!UserAccessUtil.hasUserAccess(AccessTokenFilter.getAccessToken().getUserId(), request.language, AccessType.I18N_UPDATE))
throw new InsufficientAccessException();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<I18n> i18nList = new ArrayList<>();
for (Entry<String, String> entry : request.keyValues.entrySet()) {
I18n i18n = dataAccessor.getI18n(entry.getKey());
if (i18n == null)
i18n = dataAccessor.newI18n(entry.getKey());
// Resetting the group if its already set
i18n.setGroup(request.group);
i18n.setI18nString(request.language, entry.getValue());
i18nList.add(i18n);
}
i18nList = dataAccessor.createOrUpdateI18nList(i18nList);
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class AuthorImageApi method post.
@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().newBlob(request.getName());
blobEntry.setData(request.getData());
blobEntry.setMimeType(request.getMimeType());
blobEntry.setMetaName(request.getName());
String profileImageUrl = AuthorDataUtil.saveAuthorImage(request.authorId, blobEntry);
return new Response(profileImageUrl);
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class PratilipiContentV1Api method post.
@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
PratilipiDocUtil.saveContentPage(request.pratilipiId, request.chapterNo, request.chapterTitle, request.pageNo == null ? 1 : request.pageNo, request.content);
Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", request.pratilipiId.toString()).addParam("processContentDoc", "true");
TaskQueueFactory.getPratilipiTaskQueue().add(task);
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class EventBannerApi method post.
@Post
public GenericResponse post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().newBlob(request.getName());
blobEntry.setData(request.getData());
blobEntry.setMimeType(request.getMimeType());
EventDataUtil.saveEventBanner(request.eventId, blobEntry);
return new GenericResponse();
}
use of com.pratilipi.api.shared.GenericResponse in project pratilipi by Pratilipi.
the class PratilipiProcessApi method postPratilipiProcess.
@Post
public GenericResponse postPratilipiProcess(PostPratilipiProcessRequest request) throws InvalidArgumentException, UnexpectedServerException, InsufficientAccessException {
List<Long> pratilipiIdList = request.getPratilipiIdList() != null ? request.getPratilipiIdList() : new ArrayList<Long>(1);
if (request.getPratilipiId() != null)
pratilipiIdList.add(request.getPratilipiId());
if (pratilipiIdList.size() == 0) {
logger.log(Level.SEVERE, "0 pratilipiId found.");
throw new InvalidArgumentException("'pratilipiId' or 'pratilipiIdList' must be set/non-empty.");
}
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
if (request.validateData()) {
for (Long pratilipiId : pratilipiIdList) {
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
Author author = dataAccessor.getAuthor(pratilipi.getAuthorId());
Page pratilipiPage = dataAccessor.getPage(PageType.PRATILIPI, pratilipiId);
if (pratilipi.getLanguage() == null)
throw new InvalidArgumentException("Language is null.");
if (pratilipi.getAuthorId() != null && author == null)
throw new InvalidArgumentException("Invalid Author id.");
if (pratilipi.getState() == PratilipiState.PUBLISHED && author != null && author.getState() == AuthorState.DELETED)
throw new InvalidArgumentException("Linked Author entity is DELETED.");
if (pratilipi.getState() == PratilipiState.DELETED && pratilipiPage != null)
throw new InvalidArgumentException("DELETED Pratilipi has non-deleted Page entity.");
if (pratilipi.getState() != PratilipiState.DELETED && pratilipiPage == null)
throw new InvalidArgumentException("Page entity is missing for the Pratilipi.");
if (pratilipi.getState() == PratilipiState.DELETED)
continue;
if (pratilipi.getTitle() == null && pratilipi.getTitleEn() == null)
throw new InvalidArgumentException("Title is missing for the Pratilipi.");
if ((pratilipi.getTitle() != null && pratilipi.getTitle().trim().isEmpty()) || (pratilipi.getTitleEn() != null && pratilipi.getTitleEn().trim().isEmpty()))
throw new InvalidArgumentException("Title has empty string.");
}
}
if (request.processData()) {
PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiIdList);
PratilipiDataUtil.updateFacebookScrape(pratilipiIdList);
}
if (request.processContent()) {
for (Long pratilipiId : pratilipiIdList) {
PratilipiDocUtil.updatePratilipiContent(pratilipiId);
PratilipiDataUtil.updatePratilipiIndex(pratilipiId);
boolean changed = PratilipiDocUtil.updateMeta(pratilipiId);
if (changed)
PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiId, null);
}
}
if (request.processContentDoc()) {
for (Long pratilipiId : pratilipiIdList) {
boolean changed = PratilipiDocUtil.updateMeta(pratilipiId);
if (changed)
PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiId, null);
}
}
if (request.updateReviewsDoc()) {
for (long pratilipiId : pratilipiIdList) PratilipiDocUtil.updatePratilipiReviews(pratilipiId);
}
if (request.updateStats()) {
List<Task> taskList = new ArrayList<>(pratilipiIdList.size());
List<Pratilipi> pratilipiList = DataAccessorFactory.getDataAccessor().getPratilipiList(pratilipiIdList);
for (int i = 0; i < pratilipiIdList.size(); i++) {
Pratilipi pratilipi = pratilipiList.get(i);
if (pratilipi == null || pratilipi.getState() != PratilipiState.PUBLISHED) {
pratilipiList.remove(i);
pratilipiIdList.remove(i);
i--;
continue;
}
PratilipiDataUtil.updatePratilipiStats(pratilipi.getId());
if (pratilipi.getAuthorId() != null) {
// Creating tasks to update author entities
Task task = TaskQueueFactory.newTask().setUrl("/author/process").addParam("authorId", pratilipi.getAuthorId().toString()).addParam("updateStats", "true");
taskList.add(task);
}
}
PratilipiDataUtil.updatePratilipiSearchIndex(pratilipiIdList);
TaskQueueFactory.getAuthorOfflineTaskQueue().addAll(taskList);
}
if (request.updateUserPratilipiStats()) {
for (long pratilipiId : pratilipiIdList) PratilipiDataUtil.updateUserPratilipiStats(pratilipiId);
}
return new GenericResponse();
}
Aggregations