Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3554e50

Browse files
committed
Vocabularies and Categories now has specific name and title map configuration.
1 parent bc828d6 commit 3554e50

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCategorization.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
import com.liferay.portal.kernel.service.ClassNameLocalServiceUtil;
3939
import com.liferay.portal.kernel.service.ServiceContext;
4040
import com.liferay.portal.kernel.util.ArrayUtil;
41+
import com.liferay.portal.kernel.util.LocalizationUtil;
4142
import com.liferay.portal.kernel.util.PortalUtil;
4243
import com.liferay.portlet.asset.util.AssetVocabularySettingsHelper;
4344
import com.mimacom.liferay.portal.setup.LiferaySetup;
4445
import com.mimacom.liferay.portal.setup.core.util.ResolverUtil;
46+
import com.mimacom.liferay.portal.setup.core.util.TitleMapUtil;
4547
import com.mimacom.liferay.portal.setup.domain.AssociatedAssetType;
4648
import com.mimacom.liferay.portal.setup.domain.Category;
4749
import com.mimacom.liferay.portal.setup.domain.Site;
@@ -83,25 +85,24 @@ public static void setupVocabularies(final Site site, final long groupId)
8385

8486
private static void setupVocabulary(final Vocabulary vocabulary, final Site site, final long groupId, final Locale defaultLocale) {
8587

86-
LOG.info("Setting up vocabulary with title: " + vocabulary.getTitle());
88+
LOG.info("Setting up vocabulary with name: " + vocabulary.getName());
8789

88-
Map<Locale, String> titleMap = new HashMap<>();
89-
String title = vocabulary.getTitle();
90-
titleMap.put(defaultLocale, title);
90+
Map<Locale, String> titleMap = TitleMapUtil.getTitleMap(vocabulary.getTitleTranslation(), groupId, vocabulary.getName(), "");
9191

9292
Map<Locale, String> descMap = new HashMap<>();
9393
descMap.put(defaultLocale, vocabulary.getDescription());
9494

9595
AssetVocabulary assetVocabulary = null;
9696
try {
97-
assetVocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, title);
97+
assetVocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, vocabulary.getName());
9898
} catch (PortalException | SystemException e) {
9999
LOG.error("Asset vocabulary was not found");
100100
}
101101

102102
if (assetVocabulary != null) {
103103
LOG.debug("Vocabulary already exists. Will be updated.");
104104

105+
assetVocabulary.setName(vocabulary.getName());
105106
assetVocabulary.setTitleMap(titleMap);
106107
assetVocabulary.setDescriptionMap(descMap);
107108
assetVocabulary.setSettings(composeVocabularySettings(vocabulary, groupId));
@@ -189,7 +190,7 @@ private static String composeVocabularySettings(Vocabulary vocabulary, final lon
189190

190191
assetVocabularySettingsHelper.setClassNameIdsAndClassTypePKs(ArrayUtil.toLongArray(classNameIds), ArrayUtil.toLongArray(classTypePKs), requiredsArray);
191192
if (LOG.isDebugEnabled()) {
192-
LOG.debug("Vocabulary settings composed for vocabulary:" + vocabulary.getTitle() + ". Content: " + assetVocabularySettingsHelper.toString());
193+
LOG.debug("Vocabulary settings composed for vocabulary:" + vocabulary.getName() + ". Content: " + assetVocabularySettingsHelper.toString());
193194
}
194195

195196
return assetVocabularySettingsHelper.toString();
@@ -209,12 +210,10 @@ private static void setupCategories(final long vocabularyId, final long groupId,
209210
private static void setupCategory(final Category category, final long vocabularyId,
210211
final long groupId, final Locale defaultLocale, final long parentCategoryId) {
211212

212-
LOG.info("Setting up category with title:" + category.getTitle());
213-
214-
Map<Locale, String> titleMap = new HashMap<>();
215-
String title = category.getTitle();
216-
titleMap.put(defaultLocale, title);
213+
LOG.info("Setting up category with name:" + category.getName());
217214

215+
Map<Locale, String> titleMap = TitleMapUtil.getTitleMap(category.getTitleTranslation(), groupId, category.getName(),
216+
"Category with name: " + category.getName());
218217
Map<Locale, String> descMap = new HashMap<>();
219218
String description = category.getDescription();
220219
descMap.put(defaultLocale, description);
@@ -230,20 +229,20 @@ private static void setupCategory(final Category category, final long vocabulary
230229
List<AssetCategory> existingCategories = AssetCategoryLocalServiceUtil
231230
.getChildCategories(parentCategoryId);
232231
for (AssetCategory ac : existingCategories) {
233-
if (ac.getName().equals(category.getTitle())) {
232+
if (ac.getName().equals(category.getName())) {
234233
assetCategory = ac;
235234
}
236235
}
237236
} catch (SystemException e) {
238-
LOG.error("Error while trying to find category with name: " + category.getTitle(), e);
237+
LOG.error("Error while trying to find category with name: " + category.getName(), e);
239238
}
240239

241240
if (assetCategory != null) {
242241
LOG.error("Asset category already exists for parent category. Updating...");
243242

244243
assetCategory.setTitleMap(titleMap);
245244
assetCategory.setDescriptionMap(descMap);
246-
assetCategory.setName(title);
245+
assetCategory.setName(category.getName());
247246

248247
try {
249248
AssetCategoryLocalServiceUtil.updateAssetCategory(assetCategory);
@@ -267,7 +266,7 @@ private static void setupCategory(final Category category, final long vocabulary
267266
category.getCategory(), defaultLocale);
268267

269268
} catch (PortalException | SystemException e) {
270-
LOG.error("Error in creating category with title: " + category.getTitle(), e);
269+
LOG.error("Error in creating category with name: " + category.getName(), e);
271270
}
272271

273272
}

db-setup-core/src/main/resources/setup_definition-1.0.xsd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,11 @@
737737
<xs:element name="vocabulary">
738738
<xs:complexType>
739739
<xs:sequence>
740+
<xs:element ref="title-translation" minOccurs="0" maxOccurs="unbounded"/>
740741
<xs:element ref="associated-asset-type" minOccurs="0" maxOccurs="unbounded" />
741742
<xs:element minOccurs="0" maxOccurs="unbounded" ref="category"/>
742743
</xs:sequence>
743-
<xs:attribute name="title" use="required" type="xs:string"/>
744+
<xs:attribute name="name" use="required" type="xs:string"/>
744745
<xs:attribute name="description" type="xs:string" default=""/>
745746
<xs:attribute name="multi-valued" type="xs:boolean" default="true"/>
746747
</xs:complexType>
@@ -871,9 +872,10 @@
871872
<xs:element name="category">
872873
<xs:complexType>
873874
<xs:sequence>
875+
<xs:element ref="title-translation" minOccurs="0" maxOccurs="unbounded"/>
874876
<xs:element minOccurs="0" maxOccurs="unbounded" ref="category"/>
875877
</xs:sequence>
876-
<xs:attribute name="title" use="required" type="xs:string"/>
878+
<xs:attribute name="name" use="required" type="xs:string"/>
877879
<xs:attribute name="description" type="xs:string" default=""/>
878880
</xs:complexType>
879881
</xs:element>

0 commit comments

Comments
 (0)