Search in sources :

Example 1 with PortalException

use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.

the class KBArticleMarkdownConverter method processAttachmentsReferences.

public String processAttachmentsReferences(long userId, KBArticle kbArticle, ZipReader zipReader, Map<String, FileEntry> fileEntriesMap) throws PortalException, SystemException {
    Set<Integer> indexes = new TreeSet<Integer>();
    int index = 0;
    while ((index = _html.indexOf("<img", index)) > -1) {
        indexes.add(index);
        index += 4;
    }
    if (indexes.isEmpty()) {
        return _html;
    }
    StringBundler sb = new StringBundler();
    int previousIndex = 0;
    for (int curIndex : indexes) {
        if (curIndex < 0) {
            break;
        }
        if (curIndex > previousIndex) {
            // Append text from previous position up to image tag
            String text = _html.substring(previousIndex, curIndex);
            sb.append(text);
        }
        int pos = _html.indexOf("/>", curIndex);
        if (pos < 0) {
            if (_log.isDebugEnabled()) {
                _log.debug("Expected close tag for image " + _html.substring(curIndex));
            }
            sb.append(_html.substring(curIndex));
            previousIndex = curIndex;
            break;
        }
        String text = _html.substring(curIndex, pos);
        String imageFileName = KBArticleImporterUtil.extractImageFileName(text);
        FileEntry imageFileEntry = KBArticleImporterUtil.addImageFileEntry(imageFileName, userId, kbArticle, zipReader, fileEntriesMap);
        if (imageFileEntry == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find image source " + text);
            }
            sb.append("<img alt=\"missing image\" src=\"\" ");
        } else {
            String imageSrc = StringPool.BLANK;
            try {
                imageSrc = DLUtil.getPreviewURL(imageFileEntry, imageFileEntry.getFileVersion(), null, StringPool.BLANK);
            } catch (PortalException pe) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to obtain image URL from file entry " + imageFileEntry.getFileEntryId());
                }
            }
            sb.append("<img alt=\"");
            sb.append(HtmlUtil.escapeAttribute(imageFileEntry.getTitle()));
            sb.append("\" src=\"");
            sb.append(imageSrc);
            sb.append("\" ");
        }
        previousIndex = pos;
    }
    if (previousIndex < _html.length()) {
        sb.append(_html.substring(previousIndex));
    }
    return sb.toString();
}
Also used : TreeSet(java.util.TreeSet) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 2 with PortalException

use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.

the class ClpSerializer method translateThrowable.

public static Throwable translateThrowable(Throwable throwable) {
    if (_useReflectionToTranslateThrowable) {
        try {
            UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);
            objectOutputStream.writeObject(throwable);
            objectOutputStream.flush();
            objectOutputStream.close();
            UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size());
            Thread currentThread = Thread.currentThread();
            ClassLoader contextClassLoader = currentThread.getContextClassLoader();
            ObjectInputStream objectInputStream = new ClassLoaderObjectInputStream(unsyncByteArrayInputStream, contextClassLoader);
            throwable = (Throwable) objectInputStream.readObject();
            objectInputStream.close();
            return throwable;
        } catch (SecurityException se) {
            if (_log.isInfoEnabled()) {
                _log.info("Do not use reflection to translate throwable");
            }
            _useReflectionToTranslateThrowable = false;
        } catch (Throwable throwable2) {
            _log.error(throwable2, throwable2);
            return throwable2;
        }
    }
    Class<?> clazz = throwable.getClass();
    String className = clazz.getName();
    if (className.equals(PortalException.class.getName())) {
        return new PortalException();
    }
    if (className.equals(SystemException.class.getName())) {
        return new SystemException();
    }
    if (className.equals("com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException")) {
        return new com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.DuplicateKBFolderNameException")) {
        return new com.liferay.knowledgebase.DuplicateKBFolderNameException();
    }
    if (className.equals("com.liferay.knowledgebase.InvalidKBArticleUrlTitleException")) {
        return new com.liferay.knowledgebase.InvalidKBArticleUrlTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.InvalidKBFolderNameException")) {
        return new com.liferay.knowledgebase.InvalidKBFolderNameException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleContentException")) {
        return new com.liferay.knowledgebase.KBArticleContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleImportException")) {
        return new com.liferay.knowledgebase.KBArticleImportException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleParentException")) {
        return new com.liferay.knowledgebase.KBArticleParentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticlePriorityException")) {
        return new com.liferay.knowledgebase.KBArticlePriorityException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleSourceURLException")) {
        return new com.liferay.knowledgebase.KBArticleSourceURLException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleTitleException")) {
        return new com.liferay.knowledgebase.KBArticleTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.KBCommentContentException")) {
        return new com.liferay.knowledgebase.KBCommentContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBTemplateContentException")) {
        return new com.liferay.knowledgebase.KBTemplateContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBTemplateTitleException")) {
        return new com.liferay.knowledgebase.KBTemplateTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchKBArticleSelectorException")) {
        return new com.liferay.knowledgebase.NoSuchKBArticleSelectorException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchArticleException")) {
        return new com.liferay.knowledgebase.NoSuchArticleException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchCommentException")) {
        return new com.liferay.knowledgebase.NoSuchCommentException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchFolderException")) {
        return new com.liferay.knowledgebase.NoSuchFolderException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchTemplateException")) {
        return new com.liferay.knowledgebase.NoSuchTemplateException();
    }
    return throwable;
}
Also used : UnsyncByteArrayOutputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream) ObjectOutputStream(java.io.ObjectOutputStream) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)

