Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil
- import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil
- import com.liferay.portal.kernel.service.ServiceContext
- def vocabularyName = "testSpeedVocabulary"
- long userId = 20156
- long groupId = 315107
- def values = [
- ];
- out.println(values.size())
- ServiceContext serviceContext = new ServiceContext()
- serviceContext.setAddGuestPermissions(true)
- def vocabulary
- try {
- vocabulary = AssetVocabularyLocalServiceUtil.addVocabulary(userId, groupId, vocabularyName, serviceContext)
- } catch (Exception e) {
- vocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, vocabularyName)
- }
- if (vocabulary == null) {
- out.println("Could not create vocabulary")
- throw new RuntimeException("Could not create vocabulary")
- }
- def counter = 0;
- values.each { item ->
- Map<Locale, String> titleMap = new HashMap<Locale, String>();
- titleMap.put(Locale.US, item)
- titleMap.put(Locale.UK, item)
- String[] categoryProps = ["value_KEY_VALUE_" + item]
- def category
- try {
- category = AssetCategoryLocalServiceUtil.addCategory(userId, groupId, 0, titleMap, titleMap, vocabulary.getVocabularyId(), categoryProps, serviceContext)
- out.println(++counter + " " + category.getName())
- } catch (Exception e) {
- out.println("Unable to create category with name " + item + " exception "+ e.getMessage())
- }
- }
Add Comment
Please, Sign In to add comment