Search in sources :

Example 1 with AssetVocabularySettingsHelper

use of com.liferay.portlet.asset.util.AssetVocabularySettingsHelper in project liferay-db-setup-core by ableneo.

the class SetupCategorization method composeVocabularySettings.

private static String composeVocabularySettings(Vocabulary vocabulary, final long groupId) {
    // class copied into the bundle from com.liferay.portal.impl bundle with maven shade plugin
    AssetVocabularySettingsHelper assetVocabularySettingsHelper = new AssetVocabularySettingsHelper();
    assetVocabularySettingsHelper.setMultiValued(vocabulary.isMultiValued());
    List<AssociatedAssetType> types = vocabulary.getAssociatedAssetType();
    if (Objects.isNull(types) || types.isEmpty()) {
        assetVocabularySettingsHelper.setClassNameIdsAndClassTypePKs(new long[] { AssetCategoryConstants.ALL_CLASS_NAME_ID }, new long[] { AssetCategoryConstants.ALL_CLASS_TYPE_PK }, new boolean[] { false });
        return assetVocabularySettingsHelper.toString();
    }
    List<Long> classNameIds = new LinkedList<>();
    List<Long> classTypePKs = new LinkedList<>();
    List<Boolean> requireds = new LinkedList<>();
    for (AssociatedAssetType type : types) {
        ClassName className = ClassNameLocalServiceUtil.fetchClassName(type.getClassName());
        if (className.getValue().isEmpty()) {
            continue;
        }
        long subtypePK = -1;
        if (Objects.nonNull(type.getSubtypeStructureKey()) && !type.getSubtypeStructureKey().isEmpty()) {
            // has subtype
            try {
                subtypePK = ResolverUtil.getStructureId(type.getSubtypeStructureKey(), groupId, type.getClassName(), true);
            } catch (PortalException e) {
                LOG.error("Class can not be be resolved for classname: {}", type.getClassName(), e);
                continue;
            }
        }
        classNameIds.add(className.getClassNameId());
        classTypePKs.add(subtypePK);
        requireds.add(type.isRequired());
    }
    // no valid associated types case
    if (classNameIds.isEmpty()) {
        assetVocabularySettingsHelper.setClassNameIdsAndClassTypePKs(new long[] { AssetCategoryConstants.ALL_CLASS_NAME_ID }, new long[] { AssetCategoryConstants.ALL_CLASS_TYPE_PK }, new boolean[] { false });
        return assetVocabularySettingsHelper.toString();
    }
    // when associated types exists
    boolean[] requiredsArray = new boolean[requireds.size()];
    for (int i = 0; i < requireds.size(); i++) {
        requiredsArray[i] = requireds.get(i);
    }
    assetVocabularySettingsHelper.setClassNameIdsAndClassTypePKs(ArrayUtil.toLongArray(classNameIds), ArrayUtil.toLongArray(classTypePKs), requiredsArray);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Vocabulary settings composed for vocabulary: [{}]. Content: {}", vocabulary.getName(), assetVocabularySettingsHelper);
    }
    return assetVocabularySettingsHelper.toString();
}
Also used : LinkedList(java.util.LinkedList) AssociatedAssetType(com.ableneo.liferay.portal.setup.domain.AssociatedAssetType) ClassName(com.liferay.portal.kernel.model.ClassName) PortalException(com.liferay.portal.kernel.exception.PortalException) AssetVocabularySettingsHelper(com.liferay.portlet.asset.util.AssetVocabularySettingsHelper)

Aggregations

AssociatedAssetType (com.ableneo.liferay.portal.setup.domain.AssociatedAssetType)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 ClassName (com.liferay.portal.kernel.model.ClassName)1 AssetVocabularySettingsHelper (com.liferay.portlet.asset.util.AssetVocabularySettingsHelper)1 LinkedList (java.util.LinkedList)1