Search in sources :

Example 41 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class MediaWikiImporter method readAssetTagNames.

protected String[] readAssetTagNames(long userId, WikiNode node, String content) throws PortalException, SystemException {
    Matcher matcher = _categoriesPattern.matcher(content);
    List<String> assetTagNames = new ArrayList<String>();
    while (matcher.find()) {
        String categoryName = matcher.group(1);
        categoryName = normalize(categoryName, 75);
        AssetTag assetTag = null;
        try {
            assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
        } catch (NoSuchTagException nste) {
            ServiceContext serviceContext = new ServiceContext();
            serviceContext.setAddGroupPermissions(true);
            serviceContext.setAddGuestPermissions(true);
            serviceContext.setScopeGroupId(node.getGroupId());
            assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
        }
        assetTagNames.add(assetTag.getName());
    }
    if (content.contains(_WORK_IN_PROGRESS)) {
        assetTagNames.add(_WORK_IN_PROGRESS_TAG);
    }
    return assetTagNames.toArray(new String[assetTagNames.size()]);
}
Also used : AssetTag(com.liferay.portlet.asset.model.AssetTag) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException) Matcher(java.util.regex.Matcher) ServiceContext(com.liferay.portal.service.ServiceContext) ArrayList(java.util.ArrayList)

Example 42 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class MediaWikiImporter method processImages.

protected void processImages(long userId, WikiNode node, InputStream imagesInputStream) throws Exception {
    if (imagesInputStream == null) {
        return;
    }
    ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
    int count = 0;
    ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(imagesInputStream);
    List<String> entries = zipReader.getEntries();
    int total = entries.size();
    if (total > 0) {
        try {
            WikiPageLocalServiceUtil.getPage(node.getNodeId(), SHARED_IMAGES_TITLE);
        } catch (NoSuchPageException nspe) {
            ServiceContext serviceContext = new ServiceContext();
            serviceContext.setAddGroupPermissions(true);
            serviceContext.setAddGuestPermissions(true);
            WikiPageLocalServiceUtil.addPage(userId, node.getNodeId(), SHARED_IMAGES_TITLE, SHARED_IMAGES_CONTENT, null, true, serviceContext);
        }
    }
    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<ObjectValuePair<String, InputStream>>();
    try {
        int percentage = 50;
        for (int i = 0; i < entries.size(); i++) {
            String entry = entries.get(i);
            String key = entry;
            InputStream inputStream = zipReader.getEntryAsInputStream(entry);
            String[] paths = StringUtil.split(key, CharPool.SLASH);
            if (!isValidImage(paths, inputStream)) {
                if (_log.isInfoEnabled()) {
                    _log.info("Ignoring " + key);
                }
                continue;
            }
            String fileName = StringUtil.toLowerCase(paths[paths.length - 1]);
            ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<String, InputStream>(fileName, inputStream);
            inputStreamOVPs.add(inputStreamOVP);
            count++;
            if ((i % 5) == 0) {
                WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
                inputStreamOVPs.clear();
                percentage = Math.min(50 + (i * 50) / total, 99);
                progressTracker.setPercent(percentage);
            }
        }
        if (!inputStreamOVPs.isEmpty()) {
            WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
        }
    } finally {
        for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {
            InputStream inputStream = inputStreamOVP.getValue();
            StreamUtil.cleanUp(inputStream);
        }
    }
    zipReader.close();
    if (_log.isInfoEnabled()) {
        _log.info("Imported " + count + " images into " + node.getName());
    }
}
Also used : ProgressTracker(com.liferay.portal.kernel.util.ProgressTracker) NoSuchPageException(com.liferay.portlet.wiki.NoSuchPageException) ServiceContext(com.liferay.portal.service.ServiceContext) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ZipReader(com.liferay.portal.kernel.zip.ZipReader) ObjectValuePair(com.liferay.portal.kernel.util.ObjectValuePair)

Example 43 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class MediaWikiImporter method moveFrontPage.

