use of com.ableneo.liferay.portal.setup.domain.AssociatedAssetType 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();
}
Aggregations