image of categorization of CCM_NG in Trunk is finished

git-svn-id: https://svn.libreccm.org/ccm/trunk@4172 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2016-06-22 13:27:31 +00:00
parent d91eb7d386
commit 22f36f0bb5
8 changed files with 443 additions and 48 deletions

View File

@ -24,8 +24,5 @@ package com.arsdigita.portation;
*/
public interface Identifiable {
String getTrunkClass();
void setTrunkClass(String trunkClass);
AbstractMarshaller<? extends Identifiable> getMarshaller();
}

View File

@ -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;

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 6/15/16
*/
public class Categorization implements Identifiable {
public String trunkClass;
private long categorizationId;
private Category category;
private CcmObject categorizedObject;
@ -38,22 +41,68 @@ public class Categorization implements Identifiable {
private long objectOrder;
public Categorization() {
public Categorization(ACSObject acsObject, Category category) {
this.categorizationId = category.getObjectId() +
acsObject.getID().longValue();
// Todo: generatedID
this.category = category;
this.categorizedObject = new CcmObject(acsObject);
this.index = false;
this.categoryOrder = this.categorizedObject.getCategories().size() + 1;
this.objectOrder = this.category.getObjects().size() + 1;
}
@Override
public String getTrunkClass() {
return this.trunkClass;
}
@Override
public void setTrunkClass(String trunkClass) {
this.trunkClass = trunkClass;
}
@Override
public AbstractMarshaller<? extends Identifiable> getMarshaller() {
return new CategorizationMarshaller();
}
public long getCategorizationId() {
return categorizationId;
}
public void setCategorizationId(long categorizationId) {
this.categorizationId = categorizationId;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public CcmObject getCategorizedObject() {
return categorizedObject;
}
public void setCategorizedObject(CcmObject categorizedObject) {
this.categorizedObject = categorizedObject;
}
public boolean isIndex() {
return index;
}
public void setIndex(boolean index) {
this.index = index;
}
public long getCategoryOrder() {
return categoryOrder;
}
public void setCategoryOrder(long categoryOrder) {
this.categoryOrder = categoryOrder;
}
public long getObjectOrder() {
return objectOrder;
}
public void setObjectOrder(long objectOrder) {
this.objectOrder = objectOrder;
}
}

View File

@ -18,14 +18,28 @@
*/
package com.arsdigita.portation.modules.core.categorization;
import com.arsdigita.categorization.CategorizedCollection;
import com.arsdigita.categorization.CategoryLocalizationCollection;
import com.arsdigita.portation.AbstractMarshaller;
import com.arsdigita.portation.Identifiable;
import com.arsdigita.portation.modules.core.categorization.utils.CollectionConverter;
import com.arsdigita.portation.modules.core.core.CcmObject;
import com.arsdigita.portation.modules.core.l10n.LocalizedString;
import java.util.List;
import java.util.Locale;
import static com.arsdigita.portation.modules.core.categorization.utils.CollectionConverter.convertCategories;
/**
* The category entity represents a single category. Each category is part of a
* {@code Domain}. A category can be assigned to multiple {@link CcmObject}s.
*
* In the old structure the properties of this class were split between the
* {@code Category} entity from {@code ccm-core} and the {@code Term} entity
* from {@code ccm-ldn-terms}. This class unifies the properties of these two
* classes.
*
* @author <a href="mailto:tosmers@uni-bremen.de>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<Categorization> objects;
private List<Category> 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<? extends Identifiable> 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<Categorization> getObjects() {
return objects;
}
public void setObjects(List<Categorization> objects) {
this.objects = objects;
}
public List<Category> getSubCategories() {
return subCategories;
}
public void setSubCategories(List<Category> 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;
}
}

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/22/16
*/
public class CollectionConverter {
public static final Logger logger = Logger.getLogger(CollectionConverter.class);
/**
* Converts CategorizationCollection of Trunk into a list of
* Categorizations of CCM_NG.
*
* @param categorizedCollection
* @param category
* @return
*/
public static List<Categorization> convertCategorizations
(CategorizedCollection categorizedCollection, Category category) {
List<Categorization> categorizations = new ArrayList<>();
if (categorizedCollection != null) {
while (categorizedCollection.next()) {
categorizations.add(new Categorization(categorizedCollection
.getACSObject(), category));
}
categorizedCollection.close();
} else {
logger.error("Failed to convertCategories, cause " +
"categoryCollection is null.");
}
return categorizations;
}
/**
* Converts CategoryCollection of Trunk into list of Categories of CCM_NG.
*
* @param categoryCollection
* @return
*/
public static List<Category> convertCategories(CategoryCollection
categoryCollection) {
List<Category> 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;
}
}

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 6/15/16
*/
public class CcmObject implements Identifiable {
public String trunkClass;
private long objectId;
private String uuid;
private String displayName;
@ -40,23 +53,56 @@ public class CcmObject implements Identifiable {
private List<Categorization> categories;
public CcmObject() {
}
@Override
public String getTrunkClass() {
return null;
}
@Override
public void setTrunkClass(String trunkClass) {
public CcmObject(final ACSObject trunkObject) {
this.objectId = trunkObject.getID().longValue();
this.uuid = null;
this.displayName = trunkObject.getDisplayName();
this.permissions = null;// Todo: mapping
this.categories = null;// Todo: mapping
}
@Override
public AbstractMarshaller<? extends Identifiable> getMarshaller() {
return new CcmObjectMarshaller();
}
public long getObjectId() {
return objectId;
}
public void setObjectId(long objectId) {
this.objectId = objectId;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public List<Permission> getPermissions() {
return permissions;
}
public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
public List<Categorization> getCategories() {
return categories;
}
public void setCategories(List<Categorization> categories) {
this.categories = categories;
}
}

View File

@ -21,36 +21,123 @@ package com.arsdigita.portation.modules.core.l10n;
import com.arsdigita.portation.AbstractMarshaller;
import com.arsdigita.portation.Identifiable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* A helper class for localisable string properties. This class is declared as
* embeddable, so that it can be used in every other entity. The localised
* values are stored in a {@link Map}. This class is <em>not</em> designed to be
* overwritten. But because it is an entity class we can't make the class final.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 6/15/16
*/
public class LocalizedString implements Identifiable {
private String trunkClass;
private Map<Locale, String> 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<? extends Identifiable> getMarshaller() {
return new LocalizedStringMarshaller();
}
/**
* Get all localised values.
*
* @return A unmodifiable {@code Map} containing all localised values of
* this localised string.
*/
public Map<Locale, String> 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<Locale, String> 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<Locale> getAvailableLocales() {
return values.keySet();
}
}

View File

@ -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<Party> convertParties(PartyCollection partyCollection) {
List<Party> parties = new ArrayList<>();
if (partyCollection != null) {