Guest User

Untitled

a guest
Jul 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil
  2. import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil
  3. import com.liferay.portal.kernel.service.ServiceContext
  4.  
  5. def vocabularyName = "testSpeedVocabulary"
  6. long userId = 20156
  7. long groupId = 315107
  8. def values = [
  9.  
  10. ];
  11.  
  12. out.println(values.size())
  13.  
  14. ServiceContext serviceContext = new ServiceContext()
  15. serviceContext.setAddGuestPermissions(true)
  16. def vocabulary
  17. try {
  18. vocabulary = AssetVocabularyLocalServiceUtil.addVocabulary(userId, groupId, vocabularyName, serviceContext)
  19. } catch (Exception e) {
  20. vocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, vocabularyName)
  21. }
  22.  
  23. if (vocabulary == null) {
  24. out.println("Could not create vocabulary")
  25. throw new RuntimeException("Could not create vocabulary")
  26. }
  27.  
  28. def counter = 0;
  29. values.each { item ->
  30.  
  31.  
  32. Map<Locale, String> titleMap = new HashMap<Locale, String>();
  33. titleMap.put(Locale.US, item)
  34. titleMap.put(Locale.UK, item)
  35.  
  36.  
  37. String[] categoryProps = ["value_KEY_VALUE_" + item]
  38. def category
  39. try {
  40. category = AssetCategoryLocalServiceUtil.addCategory(userId, groupId, 0, titleMap, titleMap, vocabulary.getVocabularyId(), categoryProps, serviceContext)
  41. out.println(++counter + " " + category.getName())
  42. } catch (Exception e) {
  43. out.println("Unable to create category with name " + item + " exception "+ e.getMessage())
  44. }
  45. }
Add Comment
Please, Sign In to add comment