@Indexable(type = IndexableType.REINDEX) @Override public AssetCategory moveCategory( long categoryId, long parentCategoryId, long vocabularyId, ServiceContext serviceContext) throws PortalException { AssetCategory category = assetCategoryPersistence.findByPrimaryKey(categoryId); validate(categoryId, parentCategoryId, category.getName(), vocabularyId); if (parentCategoryId > 0) { assetCategoryPersistence.findByPrimaryKey(parentCategoryId); } if (vocabularyId != category.getVocabularyId()) { assetVocabularyPersistence.findByPrimaryKey(vocabularyId); category.setVocabularyId(vocabularyId); updateChildrenVocabularyId(category, vocabularyId); } category.setParentCategoryId(parentCategoryId); assetCategoryPersistence.update(category); return category; }
@Indexable(type = IndexableType.REINDEX) @Override public AssetCategory updateCategory( long userId, long categoryId, long parentCategoryId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, long vocabularyId, String[] categoryProperties, ServiceContext serviceContext) throws PortalException { // Category String name = titleMap.get(LocaleUtil.getSiteDefault()); name = ModelHintsUtil.trimString(AssetCategory.class.getName(), "name", name); if (categoryProperties == null) { categoryProperties = new String[0]; } validate(categoryId, parentCategoryId, name, vocabularyId); if (parentCategoryId > 0) { assetCategoryPersistence.findByPrimaryKey(parentCategoryId); } AssetCategory category = assetCategoryPersistence.findByPrimaryKey(categoryId); String oldName = category.getName(); if (vocabularyId != category.getVocabularyId()) { assetVocabularyPersistence.findByPrimaryKey(vocabularyId); parentCategoryId = AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID; category.setVocabularyId(vocabularyId); updateChildrenVocabularyId(category, vocabularyId); } category.setParentCategoryId(parentCategoryId); category.setName(name); category.setTitleMap(titleMap); category.setDescriptionMap(descriptionMap); assetCategoryPersistence.update(category); // Properties List<AssetCategoryProperty> oldCategoryProperties = assetCategoryPropertyPersistence.findByCategoryId(categoryId); oldCategoryProperties = ListUtil.copy(oldCategoryProperties); for (int i = 0; i < categoryProperties.length; i++) { String[] categoryProperty = StringUtil.split( categoryProperties[i], AssetCategoryConstants.PROPERTY_KEY_VALUE_SEPARATOR); if (categoryProperty.length <= 1) { categoryProperty = StringUtil.split(categoryProperties[i], CharPool.COLON); } String key = StringPool.BLANK; if (categoryProperty.length > 0) { key = GetterUtil.getString(categoryProperty[0]); } String value = StringPool.BLANK; if (categoryProperty.length > 1) { value = GetterUtil.getString(categoryProperty[1]); } if (Validator.isNotNull(key)) { boolean addCategoryProperty = true; AssetCategoryProperty oldCategoryProperty = null; Iterator<AssetCategoryProperty> iterator = oldCategoryProperties.iterator(); while (iterator.hasNext()) { oldCategoryProperty = iterator.next(); if ((categoryId == oldCategoryProperty.getCategoryId()) && key.equals(oldCategoryProperty.getKey())) { addCategoryProperty = false; if (!value.equals(oldCategoryProperty.getValue())) { assetCategoryPropertyLocalService.updateCategoryProperty( userId, oldCategoryProperty.getCategoryPropertyId(), key, value); } iterator.remove(); break; } } if (addCategoryProperty) { assetCategoryPropertyLocalService.addCategoryProperty(userId, categoryId, key, value); } } } for (AssetCategoryProperty categoryProperty : oldCategoryProperties) { assetCategoryPropertyLocalService.deleteAssetCategoryProperty(categoryProperty); } // Indexer if (!oldName.equals(name)) { List<AssetEntry> entries = assetCategoryPersistence.getAssetEntries(category.getCategoryId()); assetEntryLocalService.reindex(entries); } return category; }