[UPDATE]
- corrects nullpointer bugs during the conversion of categories git-svn-id: https://svn.libreccm.org/ccm/trunk@4302 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
3706bbf3d1
commit
57940eedc4
|
|
@ -48,41 +48,26 @@ public class CategoryConversion {
|
||||||
List<com.arsdigita.categorization.Category> trunkCategories = com
|
List<com.arsdigita.categorization.Category> trunkCategories = com
|
||||||
.arsdigita.categorization.Category.getAllObjectCategories();
|
.arsdigita.categorization.Category.getAllObjectCategories();
|
||||||
|
|
||||||
createCategoryAndSetAssociations(trunkCategories);
|
createCategoryAndCategorizations(trunkCategories);
|
||||||
|
setRingAssociations(trunkCategories);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the equivalent ng-class of the {@code Category} and restores
|
* Creates the equivalent ng-class of the {@link Category} and restores
|
||||||
* the associations to other classes.
|
* the associations to other classes.
|
||||||
*
|
*
|
||||||
* @param trunkCategories List of all
|
* @param trunkCategories List of all
|
||||||
* {@link com.arsdigita.categorization.Category}s
|
* {@link com.arsdigita.categorization.Category}s
|
||||||
* from this old trunk-system.
|
* from this old trunk-system.
|
||||||
*/
|
*/
|
||||||
private static void createCategoryAndSetAssociations(
|
private static void createCategoryAndCategorizations(
|
||||||
List<com.arsdigita.categorization.Category> trunkCategories) {
|
List<com.arsdigita.categorization.Category> trunkCategories) {
|
||||||
for (com.arsdigita.categorization.Category
|
for (com.arsdigita.categorization.Category
|
||||||
trunkCategory : trunkCategories) {
|
trunkCategory : trunkCategories) {
|
||||||
|
|
||||||
// create categories
|
// create categories
|
||||||
Category category = new Category(trunkCategory);
|
Category category = new Category(trunkCategory);
|
||||||
|
|
||||||
|
|
||||||
// set parent and opposed association
|
|
||||||
Category parentCategory = null;
|
|
||||||
try {
|
|
||||||
com.arsdigita.categorization.Category defaultParent =
|
|
||||||
trunkCategory.getDefaultParentCategory();
|
|
||||||
|
|
||||||
if (defaultParent != null) {
|
|
||||||
parentCategory = NgCollection.categories.get(
|
|
||||||
defaultParent.getID().longValue());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {}
|
|
||||||
if (parentCategory != null) {
|
|
||||||
category.setParentCategory(parentCategory);
|
|
||||||
parentCategory.addSubCategory(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
// categorizations only for category typed objects
|
// categorizations only for category typed objects
|
||||||
CategorizedCollection categorizedCollection = trunkCategory
|
CategorizedCollection categorizedCollection = trunkCategory
|
||||||
.getObjects(com.arsdigita.categorization.Category
|
.getObjects(com.arsdigita.categorization.Category
|
||||||
|
|
@ -118,4 +103,42 @@ public class CategoryConversion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for setting the parent {@link Category} on the one side and the
|
||||||
|
* sub-{@link Category}s on the other side.
|
||||||
|
*
|
||||||
|
* @param trunkCategories List of all
|
||||||
|
* {@link com.arsdigita.categorization.Category}s
|
||||||
|
* from this old trunk-system.
|
||||||
|
*/
|
||||||
|
private static void setRingAssociations(
|
||||||
|
List<com.arsdigita.categorization.Category> trunkCategories) {
|
||||||
|
for (com.arsdigita.categorization.Category
|
||||||
|
trunkCategory : trunkCategories) {
|
||||||
|
|
||||||
|
Category category = NgCollection.categories.get(trunkCategory
|
||||||
|
.getID().longValue());
|
||||||
|
|
||||||
|
// set parent and opposed association
|
||||||
|
Category parentCategory = null;
|
||||||
|
try {
|
||||||
|
com.arsdigita.categorization.Category defaultParent =
|
||||||
|
trunkCategory.getDefaultParentCategory();
|
||||||
|
|
||||||
|
if (defaultParent != null) {
|
||||||
|
parentCategory = NgCollection.categories.get(
|
||||||
|
defaultParent.getID().longValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {}
|
||||||
|
if (parentCategory != null) {
|
||||||
|
//category.setParentCategory(parentCategory);
|
||||||
|
//parentCategory.addSubCategory(category);
|
||||||
|
|
||||||
|
// to avoid infinite recursion
|
||||||
|
category.setParentCategoryId(parentCategory.getObjectId());
|
||||||
|
parentCategory.addSubCategoryId(category.getObjectId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,10 @@ public class Category extends CcmObject {
|
||||||
private Category parentCategory;
|
private Category parentCategory;
|
||||||
private long categoryOrder;
|
private long categoryOrder;
|
||||||
|
|
||||||
|
// to avoid infinite recursion
|
||||||
|
private List<Long> subCategoriesId;
|
||||||
|
private long parentCategoryId;
|
||||||
|
|
||||||
|
|
||||||
public Category(final com.arsdigita.categorization.Category trunkCategory) {
|
public Category(final com.arsdigita.categorization.Category trunkCategory) {
|
||||||
super(trunkCategory);
|
super(trunkCategory);
|
||||||
|
|
@ -71,12 +75,18 @@ public class Category extends CcmObject {
|
||||||
trunkCategory.getCategoryLocalizationCollection();
|
trunkCategory.getCategoryLocalizationCollection();
|
||||||
if (categoryLocalizationCollection != null &&
|
if (categoryLocalizationCollection != null &&
|
||||||
categoryLocalizationCollection.next()) {
|
categoryLocalizationCollection.next()) {
|
||||||
CategoryLocalization categoryLocalization = trunkCategory
|
|
||||||
.getCategoryLocalizationCollection().getCategoryLocalization();
|
|
||||||
|
|
||||||
Locale locale = new Locale(categoryLocalization.getLocale());
|
CategoryLocalization categoryLocalization =
|
||||||
this.title.addValue(locale, categoryLocalization.getName());
|
categoryLocalizationCollection.getCategoryLocalization();
|
||||||
this.description.addValue(locale, categoryLocalization.getDescription());
|
|
||||||
|
if (categoryLocalization != null && categoryLocalization
|
||||||
|
.getLocale() != null) {
|
||||||
|
Locale locale = new Locale(categoryLocalization.getLocale());
|
||||||
|
if (categoryLocalization.getName() != null)
|
||||||
|
this.title.addValue(locale, categoryLocalization.getName());
|
||||||
|
if (categoryLocalization.getDescription() != null)
|
||||||
|
this.description.addValue(locale, categoryLocalization.getDescription());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.enabled = trunkCategory.isEnabled();
|
this.enabled = trunkCategory.isEnabled();
|
||||||
|
|
@ -208,4 +218,29 @@ public class Category extends CcmObject {
|
||||||
public void setCategoryOrder(final long categoryOrder) {
|
public void setCategoryOrder(final long categoryOrder) {
|
||||||
this.categoryOrder = categoryOrder;
|
this.categoryOrder = categoryOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Long> getSubCategoriesId() {
|
||||||
|
return subCategoriesId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubCategoriesId(List<Long> subCategoriesId) {
|
||||||
|
this.subCategoriesId = subCategoriesId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubCategoryId(final long subCategoryId) {
|
||||||
|
this.subCategoriesId.add(subCategoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSubCategoryId(final long subCategoryId) {
|
||||||
|
this.subCategoriesId.remove(subCategoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getParentCategoryId() {
|
||||||
|
return parentCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentCategoryId(long parentCategoryId) {
|
||||||
|
this.parentCategoryId = parentCategoryId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue