<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>list of Vocabularies and Categories</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=96828403" />
  <subtitle>list of Vocabularies and Categories</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=96828403</id>
  <updated>2026-06-12T02:33:06Z</updated>
  <dc:date>2026-06-12T02:33:06Z</dc:date>
  <entry>
    <title>RE: list of Vocabularies and Categories</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97082283" />
    <author>
      <name>Olga S</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97082283</id>
    <updated>2017-10-16T23:23:42Z</updated>
    <published>2017-10-16T23:23:42Z</published>
    <summary type="html">Hello Danielle!&lt;br /&gt;Thanks,&lt;br /&gt;it worked!</summary>
    <dc:creator>Olga S</dc:creator>
    <dc:date>2017-10-16T23:23:42Z</dc:date>
  </entry>
  <entry>
    <title>RE: list of Vocabularies and Categories</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96950433" />
    <author>
      <name>Danielle Ardon</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96950433</id>
    <updated>2017-10-14T14:58:55Z</updated>
    <published>2017-10-14T14:58:55Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Ahh well the group in this case means the site, so if you created the vocabulary for a specific site, you should use the groupId for that site.&lt;br&gt;But if you created the vocabulary in the global site/scope then you need the global group Id. You can get this global group Id in several ways.&lt;br&gt;If you have acces to a request object you can get it via the theme display:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute( WebKeys.THEME_DISPLAY);
And then themeDisplay.getCompany.getGroupId();&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Or if you don't have access to the request object:&lt;br&gt;&lt;pre&gt;&lt;code&gt;Override
    public Company getDefaultCompany() {
        Company defaultCompany = null;
        String webId = PropsUtil.get("company.default.web.id");
        try {
            defaultCompany = companyService.getCompanyByWebId(webId);
        } catch (PortalException e) {
            LOG.error(String.format("Error while retrieving default company, error is %s", e.getMessage()));
        }
        return defaultCompany;
    }

    @Override
    public long getGlobalGroupId() {
        Company defaultCompany = getDefaultCompany();
        long groupId = 0;
        try {
            groupId = defaultCompany.getGroupId();
        } catch (PortalException e) {
            LOG.error("Error while retrieving global groupId", e);
        }
        return groupId;
    }&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Danielle Ardon</dc:creator>
    <dc:date>2017-10-14T14:58:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: list of Vocabularies and Categories</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96885743" />
    <author>
      <name>Olga S</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96885743</id>
    <updated>2017-10-13T17:20:21Z</updated>
    <published>2017-10-13T17:20:21Z</published>
    <summary type="html">Hello Danielle!&lt;br /&gt;Thanks so much for your reply!&lt;br /&gt;I will try this code.&lt;br /&gt;I am still confused about one thing.&lt;br /&gt;All Vocabularies are retrieved based on some group, however I created my vocabularies and categories out of group context(I did&amp;#39;n assign any vocab to any group explicitly). Which group do I need to use in getGroupVocabularies() to retrieve vocabs?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks!</summary>
    <dc:creator>Olga S</dc:creator>
    <dc:date>2017-10-13T17:20:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: list of Vocabularies and Categories</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96844276" />
    <author>
      <name>Danielle Ardon</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96844276</id>
    <updated>2017-10-13T09:09:39Z</updated>
    <published>2017-10-13T09:09:39Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Olga,&lt;br&gt;&lt;br&gt;So if I understand correctly you need to be able to retrieve all the categories from a vocabulary by name?&lt;br&gt;So lets say you have a vocabulary "Animals" and you want all the animal categories in that to display in a dropdown?&lt;br&gt;&lt;br&gt;Liferay 7.0 (and 6.2 too) has a method already that allows you to search for a vocabulary by name: &lt;br&gt;https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/asset/kernel/service/AssetVocabularyLocalService.html&lt;br&gt;(In 7.0 you should just use the localservice instead of the util classes).&lt;br&gt;&lt;br&gt;So that would be something like:&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(immediate = true, service = CategoryRetriever.class)
public class CategoryRetrieverImpl implements CategoryRetriever {

	private static final Log LOG = LogFactoryUtil.getLog(CategoryRetrieverImpl.class);

	@Reference
	private AssetCategoryLocalService assetCategoryService;

	@Reference
	private AssetVocabularyLocalService assetVocabularyLocalService;

    @Reference
    private DefaultValue defaultValue;
    AssetCategory assetCategory;
    
	@Override
	public List&amp;lt;assetcategories&amp;gt; getCategories( String vocabularyName, long groupId) {
		List&amp;lt;assetcategory&amp;gt; assetCategories = new ArrayList&amp;amp;lt;&amp;amp;gt;();
		try {
			AssetVocabulary vocabulary = assetVocabularyLocalService.getGroupVocabulary(groupId,
					vocabularyName);
			if(Validator.isNotNull(vocabulary)){
                        assetCategories =  vocabulary.getCategories();
                  }
		catch (PortalException e) {
			LOG.error(String.format("Retrieving vocabulary %s failed",vocabularyName),e);
		}
 return assetCategories;
}&amp;lt;/assetcategory&amp;gt;&amp;lt;/assetcategories&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;I don't really see a reason to use dynamicquery for something that is already a standard api method. If you need to search categories by name then you can still use dynamicquery, it is still supported in 7.0.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Danielle Ardon</dc:creator>
    <dc:date>2017-10-13T09:09:39Z</dc:date>
  </entry>
  <entry>
    <title>list of Vocabularies and Categories</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96828402" />
    <author>
      <name>Olga S</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96828402</id>
    <updated>2017-10-12T22:10:18Z</updated>
    <published>2017-10-12T22:10:18Z</published>
    <summary type="html">Hello!&lt;br /&gt;I need to get the list of Vocabularies and categories which belong to those vocabularies in my Portlet (I need to display them in drop down). &lt;br /&gt;Is there a neat way to do that? &lt;br /&gt;I tried solution for 6.2 (I am using Liferay 7) but it&amp;#39;s not working  https://www.kerstner.at/2012/11/search-categories-by-name-or-vocabulary-in-liferay-6/&lt;br /&gt;&lt;br /&gt;Thanks!</summary>
    <dc:creator>Olga S</dc:creator>
    <dc:date>2017-10-12T22:10:18Z</dc:date>
  </entry>
</feed>
