diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index ab9a1f04c..86d70f299 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -30,6 +30,29 @@ + + + jp-digital-snapshots + http://archiva.jp-digital.de/repository/jp-digital-snapshots/ + + false + + + true + + + + jp-digital-releases + http://archiva.jp-digital.de/repository/jp-digital-releases/ + + true + + + false + + + + javax diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Category.java b/ccm-core/src/main/java/org/libreccm/categorization/Category.java index 7ef3ed7f4..494c52b80 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Category.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Category.java @@ -22,6 +22,7 @@ import org.libreccm.core.CcmObject; import java.io.Serializable; import java.util.List; + import javax.persistence.AssociationOverride; import javax.persistence.Column; import javax.persistence.Embedded; @@ -30,8 +31,15 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Table; + import org.libreccm.l10n.LocalizedString; +import java.util.Collections; +import java.util.Objects; + +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + /** * * @author Jens Pelzetter @@ -50,35 +58,226 @@ public class Category extends CcmObject implements Serializable { @Embedded @AssociationOverride( - name = "values", - joinTable = @JoinTable(name = "category_titles", - joinColumns = { - @JoinColumn(name = "object_id")} - )) + name = "values", + joinTable = @JoinTable(name = "category_titles", + joinColumns = { + @JoinColumn(name = "object_id")} + )) private LocalizedString title; - + @Embedded @AssociationOverride( - name = "values", - joinTable = @JoinTable(name = "category_descriptions", - joinColumns = { - @JoinColumn(name = "object_id")} - )) + name = "values", + joinTable = @JoinTable(name = "category_descriptions", + joinColumns = { + @JoinColumn(name = "object_id")} + )) private LocalizedString description; - + @Column(name = "enabled") private boolean enabled; - - @Column(name = "visible") + + @Column(name = "visible") private boolean visible; - + @Column(name = "abstract_category") private boolean abstractCategory; - - private List owners; - private List objects; + @OneToMany(mappedBy = "category") + private List objects; + + @OneToMany(mappedBy = "parent_category") private List subCategories; + + @ManyToOne private Category parentCategory; + @Column(name = "category_order") + private long categoryOrder; + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(final String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public LocalizedString getTitle() { + return title; + } + + public void setTitle(final LocalizedString title) { + this.title = title; + } + + public LocalizedString getDescription() { + return description; + } + + public void setDescription(final LocalizedString description) { + this.description = description; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(final boolean enabled) { + this.enabled = enabled; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(final boolean visible) { + this.visible = visible; + } + + public boolean isAbstractCategory() { + return abstractCategory; + } + + public void setAbstractCategory(final boolean abstractCategory) { + this.abstractCategory = abstractCategory; + } + + public List getObjects() { + return Collections.unmodifiableList(objects); + } + + protected void setObjects(final List objects) { + this.objects = objects; + } + + protected void addObject(final Categorization object) { + objects.add(object); + } + + protected void removeObject(final Categorization object) { + objects.remove(object); + } + + public List getSubCategories() { + return Collections.unmodifiableList(subCategories); + } + + public void setSubCategories(final List subCategories) { + this.subCategories = subCategories; + } + + protected void addSubCategory(final Category category) { + subCategories.add(category); + } + + protected void removeSubCategory(final Category category) { + subCategories.remove(category); + } + + public Category getParentCategory() { + return parentCategory; + } + + public void setParentCategory(final Category parentCategory) { + this.parentCategory = parentCategory; + } + + public long getCategoryOrder() { + return categoryOrder; + } + + public void setCategoryOrder(final long categoryOrder) { + this.categoryOrder = categoryOrder; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 23 * hash + Objects.hashCode(uniqueId); + hash = 23 * hash + Objects.hashCode(name); + hash = 23 * hash + Objects.hashCode(title); + hash = 23 * hash + Objects.hashCode(description); + hash = 23 * hash + (enabled ? 1 : 0); + hash = 23 * hash + (visible ? 1 : 0); + hash = 23 * hash + (abstractCategory ? 1 : 0); + hash = 23 * hash + Objects.hashCode(parentCategory); + hash = 23 * hash + (int) (categoryOrder ^ (categoryOrder >>> 32)); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Category other = (Category) obj; + if (!other.canEqual(this)) { + return false; + } + + if (!Objects.equals(uniqueId, other.getUniqueId())) { + return false; + } + if (!Objects.equals(name, other.getName())) { + return false; + } + if (!Objects.equals(title, other.getTitle())) { + return false; + } + if (!Objects.equals(description, other.getDescription())) { + return false; + } + if (enabled != other.isEnabled()) { + return false; + } + if (visible != other.isVisible()) { + return false; + } + if (abstractCategory != other.isAbstractCategory()) { + return false; + } + if (!Objects.equals(parentCategory, other.getParentCategory())) { + return false; + } + return categoryOrder == other.getCategoryOrder(); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof Category; + } + + @Override + public String toString(final String data) { + return String.format(", uniqueId = %s, " + + "name = \"%s\", " + + "title = %s, " + + "enabled = %b, " + + "visible = %b, " + + "abstractCategory = %b, " + + "parentCategory = %s, " + + "categoryOrder = %d%s", + uniqueId, + name, + title.toString(), + enabled, + visible, + abstractCategory, + parentCategory, + categoryOrder, + data); + } + } diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java index 8ea2ec894..b962df84d 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java @@ -23,7 +23,9 @@ import org.libreccm.l10n.LocalizedString; import java.io.Serializable; import java.net.URI; +import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.Objects; import javax.persistence.AssociationOverride; @@ -33,6 +35,7 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -78,6 +81,9 @@ public class Domain extends CcmObject implements Serializable { @ManyToOne private Category root; + + @OneToMany(mappedBy = "domain_id") + private List owners; public String getDomainKey() { return domainKey; @@ -135,6 +141,22 @@ public class Domain extends CcmObject implements Serializable { this.root = root; } + public List getOwners() { + return Collections.unmodifiableList(owners); + } + + protected void setOwners(final List owners) { + this.owners = owners; + } + + protected void addOwner(final DomainOwnership owner) { + owners.add(owner); + } + + protected void removeOwner(final DomainOwnership owner) { + owners.remove(owner); + } + @Override public int hashCode() { int hash = 3; diff --git a/ccm-core/src/main/java/org/libreccm/core/CcmObject.java b/ccm-core/src/main/java/org/libreccm/core/CcmObject.java index bebddf257..1856700bb 100644 --- a/ccm-core/src/main/java/org/libreccm/core/CcmObject.java +++ b/ccm-core/src/main/java/org/libreccm/core/CcmObject.java @@ -18,7 +18,14 @@ */ package org.libreccm.core; +import org.libreccm.categorization.Categorization; +import org.libreccm.categorization.Category; +import org.libreccm.categorization.DomainOwnership; + import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Objects; import javax.persistence.Column; @@ -28,10 +35,23 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.OneToMany; import javax.persistence.Table; /** - * + * 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 Jens Pelzetter */ @Entity @@ -41,16 +61,35 @@ public class CcmObject implements Serializable { private static final long serialVersionUID = 201504261329L; + /** + * The ID/primary key for the {@code CcmObject}. Please note that it is + * not necessary to define an additional ID on classes which extend this + * class. + */ @Id @Column(name = "object_id") @GeneratedValue(strategy = GenerationType.AUTO) private long objectId; + /** + * A human readable name identifying this {@code CcmObject} + */ @Column(name = "display_name") private String displayName; - //private Map ownedCategories; - //private Map assignedCategories; + /** + * Category Domains owned by this {@code CcmObject}. + */ + @OneToMany(mappedBy = "owner") + private List domains; + + /** + * Categories which have been assigned to this {@code CcmObject}. + */ + @OneToMany(mappedBy = "categorizedObject") + private List categories; + + public long getObjectId() { return objectId; } @@ -67,6 +106,67 @@ public class CcmObject implements Serializable { this.displayName = displayName; } + public CcmObject() { + domains = new ArrayList<>(); + categories = new ArrayList<>(); + } + + /** + * Getter for the list of owned domains. + * + * @return An unmodifiable list of the domain ownerships of this + * {@code CcmObject}. Might be {@code null} or empty. + */ + public List getDomains() { + return Collections.unmodifiableList(domains); + } + + /** + * Setter for the list of domain ownerships, only for use by JPA. + * + * @param domains A list of domain ownerships. + */ + protected void setDomains(final List domains) { + this.domains = domains; + } + + /** + * Internal method for adding a domain ownership. + * User should use the appropriate methods of the {@code CategoryManager} + * class. + * + * @param domain The domain ownership to add. + */ + protected void addDomain(final DomainOwnership domain) { + domains.add(domain); + } + + /** + * Internal method for removing a domain ownership. + * User should use the appropriate methods of the {@code CategoryManager} + * + * @param domain + */ + protected void removeDomain(final DomainOwnership domain) { + domains.remove(domain); + } + + public List getCategories() { + return Collections.unmodifiableList(categories); + } + + protected void setCategories(final List categories) { + this.categories = categories; + } + + protected void addCategory(final Categorization category) { + categories.add(category); + } + + protected void removeCategory(final Categorization category) { + categories.remove(category); + } + @Override public int hashCode() { int hash = 5; diff --git a/ccm-core/src/main/resources/META-INF/persistence.xml b/ccm-core/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..e85eb1f78 --- /dev/null +++ b/ccm-core/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,34 @@ + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + + + java:/comp/env/jdbc/website_study_tool/db + + + + + + + + + + + \ No newline at end of file