protected void moveFrontPage(long userId, WikiNode node, Map<String, String[]> options) {
    String frontPageTitle = MapUtil.getString(options, WikiImporterKeys.OPTIONS_FRONT_PAGE);
    if (Validator.isNotNull(frontPageTitle)) {
        frontPageTitle = normalizeTitle(frontPageTitle);
        try {
            if (WikiPageLocalServiceUtil.getPagesCount(node.getNodeId(), frontPageTitle, true) > 0) {
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setAddGroupPermissions(true);
                serviceContext.setAddGuestPermissions(true);
                WikiPageLocalServiceUtil.movePage(userId, node.getNodeId(), frontPageTitle, WikiPageConstants.FRONT_PAGE, false, serviceContext);
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                StringBundler sb = new StringBundler(4);
                sb.append("Could not move ");
                sb.append(WikiPageConstants.FRONT_PAGE);
                sb.append(" to the title provided: ");
                sb.append(frontPageTitle);
                _log.warn(sb.toString(), e);
            }
        }
    }
}
Also used : ServiceContext(com.liferay.portal.service.ServiceContext) NoSuchPageException(com.liferay.portlet.wiki.NoSuchPageException) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DocumentException(com.liferay.portal.kernel.xml.DocumentException) IOException(java.io.IOException) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 44 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class LiferayActivityService method getActivity.

protected Activity getActivity(ThemeDisplay themeDisplay, SocialActivity socialActivity) throws Exception {
    Activity activity = null;
    String className = socialActivity.getClassName();
    if (className.equals(Activity.class.getName())) {
        activity = getExternalActivity(socialActivity);
    } else {
        activity = new ActivityImpl(String.valueOf(socialActivity.getClassPK()), String.valueOf(socialActivity.getUserId()));
        HttpServletRequest request = HttpServletRequestThreadLocal.getHttpServletRequest();
        request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
        serviceContext.setCompanyId(themeDisplay.getCompanyId());
        serviceContext.setUserId(themeDisplay.getUserId());
        SocialActivityFeedEntry socialActivityFeedEntry = SocialActivityInterpreterLocalServiceUtil.interpret(StringPool.BLANK, socialActivity, serviceContext);
        activity.setBody(socialActivityFeedEntry.getBody());
        activity.setTitle(socialActivityFeedEntry.getTitle());
        activity.setUrl(socialActivityFeedEntry.getLink());
    }
    return activity;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActivityImpl(org.apache.shindig.social.core.model.ActivityImpl) ServiceContext(com.liferay.portal.service.ServiceContext) SocialActivity(com.liferay.portlet.social.model.SocialActivity) Activity(org.apache.shindig.social.opensocial.model.Activity) SocialActivityFeedEntry(com.liferay.portlet.social.model.SocialActivityFeedEntry)

Example 45 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class LiferayMediaItemService method doUpdateMediaItem.

protected void doUpdateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    User user = UserLocalServiceUtil.getUserById(userIdLong);
    if (!ShindigUtil.isValidUser(user)) {
        return;
    }
    Group group = user.getGroup();
    long groupIdLong = group.getGroupId();
    Http.Options options = new Http.Options();
    options.setLocation(mediaItem.getUrl());
    byte[] byteArray = HttpUtil.URLtoByteArray(options);
    String fileName = getFileName(mediaItem, options);
    String contentType = MimeTypesUtil.getContentType(fileName);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAttribute("sourceFileName", fileName);
    serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(mediaItem, _MEDIA_ITEM_FIELDS, user.getCompanyId(), DLFileEntry.class.getName()));
    serviceContext.setScopeGroupId(groupIdLong);
    if (mediaItemId == null) {
        long albumIdLong = GetterUtil.getLong(albumId);
        DLAppServiceUtil.addFileEntry(groupIdLong, albumIdLong, fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, byteArray, serviceContext);
    } else {
        long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
        FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(mediaItemIdLong);
        serviceContext.setCreateDate(fileEntry.getCreateDate());
        serviceContext.setModifiedDate(fileEntry.getModifiedDate());
        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, false, byteArray, serviceContext);
    }
}
Also used : Group(com.liferay.portal.model.Group) CollectionOptions(org.apache.shindig.social.opensocial.spi.CollectionOptions) User(com.liferay.portal.model.User) ServiceContext(com.liferay.portal.service.ServiceContext) Http(com.liferay.portal.kernel.util.Http) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

ServiceContext (com.liferay.portal.service.ServiceContext)57 User (com.liferay.portal.model.User)11 PrincipalException (com.liferay.portal.security.auth.PrincipalException)11 InputStream (java.io.InputStream)11 AlbumNameException (org.liferay.jukebox.AlbumNameException)9 ArtistNameException (org.liferay.jukebox.ArtistNameException)9 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)9 SongNameException (org.liferay.jukebox.SongNameException)9 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)8 Song (org.liferay.jukebox.model.Song)8 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)7 Date (java.util.Date)7 SystemException (com.liferay.portal.kernel.exception.SystemException)6 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Artist (org.liferay.jukebox.model.Artist)5 Gadget (com.liferay.opensocial.model.Gadget)4 Folder (com.liferay.portal.kernel.repository.model.Folder)4 Element (com.liferay.portal.kernel.xml.Element)4