diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index 0ead99f22..e16ff2f4e 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -64,6 +64,12 @@ hamcrest-library test + + + nl.jqno.equalsverifier + equalsverifier + test + 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 58ea15995..97e037951 100644 --- a/ccm-core/src/main/java/org/libreccm/core/CcmObject.java +++ b/ccm-core/src/main/java/org/libreccm/core/CcmObject.java @@ -356,7 +356,8 @@ public class CcmObject implements Serializable { public String toString(final String data) { return String.format( "%s{ " - + "objectId = %d; displayName = \"%s\"" + + "objectId = %d, " + + "displayName = \"%s\"" + "%s" + " }", super.toString(), diff --git a/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java b/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java index 284a5508a..70b9573cb 100644 --- a/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java +++ b/ccm-core/src/main/java/org/libreccm/core/EmailAddress.java @@ -22,6 +22,7 @@ import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotBlank; import java.io.Serializable; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Embeddable; @@ -71,6 +72,41 @@ public class EmailAddress implements Serializable { this.verified = verified; } + @Override + public int hashCode() { + int hash = 5; + hash = 79 * hash + Objects.hashCode(eMailAddress); + hash = 79 * hash + (bouncing ? 1 : 0); + hash = 79 * hash + (verified ? 1 : 0); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final EmailAddress other = (EmailAddress) obj; + if (!other.canEqual(this)) { + return false; + } + + if (!Objects.equals(eMailAddress, other.getEmailAddress())) { + return false; + } + if (bouncing != other.isBouncing()) { + return false; + } + return verified == other.isVerified(); + } + + public boolean canEqual(final Object obj) { + return obj instanceof EmailAddress; + } + @Override public String toString() { return String.format("%s{ " diff --git a/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java b/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java index eb5c57c62..44d23f1e0 100644 --- a/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java +++ b/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java @@ -96,13 +96,13 @@ public class GroupMembership implements Serializable { return false; } - if (this.membershipId != other.membershipId) { + if (this.membershipId != other.getMembershipId()) { return false; } - if (!Objects.equals(this.group, other.group)) { + if (!Objects.equals(this.group, other.getGroup())) { return false; } - return Objects.equals(this.user, other.user); + return Objects.equals(this.user, other.getUser()); } public boolean canEqual(final Object obj) { diff --git a/ccm-core/src/main/java/org/libreccm/formbuilder/Component.java b/ccm-core/src/main/java/org/libreccm/formbuilder/Component.java new file mode 100644 index 000000000..483cc92fe --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/formbuilder/Component.java @@ -0,0 +1,217 @@ +/* + * 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 org.libreccm.formbuilder; + +import org.libreccm.core.CcmObject; +import org.libreccm.l10n.LocalizedString; + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import javax.persistence.AssociationOverride; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "formbuilder_components") +public class Component extends CcmObject implements Serializable { + + private static final long serialVersionUID = 1787173100367982069L; + + @Column(name = "admin_name") + private String adminName; + + @Embedded + @AssociationOverride( + name = "values", + joinTable = @JoinTable(name = "formbuilder_component_descriptions", + joinColumns = { + @JoinColumn(name = "component_id")})) + private LocalizedString description; + + @Column(name = "attribute_string") + private String attributeString; + + @Column(name = "active") + private boolean active; + + @ManyToOne + private Component parentComponent; + + @OneToMany(mappedBy = "parentComponent") + private List childComponents; + + @Column(name = "component_order") + private long componentOrder; + + @Column(name = "selected") + private boolean selected; + + public String getAdminName() { + return adminName; + } + + public void setAdminName(final String adminName) { + this.adminName = adminName; + } + + public LocalizedString getDescription() { + return description; + } + + public void setDescription(final LocalizedString description) { + this.description = description; + } + + public String getAttributeString() { + return attributeString; + } + + public void setAttributeString(final String attributeString) { + this.attributeString = attributeString; + } + + public boolean isActive() { + return active; + } + + public void setActive(final boolean active) { + this.active = active; + } + + public Component getParentComponent() { + return parentComponent; + } + + protected void setParentComponent(final Component parentComponent) { + this.parentComponent = parentComponent; + } + + public List getChildComponents() { + return Collections.unmodifiableList(childComponents); + } + + protected void setChildComponents(final List childComponents) { + this.childComponents = childComponents; + } + + public long getComponentOrder() { + return componentOrder; + } + + public void setComponentOrder(final long componentOrder) { + this.componentOrder = componentOrder; + } + + public boolean isSelected() { + return selected; + } + + public void setSelected(final boolean selected) { + this.selected = selected; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 53 * hash + Objects.hashCode(adminName); + hash = 53 * hash + Objects.hashCode(description); + hash = 53 * hash + Objects.hashCode(attributeString); + hash = 53 * hash + (active ? 1 : 0); + hash = 53 * hash + Objects.hashCode(parentComponent); + hash = 53 * hash + Objects.hashCode(childComponents); + hash = 53 * hash + (int) (componentOrder ^ (componentOrder >>> 32)); + hash = 53 * hash + (selected ? 1 : 0); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Component other = (Component) obj; + if (!other.canEqual(this)) { + return false; + } + + if (!Objects.equals(adminName, other.getAdminName())) { + return false; + } + if (!Objects.equals(description, other.getDescription())) { + return false; + } + if (!Objects.equals(attributeString, other.getAttributeString())) { + return false; + } + if (active != other.isActive()) { + return false; + } + if (!Objects.equals(parentComponent, other.getParentComponent())) { + return false; + } + if (!Objects.equals(childComponents, other.getChildComponents())) { + return false; + } + if (componentOrder != other.getComponentOrder()) { + return false; + } + return selected == other.isSelected(); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof Component; + } + + @Override + public String toString(final String data) { + return super.toString(String.format(", adminName = \"%s\", " + + "description = %s, " + + "attributeString = \"%s\", " + + "active = %b, " + + "parentComponent = %s, " + + "componentOrder, " + + "selected = %b%s", + adminName, + Objects.toString(description), + attributeString, + active, + Objects.toString(parentComponent), + componentOrder, + selected, + data)); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/formbuilder/Listener.java b/ccm-core/src/main/java/org/libreccm/formbuilder/Listener.java new file mode 100644 index 000000000..ccb34856f --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/formbuilder/Listener.java @@ -0,0 +1,122 @@ +/* + * 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 org.libreccm.formbuilder; + +import org.libreccm.core.CcmObject; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "formbuilder_listeners") +public class Listener extends CcmObject implements Serializable { + + private static final long serialVersionUID = 9030104813240364500L; + + @Column(name = "class_name") + private String className; + + @Column(name = "attribute_string") + private String attributeString; + + @ManyToOne + private Widget widget; + + public String getClassName() { + return className; + } + + public void setClassName(final String className) { + this.className = className; + } + + public String getAttributeString() { + return attributeString; + } + + public void setAttributeString(final String attributeString) { + this.attributeString = attributeString; + } + + public Widget getWidget() { + return widget; + } + + protected void setWidget(final Widget widget) { + this.widget = widget; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 59 * hash + Objects.hashCode(className); + hash = 59 * hash + Objects.hashCode(attributeString); + hash = 59 * hash + Objects.hashCode(widget); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Listener other = (Listener) obj; + if (other.canEqual(this)) { + return false; + } + + if (!Objects.equals(className, other.getClassName())) { + return false; + } + if (!Objects.equals(attributeString, other.getAttributeString())) { + return false; + } + if (!Objects.equals(widget, other.getWidget())) { + return false; + } + return true; + } + + @Override + public boolean canEqual(Object obj) { + return obj instanceof Listener; + } + + @Override + public String toString(final String data) { + return super.toString(String.format(", className = \"%s\", " + + "attributeString = \"%s\"%s", + className, + attributeString, + data)); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/formbuilder/Widget.java b/ccm-core/src/main/java/org/libreccm/formbuilder/Widget.java new file mode 100644 index 000000000..0e90577ba --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/formbuilder/Widget.java @@ -0,0 +1,158 @@ +/* + * 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 org.libreccm.formbuilder; + + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "formbuilder_widgets") +public class Widget extends Component implements Serializable { + + private static final long serialVersionUID = 1057792450655098288L; + + @Column(name = "parameter_name") + private String parameterName; + + @Column(name = "parameter_model") + private String parameterModel; + + @Column(name = "default_value") + private String defaultValue; + + @OneToOne + private WidgetLabel label; + + @OneToMany(mappedBy = "widget") + private List listeners; + + public String getParameterName() { + return parameterName; + } + + public void setParameterName(final String parameterName) { + this.parameterName = parameterName; + } + + public String getParameterModel() { + return parameterModel; + } + + public void setParameterModel(final String parameterModel) { + this.parameterModel = parameterModel; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(final String defaultValue) { + this.defaultValue = defaultValue; + } + + public WidgetLabel getLabel() { + return label; + } + + protected void setLabel(final WidgetLabel label) { + this.label = label; + } + + public List getListeners() { + return Collections.unmodifiableList(listeners); + } + + protected void setListeners(final List listeners) { + this.listeners = listeners; + } + + protected void addListener(final Listener listener) { + listeners.add(listener); + } + + protected void removeListener(final Listener listener) { + listeners.remove(listener); + } + + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 17 * hash + Objects.hashCode(parameterName); + hash = 17 * hash + Objects.hashCode(parameterModel); + hash = 17 * hash + Objects.hashCode(defaultValue); + hash = 17 * hash + Objects.hashCode(label); + hash = 17 * hash + Objects.hashCode(listeners); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Widget other = (Widget) obj; + if (!other.canEqual(this)) { + return false; + } + + if (!Objects.equals(parameterName, other.getParameterName())) { + return false; + } + if (!Objects.equals(parameterModel, other.getParameterModel())) { + return false; + } + if (!Objects.equals(defaultValue, other.getDefaultValue())) { + return false; + } + if (!Objects.equals(label, other.getLabel())) { + return false; + } + + return Objects.equals(listeners, other.getListeners()); + } + + @Override + public String toString(final String data) { + return super.toString(String.format(", parameterName = \"%s\", " + + "parameterModel = \"%s\", " + + "defaultValue = \"%s\"%s", + parameterName, + parameterModel, + defaultValue, + data)); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/formbuilder/WidgetLabel.java b/ccm-core/src/main/java/org/libreccm/formbuilder/WidgetLabel.java new file mode 100644 index 000000000..d6f711567 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/formbuilder/WidgetLabel.java @@ -0,0 +1,78 @@ +/* + * 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 org.libreccm.formbuilder; + + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.Entity; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "formbuilder_widget_labels") +public class WidgetLabel extends Component implements Serializable { + + private static final long serialVersionUID = -2939505715812565159L; + + @OneToOne + private Widget widget; + + public Widget getWidget() { + return widget; + } + + protected void setWidget(final Widget widget) { + this.widget = widget; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 19 * hash + Objects.hashCode(widget); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final WidgetLabel other = (WidgetLabel) obj; + if (!other.canEqual(this)) { + return false; + } + + return Objects.equals(widget, other.getWidget()); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof WidgetLabel; + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/core/EqualsTest.java b/ccm-core/src/test/java/org/libreccm/core/EqualsTest.java new file mode 100644 index 000000000..8121d1ab1 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/core/EqualsTest.java @@ -0,0 +1,156 @@ +/* + * 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 org.libreccm.core; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.libreccm.tests.categories.UnitTest; + +/** + * + * @author Jens Pelzetter + */ +@Category(UnitTest.class) +public class EqualsTest { + + public EqualsTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void verifyCcmObject() { + EqualsVerifier + .forClass(CcmObject.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyEmailAddress() { + EqualsVerifier + .forClass(EmailAddress.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyGroupMembership() { + EqualsVerifier + .forClass(GroupMembership.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyParty() { + EqualsVerifier + .forClass(Party.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyPermission() { + EqualsVerifier + .forClass(Permission.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyPersonName() { + EqualsVerifier + .forClass(PersonName.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyPrivilege() { + EqualsVerifier + .forClass(Privilege.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyResource() { + EqualsVerifier + .forClass(Resource.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyRole() { + EqualsVerifier + .forClass(Role.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyUser() { + EqualsVerifier + .forClass(User.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + + @Test + public void verifyUserGroup() { + EqualsVerifier + .forClass(UserGroup.class) + .suppress(Warning.STRICT_INHERITANCE) + .withRedefinedSuperclass() + .verify(); + } + +}