Search in sources :

Example 1 with NoSuchTagException

use of com.liferay.asset.kernel.exception.NoSuchTagException in project liferay-db-setup-core by ableneo.

the class TaggingUtil method getCategories.

public static long[] getCategories(final List<String> categories, final long groupId, final long runAsUser) {
    // The categories and tags to assign
    final long[] assetCategoryIds = new long[categories.size()];
    for (int i = 0; i < categories.size(); ++i) {
        final String name = categories.get(i);
        AssetTag assetTag = null;
        try {
            assetTag = AssetTagLocalServiceUtil.getTag(groupId, name);
        } catch (final NoSuchTagException e) {
            try {
                assetTag = AssetTagLocalServiceUtil.addTag(runAsUser, groupId, name, new ServiceContext());
            } catch (PortalException | SystemException e1) {
                LOG.error(String.format("Category %1$s not found! ", name), e1);
            }
        } catch (PortalException | SystemException e) {
            LOG.error(String.format("Category %1$s not found! ", name), e);
        }
        if (assetTag != null) {
            assetCategoryIds[i] = assetTag.getTagId();
        }
    }
    return assetCategoryIds;
}
Also used : AssetTag(com.liferay.asset.kernel.model.AssetTag) NoSuchTagException(com.liferay.asset.kernel.exception.NoSuchTagException) SystemException(com.liferay.portal.kernel.exception.SystemException) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) PortalException(com.liferay.portal.kernel.exception.PortalException)

Aggregations

NoSuchTagException (com.liferay.asset.kernel.exception.NoSuchTagException)1 AssetTag (com.liferay.asset.kernel.model.AssetTag)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1