protected void importAssetVocabulary( PortletDataContext portletDataContext, Map<Long, Long> assetVocabularyPKs, Element assetVocabularyElement, AssetVocabulary assetVocabulary) throws Exception { long userId = portletDataContext.getUserId(assetVocabulary.getUserUuid()); long groupId = portletDataContext.getScopeGroupId(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setCreateDate(assetVocabulary.getCreateDate()); serviceContext.setModifiedDate(assetVocabulary.getModifiedDate()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); AssetVocabulary importedAssetVocabulary = null; AssetVocabulary existingAssetVocabulary = AssetVocabularyUtil.fetchByG_N(groupId, assetVocabulary.getName()); if (existingAssetVocabulary == null) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); existingAssetVocabulary = AssetVocabularyUtil.fetchByG_N(companyGroup.getGroupId(), assetVocabulary.getName()); } if (existingAssetVocabulary == null) { serviceContext.setUuid(assetVocabulary.getUuid()); importedAssetVocabulary = AssetVocabularyLocalServiceUtil.addVocabulary( userId, assetVocabulary.getTitle(), getAssetVocabularyTitleMap(assetVocabulary), assetVocabulary.getDescriptionMap(), assetVocabulary.getSettings(), serviceContext); } else { importedAssetVocabulary = AssetVocabularyLocalServiceUtil.updateVocabulary( existingAssetVocabulary.getVocabularyId(), assetVocabulary.getTitle(), getAssetVocabularyTitleMap(assetVocabulary), assetVocabulary.getDescriptionMap(), assetVocabulary.getSettings(), serviceContext); } assetVocabularyPKs.put( assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId()); portletDataContext.importPermissions( AssetVocabulary.class, assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId()); }
@Indexable(type = IndexableType.REINDEX) @Override public AssetVocabulary updateVocabulary( long vocabularyId, String title, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String settings, ServiceContext serviceContext) throws PortalException { String name = titleMap.get(LocaleUtil.getSiteDefault()); AssetVocabulary vocabulary = assetVocabularyPersistence.findByPrimaryKey(vocabularyId); if (!vocabulary.getName().equals(name)) { validate(vocabulary.getGroupId(), name); } vocabulary.setName(name); vocabulary.setTitleMap(titleMap); if (Validator.isNotNull(title)) { vocabulary.setTitle(title); } vocabulary.setDescriptionMap(descriptionMap); vocabulary.setSettings(settings); assetVocabularyPersistence.update(vocabulary); return vocabulary; }
@Override public int compareTo(AssetVocabulary assetVocabulary) { int value = 0; value = getName().compareTo(assetVocabulary.getName()); if (value != 0) { return value; } return 0; }
protected Map<Locale, String> getAssetVocabularyTitleMap(AssetVocabulary assetVocabulary) { Map<Locale, String> titleMap = assetVocabulary.getTitleMap(); if (titleMap == null) { titleMap = new HashMap<Locale, String>(); } Locale locale = LocaleUtil.getDefault(); String title = titleMap.get(locale); if (Validator.isNull(title)) { titleMap.put(locale, assetVocabulary.getName()); } return titleMap; }
protected JSONArray toJSONArray(List<AssetCategory> categories) throws PortalException, SystemException { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (AssetCategory category : categories) { String categoryJSON = JSONFactoryUtil.looseSerialize(category); JSONObject categoryJSONObject = JSONFactoryUtil.createJSONObject(categoryJSON); List<String> names = new ArrayList<String>(); AssetCategory curCategory = category; while (curCategory.getParentCategoryId() > 0) { AssetCategory parentCategory = getCategory(curCategory.getParentCategoryId()); names.add(parentCategory.getName()); names.add(StringPool.SPACE + StringPool.GREATER_THAN + StringPool.SPACE); curCategory = parentCategory; } Collections.reverse(names); AssetVocabulary vocabulary = assetVocabularyService.getVocabulary(category.getVocabularyId()); StringBundler sb = new StringBundler(1 + names.size()); sb.append(vocabulary.getName()); sb.append(names.toArray(new String[names.size()])); categoryJSONObject.put("path", sb.toString()); jsonArray.put(categoryJSONObject); } return jsonArray; }