Search in sources :

Example 16 with Pratilipi

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;
}
Also used : BlobEntry(com.pratilipi.data.type.BlobEntry) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Example 17 with Pratilipi

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));
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) Chapter(com.pratilipi.data.type.PratilipiContentDoc.Chapter) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) PratilipiContentDoc(com.pratilipi.data.type.PratilipiContentDoc)

Example 18 with Pratilipi

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;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) PratilipiData(com.pratilipi.data.client.PratilipiData) AccessToken(com.pratilipi.data.type.AccessToken) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog)

Example 19 with Pratilipi

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;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Page(com.pratilipi.data.type.Page) LinkedList(java.util.LinkedList) UserPratilipi(com.pratilipi.data.type.UserPratilipi) PratilipiData(com.pratilipi.data.client.PratilipiData) AuthorData(com.pratilipi.data.client.AuthorData) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi)

Example 20 with Pratilipi

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));
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Aggregations

Pratilipi (com.pratilipi.data.type.Pratilipi)45 DataAccessor (com.pratilipi.data.DataAccessor)36 UserPratilipi (com.pratilipi.data.type.UserPratilipi)33 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)17 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)14 DocAccessor (com.pratilipi.data.DocAccessor)13 AuditLog (com.pratilipi.data.type.AuditLog)10 Author (com.pratilipi.data.type.Author)9 Page (com.pratilipi.data.type.Page)9 Chapter (com.pratilipi.data.type.PratilipiContentDoc.Chapter)9 Date (java.util.Date)9 BlobEntry (com.pratilipi.data.type.BlobEntry)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)6 BlobAccessor (com.pratilipi.data.BlobAccessor)6 Get (com.pratilipi.api.annotation.Get)5 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 PratilipiData (com.pratilipi.data.client.PratilipiData)5 PratilipiEntity (com.pratilipi.data.type.gae.PratilipiEntity)4