Search in sources :

Example 1 with SystemException

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

the class RosterMemberLocalServiceBaseImpl method runSQL.

/**
 * Performs a SQL query.
 *
 * @param sql the sql query
 */
protected void runSQL(String sql) {
    try {
        DataSource dataSource = rosterMemberPersistence.getDataSource();
        DB db = DBManagerUtil.getDB();
        sql = db.buildSQL(sql);
        sql = PortalUtil.transformSQL(sql);
        SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql);
        sqlUpdate.update();
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) SqlUpdate(com.liferay.portal.kernel.dao.jdbc.SqlUpdate) DB(com.liferay.portal.kernel.dao.db.DB) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DataSource(javax.sql.DataSource)

Example 2 with SystemException

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

the class RosterMemberServiceBaseImpl method runSQL.

/**
 * Performs a SQL query.
 *
 * @param sql the sql query
 */
protected void runSQL(String sql) {
    try {
        DataSource dataSource = rosterMemberPersistence.getDataSource();
        DB db = DBManagerUtil.getDB();
        sql = db.buildSQL(sql);
        sql = PortalUtil.transformSQL(sql);
        SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql);
        sqlUpdate.update();
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) SqlUpdate(com.liferay.portal.kernel.dao.jdbc.SqlUpdate) DB(com.liferay.portal.kernel.dao.db.DB) SystemException(com.liferay.portal.kernel.exception.SystemException) DataSource(javax.sql.DataSource)

Example 3 with SystemException

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

the class KBArticleImporter method addKBArticleMarkdown.

protected KBArticle addKBArticleMarkdown(long userId, long groupId, long parentKBFolderId, long parentResourceClassNameId, long parentResourcePrimaryKey, String markdown, String fileEntryName, ZipReader zipReader, Map<String, String> metadata, PrioritizationStrategy prioritizationStrategy, ServiceContext serviceContext) throws KBArticleImportException, SystemException {
    if (Validator.isNull(markdown)) {
        throw new KBArticleImportException("Markdown is null for file entry " + fileEntryName);
    }
    KBArticleMarkdownConverter kbArticleMarkdownConverter = new KBArticleMarkdownConverter(markdown, fileEntryName, metadata);
    String urlTitle = kbArticleMarkdownConverter.getUrlTitle();
    KBArticle kbArticle = KBArticleLocalServiceUtil.fetchKBArticleByUrlTitle(groupId, parentKBFolderId, urlTitle);
    boolean newKBArticle = false;
    if (kbArticle == null) {
        newKBArticle = true;
    }
    try {
        if (kbArticle == null) {
            int workflowAction = serviceContext.getWorkflowAction();
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
            kbArticle = KBArticleLocalServiceUtil.addKBArticle(userId, parentResourceClassNameId, parentResourcePrimaryKey, kbArticleMarkdownConverter.getTitle(), urlTitle, markdown, null, kbArticleMarkdownConverter.getSourceURL(), null, null, serviceContext);
            serviceContext.setWorkflowAction(workflowAction);
        }
    } catch (Exception e) {
        StringBundler sb = new StringBundler(4);
        sb.append("Unable to add basic KB article for file entry ");
        sb.append(fileEntryName);
        sb.append(": ");
        sb.append(e.getLocalizedMessage());
        throw new KBArticleImportException(sb.toString(), e);
    }
    try {
        String html = kbArticleMarkdownConverter.processAttachmentsReferences(userId, kbArticle, zipReader, new HashMap<String, FileEntry>());
        kbArticle = KBArticleLocalServiceUtil.updateKBArticle(userId, kbArticle.getResourcePrimKey(), kbArticleMarkdownConverter.getTitle(), html, kbArticle.getDescription(), kbArticleMarkdownConverter.getSourceURL(), null, null, null, serviceContext);
        if (newKBArticle) {
            prioritizationStrategy.addKBArticle(kbArticle, fileEntryName);
        } else {
            prioritizationStrategy.updateKBArticle(kbArticle, fileEntryName);
        }
        return kbArticle;
    } catch (Exception e) {
        StringBundler sb = new StringBundler(4);
        sb.append("Unable to update KB article for file entry ");
        sb.append(fileEntryName);
        sb.append(": ");
        sb.append(e.getLocalizedMessage());
        throw new KBArticleImportException(sb.toString(), e);
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBArticleMarkdownConverter(com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 4 with SystemException

use of com.liferay.portal.kernel.exception.SystemException 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 5 with SystemException

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

the class AlbumPersistenceImpl method filterFindByG_LikeN_S.

/**
 * Returns an ordered range of all the albums that the user has permissions to view where groupId = &#63; and name LIKE &#63; and status = &#63;.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.liferay.jukebox.model.impl.AlbumModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param name the name
 * @param status the status
 * @param start the lower bound of the range of albums
 * @param end the upper bound of the range of albums (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching albums that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Album> filterFindByG_LikeN_S(long groupId, String name, int status, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_LikeN_S(groupId, name, status, start, end, orderByComparator);
    }
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(5 + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(5);
    }
    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_ALBUM_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_ALBUM_NO_INLINE_DISTINCT_WHERE_1);
    }
    query.append(_FINDER_COLUMN_G_LIKEN_S_GROUPID_2);
    boolean bindName = false;
    if (name == null) {
        query.append(_FINDER_COLUMN_G_LIKEN_S_NAME_1);
    } else if (name.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_LIKEN_S_NAME_3);
    } else {
        bindName = true;
        query.append(_FINDER_COLUMN_G_LIKEN_S_NAME_2);
    }
    query.append(_FINDER_COLUMN_G_LIKEN_S_STATUS_2);
    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_ALBUM_NO_INLINE_DISTINCT_WHERE_2);
    }
    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(AlbumModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(AlbumModelImpl.ORDER_BY_SQL);
        }
    }
    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Album.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
    Session session = null;
    try {
        session = openSession();
        SQLQuery q = session.createSQLQuery(sql);
        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, AlbumImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, AlbumImpl.class);
        }
        QueryPos qPos = QueryPos.getInstance(q);
        qPos.add(groupId);
        if (bindName) {
            qPos.add(name.toLowerCase());
        }
        qPos.add(status);
        return (List<Album>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Album(org.liferay.jukebox.model.Album) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchAlbumException(org.liferay.jukebox.NoSuchAlbumException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

SystemException (com.liferay.portal.kernel.exception.SystemException)571 Session (com.liferay.portal.kernel.dao.orm.Session)509 StringBundler (com.liferay.portal.kernel.util.StringBundler)336 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)324 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)312 Query (com.liferay.portal.kernel.dao.orm.Query)252 NoSuchArticleException (com.liferay.knowledgebase.NoSuchArticleException)194 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)191 ArrayList (java.util.ArrayList)175 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)173 List (java.util.List)173 KBArticle (com.liferay.knowledgebase.model.KBArticle)147 NoSuchSongException (org.liferay.jukebox.NoSuchSongException)58 NoSuchAlbumException (org.liferay.jukebox.NoSuchAlbumException)53 KBArticleImpl (com.liferay.knowledgebase.model.impl.KBArticleImpl)46 NoSuchArtistException (org.liferay.jukebox.NoSuchArtistException)44 Song (org.liferay.jukebox.model.Song)44 PortalException (com.liferay.portal.kernel.exception.PortalException)43 Album (org.liferay.jukebox.model.Album)42 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)34