diff --git a/ccm-core/src/com/arsdigita/portation/Identifiable.java b/ccm-core/src/com/arsdigita/portation/Identifiable.java index 9011b6999..f8b15fbf5 100644 --- a/ccm-core/src/com/arsdigita/portation/Identifiable.java +++ b/ccm-core/src/com/arsdigita/portation/Identifiable.java @@ -24,8 +24,5 @@ package com.arsdigita.portation; */ public interface Identifiable { - String getTrunkClass(); - void setTrunkClass(String trunkClass); - AbstractMarshaller getMarshaller(); } diff --git a/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java b/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java index e02108c5a..51b65a2d7 100644 --- a/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java +++ b/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java @@ -25,7 +25,7 @@ import com.arsdigita.portation.modules.core.security.Party; import com.arsdigita.portation.modules.core.security.PartyMarshaller; import com.arsdigita.portation.modules.core.security.User; import com.arsdigita.portation.modules.core.security.UserMarshaller; -import com.arsdigita.portation.modules.core.utils.CollectionConverter; +import com.arsdigita.portation.modules.utils.CollectionConverter; import org.apache.log4j.Logger; import java.util.ArrayList; diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java index 714b8ad31..fe0e7c5cd 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java @@ -18,18 +18,21 @@ */ package com.arsdigita.portation.modules.core.categorization; +import com.arsdigita.kernel.ACSObject; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.modules.core.core.CcmObject; /** + * Association class describing the association between a category and an + * object. Instances of these class should not created manually. The methods + * provided by the {@code CategoryManager} take care of that. + * * @author Tobias Osmers<\a> * @version created the 6/15/16 */ @@ -33,23 +47,139 @@ public class Category extends CcmObject { private String uniqueId; private String name; + private LocalizedString title; private LocalizedString description; + private boolean enabled; private boolean visible; private boolean abstractCategory; + private List objects; + private List subCategories; private Category parentCategory; private long categoryOrder; - public Category() { + public Category(final com.arsdigita.categorization.Category trunkCategory) { + super(trunkCategory); + this.uniqueId = null;// Todo: mapping + this.name = trunkCategory.getName(); + + CategoryLocalizationCollection categoryLocalization = trunkCategory + .getCategoryLocalizationCollection(); + Locale locale = new Locale(categoryLocalization.getLocale()); + this.title.addValue(locale, categoryLocalization.getName()); + this.description.addValue(locale, categoryLocalization.getDescription()); + + this.enabled = trunkCategory.isEnabled(); + this.visible = trunkCategory.isVisible(); + this.abstractCategory = trunkCategory.isAbstract(); + + CategorizedCollection categorizedCollection = trunkCategory.getObjects( + trunkCategory.getObjectType().toString()); + this.objects = CollectionConverter.convertCategorizations( + categorizedCollection, this); + + this.subCategories = convertCategories(trunkCategory.getChildren()); + this.parentCategory = trunkCategory.getParentCategoryCount() >= 1 ? + new Category(trunkCategory.getParents().getCategory()) : null; + this.categoryOrder = 0; } + @Override public AbstractMarshaller getMarshaller() { return new CategoryMarshaller(); } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public LocalizedString getTitle() { + return this.title; + } + + public void setTitle(LocalizedString title) { + this.title = title; + } + + public LocalizedString getDescription() { + return this.description; + } + + public void setDescription(LocalizedString description) { + this.description = description; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + public boolean isAbstractCategory() { + return abstractCategory; + } + + public void setAbstractCategory(boolean abstractCategory) { + this.abstractCategory = abstractCategory; + } + + public List getObjects() { + return objects; + } + + public void setObjects(List objects) { + this.objects = objects; + } + + public List getSubCategories() { + return subCategories; + } + + public void setSubCategories(List subCategories) { + this.subCategories = subCategories; + } + + public Category getParentCategory() { + return parentCategory; + } + + public void setParentCategory(Category parentCategory) { + this.parentCategory = parentCategory; + } + + public long getCategoryOrder() { + return categoryOrder; + } + + public void setCategoryOrder(long categoryOrder) { + this.categoryOrder = categoryOrder; + } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java new file mode 100644 index 000000000..94c22bec9 --- /dev/null +++ b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.portation.modules.core.categorization.utils; + +import com.arsdigita.categorization.CategorizedCollection; +import com.arsdigita.categorization.CategoryCollection; +import com.arsdigita.portation.modules.core.categorization.Categorization; +import com.arsdigita.portation.modules.core.categorization.Category; +import org.apache.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author convertCategories(CategoryCollection + categoryCollection) { + List categories = new ArrayList<>(); + if (categoryCollection != null) { + while (categoryCollection.next()) { + categories.add(new Category(categoryCollection.getCategory())); + } + categoryCollection.close(); + } else { + logger.error("Failed to convertCategories, cause " + + "categoryCollection is null."); + } + return categories; + } +} diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java index c14fcce68..2a3f2c242 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java @@ -18,21 +18,34 @@ */ package com.arsdigita.portation.modules.core.core; +import com.arsdigita.kernel.ACSObject; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.modules.core.categorization.Categorization; +import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.security.Permission; import java.util.List; /** + * Root class of all entities in LibreCCM which need categorisation and + * permission services. + * + * This class defines several basic properties including associations to + * {@link Category} (via the {@link Categorization} class and permissions. + * + * In the old hierarchy the equivalent of this class was the {@code ACSObject} + * entity. + * + * We are using the {@code JOINED} inheritance strategy for the inheritance + * hierarchy of this class to achieve modularity and to minimise duplicate data + * in the database. + * * @author Tobias Osmers<\a> * @version created the 6/15/16 */ public class LocalizedString implements Identifiable { - private String trunkClass; - private Map values; - + /** + * Constructor. Only creates the initial, empty map for new instances. + */ public LocalizedString() { - - } - - @Override - public String getTrunkClass() { - return this.trunkClass; - } - - @Override - public void setTrunkClass(String trunkClass) { - this.trunkClass = trunkClass; + this.values = new HashMap<>(); } @Override public AbstractMarshaller getMarshaller() { return new LocalizedStringMarshaller(); } + + /** + * Get all localised values. + * + * @return A unmodifiable {@code Map} containing all localised values of + * this localised string. + */ + public Map getValues() { + if (values == null) { + return null; + } else { + return Collections.unmodifiableMap(values); + } + } + + /** + * Setter for replacing the complete {@code Map} of values. Only to be used + * by JPA and the Repository classes in the package. + * + * @param values The new map of values. + */ + protected void setValues(final Map values) { + this.values = values; + } + + /** + * Retrieves the values for the default locale. + * + * @return The localised value for the default locale of the system the + * application is running on. In most cases this is not what you + * want. Use {@link #getValue(java.util.Locale)} instead. + */ + public String getValue() { + return getValue(Locale.getDefault()); + } + + /** + * Retrieves the localised value of a locale. + * + * @param locale The locale for which the value shall be retrieved. + * + * @return The localised for the {@code locale} or {@code null} if there is + * no value for the provided locale. + */ + public String getValue(final Locale locale) { + return values.get(locale); + } + + /** + * Add a new localised value for a locale. If there is already a value for + * the provided locale the value is replaced with the new value. + * + * @param locale The locale of the provided value. + * @param value The localised value for the provided locale. + */ + public void addValue(final Locale locale, final String value) { + values.put(locale, value); + } + + /** + * Removes the value for the provided locale. + * + * @param locale The locale for which the value shall be removed. + */ + public void removeValue(final Locale locale) { + values.remove(locale); + } + + /** + * Checks if a localised string instance has a value for a locale. + * + * @param locale The locale. + * + * @return {@code true} if this localised string has a value for the + * provided locale, {@code false} if not. + */ + public boolean hasValue(final Locale locale) { + return values.containsKey(locale); + } + + /** + * Retrieves all present locales. + * + * @return A {@link Set} containing all locales for which this localised + * string has values. + */ + public Set getAvailableLocales() { + return values.keySet(); + } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/utils/CollectionConverter.java b/ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java similarity index 98% rename from ccm-core/src/com/arsdigita/portation/modules/core/utils/CollectionConverter.java rename to ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java index f47638ae3..35761734e 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/utils/CollectionConverter.java +++ b/ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ -package com.arsdigita.portation.modules.core.utils; +package com.arsdigita.portation.modules.utils; import com.arsdigita.kernel.EmailAddress; import com.arsdigita.kernel.GroupCollection; @@ -38,6 +38,10 @@ import java.util.List; public class CollectionConverter { private static final Logger logger = Logger.getLogger(CollectionConverter.class); + + + + public static List convertParties(PartyCollection partyCollection) { List parties = new ArrayList<>(); if (partyCollection != null) {