diff --git a/ccm-cms-dabinimporter/src/com/arsdigita/cms/dabin/DaBInImporter.java b/ccm-cms-dabinimporter/src/com/arsdigita/cms/dabin/DaBInImporter.java index 2a7754333..6ecd1559b 100644 --- a/ccm-cms-dabinimporter/src/com/arsdigita/cms/dabin/DaBInImporter.java +++ b/ccm-cms-dabinimporter/src/com/arsdigita/cms/dabin/DaBInImporter.java @@ -2138,19 +2138,22 @@ public class DaBInImporter extends Program { Term term; term = termsDomain.getTerm( finishedProjectsTerm.getUniqueID()); + System.out.printf("\tAdding project to term '%s:%s'...\n", + term.getUniqueID(), + term.getName()); term.addObject(project); term.save(); + project.save(); } else { Term term; term = termsDomain.getTerm(currentProjectsTerm.getUniqueID()); - if (projectDe != null) { - term.addObject(projectDe); - } - if (projectEn != null) { - term.addObject(projectEn); - } + System.out.printf("\tAdding project to term '%s:%s'...\n", + term.getUniqueID(), + term.getName()); + term.addObject(project); term.save(); + project.save(); } System.out.println("\tOK"); @@ -2641,12 +2644,9 @@ public class DaBInImporter extends Program { term = publicationsTerm; } term = termsDomain.getTerm(term.getUniqueID()); - if (publicationDe != null) { - term.addObject(publicationDe); - } - if (publicationEn != null) { - term.addObject(publicationEn); - } + System.out.printf("\tAdding publication to term '%s:%s'...\n", term. + getUniqueID(), term.getName()); + term.addObject(publication); term.save(); } }; @@ -2761,12 +2761,9 @@ public class DaBInImporter extends Program { term = workingPapersTerm; } term = termsDomain.getTerm(term.getUniqueID()); - if (workingPaperDe != null) { - term.addObject(workingPaperDe); - } - if (workingPaperEn != null) { - term.addObject(workingPaperEn); - } + System.out.printf("\tAdding project to term '%s:%s'...\n", term. + getUniqueID(), term.getName()); + term.addObject(workingPaper); term.save(); System.out.println("\tOK"); @@ -2823,7 +2820,7 @@ public class DaBInImporter extends Program { getName()); if (name.length() > 200) { name = name.substring(0, 200); - } + } fsi.setName(name); FileAsset file = new FileAsset(); file.loadFromFile(name, @@ -3291,8 +3288,10 @@ public class DaBInImporter extends Program { try { Term term = Term.create(uniqueId, name, false, "", domain); term.save(); - parent.addNarrowerTerm(term, false, false); - //parent.save(); + Term parentTerm = termsDomain.getTerm(parent.getUniqueID()); + term = termsDomain.getTerm(term.getUniqueID()); + parentTerm.addNarrowerTerm(term, true, true); + parentTerm.save(); } catch (Exception ex) { ex.printStackTrace(System.err); } diff --git a/ccm-core/src/com/arsdigita/categorization/Category.java b/ccm-core/src/com/arsdigita/categorization/Category.java index d49342f52..f4452d405 100755 --- a/ccm-core/src/com/arsdigita/categorization/Category.java +++ b/ccm-core/src/com/arsdigita/categorization/Category.java @@ -51,7 +51,6 @@ import java.util.StringTokenizer; import org.apache.log4j.Logger; - /** * *

Implements persistent storage of categories. See {@link @@ -104,42 +103,37 @@ import org.apache.log4j.Logger; * Quasimodo */ public class Category extends ACSObject { - private static final Logger s_log = Logger.getLogger(Category.class); + private static final Logger s_log = Logger.getLogger(Category.class); /** * @see ObjectType **/ public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.categorization.Category"; - + "com.arsdigita.categorization.Category"; private static final String BASE_DATA_OBJECT_PACKAGE = - "com.arsdigita.categorization"; - + "com.arsdigita.categorization"; /** * The PrivilegeDescriptor corresponding to the privilege to * map subcategories and objects to this category **/ public static final PrivilegeDescriptor MAP_DESCRIPTOR = - new PrivilegeDescriptor("map_to_category"); - + new PrivilegeDescriptor( + "map_to_category"); // Quasimodo: Begin private static CategorizationConfig s_config = new CategorizationConfig(); - + static { s_config.load(); } // Quasimodo: End - public static final String ROOT_CATEGORY = "rootCategory"; - public static final String USE_CONTEXT = "useContext"; + public static final String USE_CONTEXT = "useContext"; public static final String CATEGORY_OWNER = "categoryOwner"; public static final String ROOT_USE_CONTEXT = "rootUseContext"; public static final String OWNER_USE_CONTEXT = "ownerUseContext"; - - // category-category mapping types /** An attribute name for the underlying data object. */ - public static final String CHILD = "child"; + public static final String CHILD = "child"; /** An attribute name for the underlying data object. */ public static final String PARENTS = "parents"; /** An attribute name for the underlying data object. */ @@ -149,11 +143,10 @@ public class Category extends ACSObject { public static final String REL_TYPE = "relationType"; /** An attribute name for the underlying data object. */ public static final String SORT_KEY = "sortKey"; - public static final String IS_DEFAULT = "isDefault"; - public static final String IS_INDEX = "isIndex"; + public static final String IS_DEFAULT = "isDefault"; + public static final String IS_INDEX = "isIndex"; public static final String PARENT_CATEGORY = "parentCategory"; - public static final String CATEGORY_ID = "categoryID"; - + public static final String CATEGORY_ID = "categoryID"; // these are some constants to use in the code /** An attribute name for the underlying data object. */ public static final String NAME = "name"; @@ -168,25 +161,20 @@ public class Category extends ACSObject { /** An attribute name for the underlying data object. */ public static final String DEFAULT_ANCESTORS = "defaultAncestors"; /** An attribute name for the underlying data object. */ - public static final String IGNORE_PARENT_INDEX_ITEM = "ignoreParentIndexItem"; + public static final String IGNORE_PARENT_INDEX_ITEM = + "ignoreParentIndexItem"; /** An attribute name for the underlying data object. */ private static final String PURPOSES = "purposes"; - // this contains association names from the pdl file public final static String CHILD_OBJECTS = "childObjects"; public final static String RELATED_CATEGORIES = RELATED; public final static String CATEGORIES = "categories"; - public static final String LOCALIZATIONS = "localizations"; - // some named queries in the pdl files private static final String CHILD_CATEGORY_IDS = - "com.arsdigita.categorization.childCategoryIDs"; - + "com.arsdigita.categorization.childCategoryIDs"; private static final String CURRENT_SORT_KEY = "currentSortKey"; - private HierarchyDenormalization m_hierarchy; - // Quasimodo: Begin // Save the localized parts of category private CategoryLocalizationCollection m_categoryLocalizationCollection; @@ -203,7 +191,6 @@ public class Category extends ACSObject { return BASE_DATA_OBJECT_PACKAGE; } - /** * Initializes the category with the specified data object. * @@ -223,7 +210,6 @@ public class Category extends ACSObject { this(BASE_DATA_OBJECT_TYPE); } - /** * Initializes the contained data object with a new data object whose object * type is specified by the passed in type name. @@ -251,7 +237,6 @@ public class Category extends ACSObject { super(type); } - /** * Retrieves the data object with the specified OID from the persistent * storage mechanism. @@ -267,7 +252,6 @@ public class Category extends ACSObject { super(oid); } - /** * Retrieves the data object with the specified ID from the persistence * storage mechanism. This method is just a wrapper for the {@link @@ -291,7 +275,6 @@ public class Category extends ACSObject { setDescription(description); } - /** * Creates a new category with the given name, description and URL * component. @@ -304,10 +287,9 @@ public class Category extends ACSObject { this(); setName(name); setDescription(description); - setURL (url); + setURL(url); } - /** * Retrieves the category with the given category ID, and sets the name and * description. For the new name and descrption to be permanent, the caller @@ -327,7 +309,6 @@ public class Category extends ACSObject { setDescription(description); } - /** * Retrieves the category with the given category ID, and sets the name and * description. For the new name and descrption to be permanent, the caller @@ -346,12 +327,10 @@ public class Category extends ACSObject { this(categoryID); setName(name); setDescription(description); - setURL (url); + setURL(url); } - // Quasimodo: Begin - /** * Retrieves the current configuration */ @@ -381,16 +360,17 @@ public class Category extends ACSObject { } - m_hierarchy = new HierarchyDenormalization - ("com.arsdigita.categorization.updateCategoryDescendants", this, - DEFAULT_ANCESTORS) {}; + m_hierarchy = new HierarchyDenormalization( + "com.arsdigita.categorization.updateCategoryDescendants", this, + DEFAULT_ANCESTORS) { + }; - m_categoryLocalizationCollection = new CategoryLocalizationCollection(this); + m_categoryLocalizationCollection = new CategoryLocalizationCollection( + this); } // Quasimodo: End - - + /** * Quasimodo: * Returns the localized name or the name key if localized version don't exist @@ -400,19 +380,20 @@ public class Category extends ACSObject { public String getName(String locale) { // Test for localized version - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + // Return value of isEnabled from localized version, so categories could be disabled depending on locale return m_categoryLocalizationCollection.getName(); - + } else { - + // Return name key return (String) get(NAME); } } - + /** * @return the category name. */ @@ -439,7 +420,6 @@ public class Category extends ACSObject { return getName(); } - /** * Returns the name of the category along with its default ancestors. * @@ -492,19 +472,22 @@ public class Category extends ACSObject { * @param includeRoot should root category be shown * @return category path */ - public String getPreferredQualifiedName(String delimiter, boolean includeRoot) { + public String getPreferredQualifiedName(String delimiter, + boolean includeRoot) { // is this a synonym? - CategoryCollection cc = new CategoryCollection (getRelatedCategories(PREFERRED)); + CategoryCollection cc = new CategoryCollection(getRelatedCategories( + PREFERRED)); if (cc.next()) { Category preferred = cc.getCategory(); cc.close(); - String preferredPath = preferred.getQualifiedName(delimiter, includeRoot); + String preferredPath = preferred.getQualifiedName(delimiter, + includeRoot); return preferredPath + " (" + getName() + ")"; } else { return getQualifiedName(delimiter, includeRoot); } } - + /** * Returns the url of the category along with its default ancestors * @@ -544,9 +527,11 @@ public class Category extends ACSObject { * @param value the new name of the category */ public void setName(String name, String locale) { - - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - m_categoryLocalizationCollection.getCategoryLocalization().setName(name); + + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + m_categoryLocalizationCollection.getCategoryLocalization().setName( + name); } } @@ -560,7 +545,6 @@ public class Category extends ACSObject { set(NAME, name); } - /** * Returns the description of the category. * @@ -573,13 +557,14 @@ public class Category extends ACSObject { // Test for localized version // HACK - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + // Return value of isEnabled from localized version, so categories could be disabled depending on locale return m_categoryLocalizationCollection.getDescription(); - + } else { - + // Return description key return (String) get(DESCRIPTION); } @@ -591,7 +576,8 @@ public class Category extends ACSObject { * @return the category name. */ public String getDescription() { - return getDescription(DispatcherHelper.getNegotiatedLocale().getLanguage()); + return getDescription( + DispatcherHelper.getNegotiatedLocale().getLanguage()); } /** @@ -602,8 +588,8 @@ public class Category extends ACSObject { * ids whose position in the path is known. * (Added by Chris Gilbert) */ - public String getDefaultAncestors () { - return (String)get(DEFAULT_ANCESTORS); + public String getDefaultAncestors() { + return (String) get(DEFAULT_ANCESTORS); } /** @@ -612,9 +598,11 @@ public class Category extends ACSObject { * @param value the new description of the category */ public void setDescription(String description, String locale) { - - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - m_categoryLocalizationCollection.getCategoryLocalization().setDescription(description); + + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + m_categoryLocalizationCollection.getCategoryLocalization(). + setDescription(description); } } @@ -628,7 +616,6 @@ public class Category extends ACSObject { set(DESCRIPTION, description); } - /** * Returns the URL component of the category. * @@ -640,17 +627,18 @@ public class Category extends ACSObject { public String getURL(String locale) { // Test for localized version - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + // Return value of isEnabled from localized version, so categories could be disabled depending on locale return m_categoryLocalizationCollection.getURL(); - + } else { - + // Return URL-key return (String) get(URL); } - + } /** @@ -662,21 +650,21 @@ public class Category extends ACSObject { return getURL(DispatcherHelper.getNegotiatedLocale().getLanguage()); } - /** * Sets the URL component of the category. * * @param url URL component used when browsing categories */ public void setURL(String url, String locale) { - - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - m_categoryLocalizationCollection.getCategoryLocalization().setURL(url); + + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + m_categoryLocalizationCollection.getCategoryLocalization().setURL( + url); } } - /** * Sets the URL component of the category. * @@ -686,7 +674,6 @@ public class Category extends ACSObject { set(URL, url); } - /** * Determines the current state of the category. * @@ -702,28 +689,29 @@ public class Category extends ACSObject { * */ public boolean isEnabled(String locale) { - + // If locale == "" return global status // or if globally disabled, return category as disabled - if(locale == "" || ((Boolean) get(IS_ENABLED)).booleanValue() == false) { + if (locale == "" || ((Boolean) get(IS_ENABLED)).booleanValue() == false) { return ((Boolean) get(IS_ENABLED)).booleanValue(); } - + // Test for localized version // HACK - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + // Return value of isEnabled from localized version, so categories could be disabled depending on locale return m_categoryLocalizationCollection.isEnabled(); - + } else { - + // Return value of Category.getConfig().getShowInternalName() // This will disable all categories without selected locale, if Category.getConfig().getShowInternalName() == false return Category.getConfig().getShowInternalName(); } - + } /** @@ -743,9 +731,11 @@ public class Category extends ACSObject { * false otherwise. */ public void setEnabled(boolean isEnabled, String locale) { - - if(locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.localizationExists(locale)) { - m_categoryLocalizationCollection.getCategoryLocalization().setEnabled(isEnabled); + + if (locale != "" && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. + localizationExists(locale)) { + m_categoryLocalizationCollection.getCategoryLocalization(). + setEnabled(isEnabled); } } @@ -760,7 +750,6 @@ public class Category extends ACSObject { set(IS_ENABLED, new Boolean(isEnabled)); } - /** * An abstract category cannot have any child objects, but it can have child * categories. @@ -772,7 +761,6 @@ public class Category extends ACSObject { return ((Boolean) get(IS_ABSTRACT)).booleanValue(); } - /** * Sets whether the category is abstract. * @@ -789,7 +777,7 @@ public class Category extends ACSObject { * @return true if the parent index item should be ignored (no default index item) * false otherwise. */ - public boolean ignoreParentIndexItem(){ + public boolean ignoreParentIndexItem() { return ((Boolean) get(IGNORE_PARENT_INDEX_ITEM)).booleanValue(); } @@ -800,26 +788,25 @@ public class Category extends ACSObject { * @param ignoreParentIndexItem true if the parent index item should be ignored (no default index item) * false otherwise */ - public void setIgnoreParentIndexItem(boolean ignoreParentIndexItem){ + public void setIgnoreParentIndexItem(boolean ignoreParentIndexItem) { set(IGNORE_PARENT_INDEX_ITEM, new Boolean(ignoreParentIndexItem)); } - /** * @deprecated use the "use context" APIs instead **/ public Collection getPurposes() { - DataAssociationCursor purposeCur = ((DataAssociation) get(PURPOSES)).cursor(); + DataAssociationCursor purposeCur = ((DataAssociation) get(PURPOSES)). + cursor(); Collection purposes = new LinkedList(); while (purposeCur.next()) { - CategoryPurpose cp = (CategoryPurpose) - DomainObjectFactory.newInstance(purposeCur.getDataObject()); + CategoryPurpose cp = (CategoryPurpose) DomainObjectFactory. + newInstance(purposeCur.getDataObject()); purposes.add(cp); } return purposes; } - /** * Adds the specified purpose to this category. * @@ -830,7 +817,6 @@ public class Category extends ACSObject { add(PURPOSES, purpose); } - /** * Removes the specified purpose from this category. * @@ -846,13 +832,12 @@ public class Category extends ACSObject { if (defaultParent == null) { value = getID() + "/"; } else { - value = (String) defaultParent.get(DEFAULT_ANCESTORS) + - getID().toString() + "/"; + value = (String) defaultParent.get(DEFAULT_ANCESTORS) + getID(). + toString() + "/"; } set(DEFAULT_ANCESTORS, value); } - /** * @see com.arsdigita.domain.DomainObject#beforeSave() */ @@ -880,11 +865,10 @@ public class Category extends ACSObject { * @param object the object to test */ public static boolean isCategory(ACSObject object) { - return object.getSpecificObjectType().equals - (Category.BASE_DATA_OBJECT_TYPE); + return object.getSpecificObjectType().equals( + Category.BASE_DATA_OBJECT_TYPE); } - /** * Cleans up all the mappings where this category is a child, and then * deletes the category. This method should generally not be used. Use @@ -901,25 +885,25 @@ public class Category extends ACSObject { DataAssociationCursor children = getRelatedCategories(CHILD); children.addEqualsFilter("link.isDefault", Boolean.TRUE); try { - if ( children.next() ) { - throw new CategorizationException - ("This category is the default parent of another category." + - " You must explicitly delete the child categories first. " + - "Child category: " + children.getDataObject()); + if (children.next()) { + throw new CategorizationException("This category is the default parent of another category." + + " You must explicitly delete the child categories first. " + + "Child category: " + children. + getDataObject()); } } finally { children.close(); } DataAssociationCursor objects = - ((DataAssociation) get(CHILD_OBJECTS)).cursor(); + ((DataAssociation) get(CHILD_OBJECTS)).cursor(); if (objects != null) { try { - if ( objects.next() ) { - throw new CategorizationException - ("This category has child objects. You must delete " + - " any such objects explicitly, before deleting the " + - " category. Child object: " + objects.getDataObject()); + if (objects.next()) { + throw new CategorizationException("This category has child objects. You must delete " + + " any such objects explicitly, before deleting the " + + " category. Child object: " + objects. + getDataObject()); } } finally { objects.close(); @@ -931,7 +915,6 @@ public class Category extends ACSObject { super.delete(); } - /** * This clears out all relations so that we do not have any issues with * mutating triggers @@ -941,7 +924,6 @@ public class Category extends ACSObject { clear(PARENTS); } - /** * Deletes the category after deleting all default categories in its subtree * @@ -953,7 +935,7 @@ public class Category extends ACSObject { public void deleteCategorySubtree() { // we get the association between this category and its children DataAssociationCursor cursor = - ((DataAssociation) get(RELATED_CATEGORIES)).cursor(); + ((DataAssociation) get(RELATED_CATEGORIES)).cursor(); while (cursor.next()) { DataObject link = cursor.getLink(); @@ -967,7 +949,6 @@ public class Category extends ACSObject { delete(); } - /** * Deletes the passed in category after remapping all the children. Adds a * mapping from the children to the default parent of the passed in category @@ -993,12 +974,12 @@ public class Category extends ACSObject { } DataAssociationCursor cursor = - ((DataAssociation) get(RELATED_CATEGORIES)).cursor(); + ((DataAssociation) get(RELATED_CATEGORIES)).cursor(); while (cursor.next()) { DataObject link = cursor.getLink(); - String relationType = (String)link.get(REL_TYPE); - Boolean isDefault = (Boolean)link.get(IS_DEFAULT); + String relationType = (String) link.get(REL_TYPE); + Boolean isDefault = (Boolean) link.get(IS_DEFAULT); remove(RELATED_CATEGORIES, cursor.getDataObject()); if ("child".equals(relationType)) { Category category = new Category(cursor.getDataObject()); @@ -1010,7 +991,8 @@ public class Category extends ACSObject { } cursor = ((DataAssociation) get(CHILD_OBJECTS)).cursor(); - DataAssociation parentChildren = (DataAssociation)parent.get(CHILD_OBJECTS); + DataAssociation parentChildren = (DataAssociation) parent.get( + CHILD_OBJECTS); while (cursor.next()) { DataObject link = cursor.getLink(); DataObject object = cursor.getDataObject(); @@ -1025,7 +1007,6 @@ public class Category extends ACSObject { delete(); } - /** * Deletes the passed in category. Does not remap any of the children * categories or objects. Instead, it just deletes all records of the @@ -1038,7 +1019,6 @@ public class Category extends ACSObject { super.delete(); } - /** * This makes the ACS object a child of the category if: *