Example 3 with PortalException

use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.

the class ArtistLocalServiceImpl method updateArtist.

@Indexable(type = IndexableType.REINDEX)
public Artist updateArtist(long userId, long artistId, String name, String bio, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    // Event
    User user = userPersistence.findByPrimaryKey(userId);
    validate(name);
    Artist artist = artistPersistence.findByPrimaryKey(artistId);
    artist.setModifiedDate(serviceContext.getModifiedDate(null));
    artist.setName(name);
    artist.setBio(bio);
    artist.setExpandoBridgeAttributes(serviceContext);
    artistPersistence.update(artist);
    if (inputStream != null) {
        Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
        if (repository != null) {
            try {
                PortletFileRepositoryUtil.deletePortletFileEntry(repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(artist.getArtistId()));
            } catch (Exception e) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Cannot delete artist image");
                }
            }
        }
        PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Artist.class.getName(), artist.getArtistId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(artist.getArtistId()), StringPool.BLANK, true);
    }
    // Asset
    updateAsset(userId, artist, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return artist;
}
Also used : Artist(org.liferay.jukebox.model.Artist) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) ArtistNameException(org.liferay.jukebox.ArtistNameException) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 4 with PortalException

use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.

the class ArtistLocalServiceImpl method deleteArtist.

@Indexable(type = IndexableType.DELETE)
public Artist deleteArtist(long artistId) throws PortalException, SystemException {
    Artist artist = artistPersistence.findByPrimaryKey(artistId);
    List<Album> albums = albumLocalService.getAlbumsByArtistId(artistId);
    for (Album album : albums) {
        albumLocalService.deleteAlbum(album.getAlbumId());
    }
    try {
        PortletFileRepositoryUtil.deletePortletFileEntry(artist.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(artistId));
    } catch (Exception e) {
    }
    return artistPersistence.remove(artistId);
}
Also used : Artist(org.liferay.jukebox.model.Artist) Album(org.liferay.jukebox.model.Album) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) ArtistNameException(org.liferay.jukebox.ArtistNameException) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 5 with PortalException

use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.

the class LegacyAPIsAntPortlet method doView.

@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    try {
        long groupId = PortalUtil.getScopeGroupId(renderRequest);
        int count = JournalArticleLocalServiceUtil.getArticlesCount(groupId);
        renderRequest.setAttribute("groupJournalArticlesCount", count);
        JournalArticleLocalService service = JournalArticleLocalServiceUtil.getService();
        int journalArticlesCount = service.getJournalArticlesCount();
        renderRequest.setAttribute("journalArticlesCount", journalArticlesCount);
    } catch (PortalException | SystemException e) {
        e.printStackTrace();
    }
    super.doView(renderRequest, renderResponse);
}
Also used : JournalArticleLocalService(com.liferay.portlet.journal.service.JournalArticleLocalService) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException)

Aggregations

PortalException (com.liferay.portal.kernel.exception.PortalException)40 SystemException (com.liferay.portal.kernel.exception.SystemException)25 User (com.liferay.portal.model.User)10 IOException (java.io.IOException)10 User (com.liferay.portal.kernel.model.User)9 Indexable (com.liferay.portal.kernel.search.Indexable)5 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)4 PrincipalException (com.liferay.portal.security.auth.PrincipalException)4 CompanyMaxUsersException (com.liferay.portal.CompanyMaxUsersException)3 ContactBirthdayException (com.liferay.portal.ContactBirthdayException)3 ContactFirstNameException (com.liferay.portal.ContactFirstNameException)3 ContactFullNameException (com.liferay.portal.ContactFullNameException)3 ContactLastNameException (com.liferay.portal.ContactLastNameException)3 DuplicateOpenIdException (com.liferay.portal.DuplicateOpenIdException)3 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)3 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)3 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)3 ModelListenerException (com.liferay.portal.ModelListenerException)3 NoSuchImageException (com.liferay.portal.NoSuchImageException)3 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)3