001
014
015 package com.liferay.portlet.asset.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.search.Document;
019 import com.liferay.portal.kernel.search.Field;
020 import com.liferay.portal.kernel.search.Hits;
021 import com.liferay.portal.kernel.search.Indexer;
022 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
023 import com.liferay.portal.kernel.util.GetterUtil;
024 import com.liferay.portlet.asset.model.AssetVocabulary;
025 import com.liferay.portlet.asset.service.AssetVocabularyLocalServiceUtil;
026
027 import java.util.ArrayList;
028 import java.util.List;
029
030
033 public class AssetVocabularyUtil {
034
035 public static List<AssetVocabulary> getVocabularies(Hits hits)
036 throws PortalException {
037
038 List<Document> documents = hits.toList();
039
040 List<AssetVocabulary> vocabularies = new ArrayList<AssetVocabulary>(
041 documents.size());
042
043 for (Document document : documents) {
044 long vocabularyId = GetterUtil.getLong(
045 document.get(Field.ASSET_VOCABULARY_ID));
046
047 AssetVocabulary vocabulary =
048 AssetVocabularyLocalServiceUtil.getVocabulary(vocabularyId);
049
050 if (vocabulary == null) {
051 vocabularies = null;
052
053 Indexer indexer = IndexerRegistryUtil.getIndexer(
054 AssetVocabulary.class);
055
056 long companyId = GetterUtil.getLong(
057 document.get(Field.COMPANY_ID));
058
059 indexer.delete(companyId, document.getUID());
060 }
061 else if (vocabularies != null) {
062 vocabularies.add(vocabulary);
063 }
064 }
065
066 return vocabularies;
067 }
068
069 }