use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDocUtil method saveContentPageBatch.
public static void saveContentPageBatch(Long pratilipiId, JsonObject chapters) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
// Doc
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
pcDoc = docAccessor.newPratilipiContentDoc();
for (Map.Entry<String, JsonElement> chapterEntry : chapters.entrySet()) {
Integer chapterNo = Integer.parseInt(chapterEntry.getKey());
// chapterTitle
String chapterTitle = null;
if (chapterEntry.getValue().getAsJsonObject().has("chapterTitle"))
chapterTitle = chapterEntry.getValue().getAsJsonObject().get("chapterTitle").getAsString();
// content
String content = null;
if (chapterEntry.getValue().getAsJsonObject().has("content"))
content = chapterEntry.getValue().getAsJsonObject().get("content").getAsString();
// pageNo
if (!chapterEntry.getValue().getAsJsonObject().has("pageNo"))
throw new InvalidArgumentException(GenericRequest.ERR_PRATILIPI_PAGE_NO_REQUIRED);
Integer pageNo = chapterEntry.getValue().getAsJsonObject().get("pageNo").getAsInt();
// Chapter
Chapter chapter = pcDoc.getChapter(chapterNo);
if (chapter == null)
chapter = pcDoc.addChapter(chapterNo, chapterTitle);
else if (chapterTitle != null)
chapter.setTitle(chapterTitle);
// Page
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
page = chapter.addPage(pageNo);
_setPage(pratilipiId, page, content);
}
// Save
docAccessor.save(pratilipiId, pcDoc);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContentIndex.
// Content doc
public static JsonArray getContentIndex(Long pratilipiId) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
return pcDoc == null ? null : pcDoc.getIndex();
}
use of com.pratilipi.common.exception.InsufficientAccessException 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);
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;
}
use of com.pratilipi.common.exception.InsufficientAccessException 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.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class InitDataUtil method saveInitBanner.
public static String saveInitBanner(Language language, BlobEntry blobEntry) throws InsufficientAccessException, UnexpectedServerException {
if (!hasAccessToUpdateInit(language))
throw new InsufficientAccessException();
String name = new Date().getTime() + "";
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
blobEntry.setName("init/banners/" + language.getCode() + "/" + name);
blobAccessor.createOrUpdateBlob(blobEntry);
return name;
}
Aggregations