CCM NG: Some more work on the entities.
git-svn-id: https://svn.libreccm.org/ccm/jpa@3366 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
c0fe9ee411
commit
bb55de0ef7
|
|
@ -30,6 +30,29 @@
|
|||
</license>
|
||||
</licenses>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jp-digital-snapshots</id>
|
||||
<url>http://archiva.jp-digital.de/repository/jp-digital-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jp-digital-releases</id>
|
||||
<url>http://archiva.jp-digital.de/repository/jp-digital-releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
|
|
|
|||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -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;
|
||||
|
||||
@OneToMany(mappedBy = "category")
|
||||
private List<Categorization> objects;
|
||||
|
||||
private List<CcmObject> owners;
|
||||
private List<CcmObject> objects;
|
||||
@OneToMany(mappedBy = "parent_category")
|
||||
private List<Category> 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<Categorization> getObjects() {
|
||||
return Collections.unmodifiableList(objects);
|
||||
}
|
||||
|
||||
protected void setObjects(final List<Categorization> objects) {
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
protected void addObject(final Categorization object) {
|
||||
objects.add(object);
|
||||
}
|
||||
|
||||
protected void removeObject(final Categorization object) {
|
||||
objects.remove(object);
|
||||
}
|
||||
|
||||
public List<Category> getSubCategories() {
|
||||
return Collections.unmodifiableList(subCategories);
|
||||
}
|
||||
|
||||
public void setSubCategories(final List<Category> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -79,6 +82,9 @@ public class Domain extends CcmObject implements Serializable {
|
|||
@ManyToOne
|
||||
private Category root;
|
||||
|
||||
@OneToMany(mappedBy = "domain_id")
|
||||
private List<DomainOwnership> owners;
|
||||
|
||||
public String getDomainKey() {
|
||||
return domainKey;
|
||||
}
|
||||
|
|
@ -135,6 +141,22 @@ public class Domain extends CcmObject implements Serializable {
|
|||
this.root = root;
|
||||
}
|
||||
|
||||
public List<DomainOwnership> getOwners() {
|
||||
return Collections.unmodifiableList(owners);
|
||||
}
|
||||
|
||||
protected void setOwners(final List<DomainOwnership> 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;
|
||||
|
|
|
|||
|
|
@ -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,9 +35,22 @@ 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 <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
|
|
@ -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<String, Category> ownedCategories;
|
||||
//private Map<String, Category> assignedCategories;
|
||||
/**
|
||||
* Category Domains owned by this {@code CcmObject}.
|
||||
*/
|
||||
@OneToMany(mappedBy = "owner")
|
||||
private List<DomainOwnership> domains;
|
||||
|
||||
/**
|
||||
* Categories which have been assigned to this {@code CcmObject}.
|
||||
*/
|
||||
@OneToMany(mappedBy = "categorizedObject")
|
||||
private List<Categorization> 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<DomainOwnership> 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<DomainOwnership> domains) {
|
||||
this.domains = domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>Internal</strong> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>Internal</strong> 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<Categorization> getCategories() {
|
||||
return Collections.unmodifiableList(categories);
|
||||
}
|
||||
|
||||
protected void setCategories(final List<Categorization> 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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
author: Jens Pelzetter
|
||||
-->
|
||||
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="LibreCCM" transaction-type="JTA">
|
||||
|
||||
<!--
|
||||
Enforce JPA provider
|
||||
Not really necessary here because we don't use any Hibernate
|
||||
specific features, but makes it easier to manage to database
|
||||
creation scripts.
|
||||
-->
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<jta-data-source>
|
||||
java:/comp/env/jdbc/website_study_tool/db
|
||||
</jta-data-source>
|
||||
|
||||
<properties>
|
||||
<property name="hibernate.hbm2ddl.auto" value="verify"/>
|
||||
<property name="hibernate.connection.autocommit" value="false" />
|
||||
<property name="hibernate.id.new_generator_mappings" value="true"/>
|
||||
</properties>
|
||||
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
Loading…
Reference in New Issue