From ba30f3d60ed745192f93e76dcf8d37fcead55f78 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Mon, 19 Aug 2019 20:26:55 +0200 Subject: [PATCH] Assets for the publications modulAssets for the publications modulee --- .gitignore | 4 +- pom.xml | 1 + sci-publications/pom.xml | 311 ++++++++++++++++++ .../SciPublicationsConstants.java | 16 + .../publications/assets/Journal.java | 175 ++++++++++ .../publications/assets/Publisher.java | 109 ++++++ .../SecurityEntitiesPrefabProvider.java | 53 +++ .../assets/EqualsAndHashCodeTest.java | 171 ++++++++++ 8 files changed, 839 insertions(+), 1 deletion(-) create mode 100644 sci-publications/pom.xml create mode 100644 sci-publications/src/main/java/org/scientificcms/SciPublicationsConstants.java create mode 100644 sci-publications/src/main/java/org/scientificcms/publications/assets/Journal.java create mode 100644 sci-publications/src/main/java/org/scientificcms/publications/assets/Publisher.java create mode 100644 sci-publications/src/test/java/org/libreccm/security/SecurityEntitiesPrefabProvider.java create mode 100644 sci-publications/src/test/java/org/scientificcms/publications/assets/EqualsAndHashCodeTest.java diff --git a/.gitignore b/.gitignore index cc4a18c..a656092 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /sci-types-project/target/ -/scientificcms/target/ \ No newline at end of file +/scientificcms/target/ +/sci-publications/nbproject/ +/sci-publications/target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index aab020b..7b74901 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ sci-types-project scientificcms + sci-publications diff --git a/sci-publications/pom.xml b/sci-publications/pom.xml new file mode 100644 index 0000000..729b939 --- /dev/null +++ b/sci-publications/pom.xml @@ -0,0 +1,311 @@ + + + + 4.0.0 + + UTF-8 + ${maven.build.timestamp} + yyyy-MM-dd'T'HH:mm:ss'Z'Z + + + + org.scientificcms + scientificcms-parent + 7.0.0-SNAPSHOT + + + org.scientificcms + sci-publications + 7.0.0-SNAPSHOT + + ScientificCMS Publications + + + + javax + javaee-api + jar + provided + + + + org.libreccm + ccm-core + ${project.parent.version} + provided + + + + org.librecms + ccm-cms + ${project.parent.version} + provided + + + + org.hibernate + hibernate-core + + + + org.hibernate + hibernate-envers + provided + + + + org.hibernate + hibernate-validator + + + + junit + junit + test + + + + org.hamcrest + hamcrest-core + test + + + org.hamcrest + hamcrest-library + test + + + + org.libreccm + ccm-testutils + ${project.parent.version} + test + + + + nl.jqno.equalsverifier + equalsverifier + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.extension + arquillian-persistence-dbunit + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + + + + com.h2database + h2 + test + + + + + + + sci-publications + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + true + true + ${project.build.sourceEncoding} + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + org.libreccm.tests.categories.UnitTest + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + + + + de.jpdigital + hibernate53-ddl-maven-plugin + + + h2 + oracle12c + postgresql9 + + + org.libreccm + org.librecms + org.scientificcms + + true + + + + + gen-ddl + + process-classes + + + + + + + + src/main/resources + true + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + true + true + + http://docs.oracle.com/javase/7/docs/api/ + http://docs.oracle.com/javaee/7/api/ + http://docs.jboss.org/hibernate/orm/4.3/javadocs/ + + private + true + UTF-8 + UTF-8 + UTF-8 + true + true + true + true + false + org.jboss.apiviz.APIviz + + org.jboss.apiviz + apiviz + 1.3.2.GA + + true + + -sourceclasspath ${project.build.outputDirectory} + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.5 + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.18.1 + + + org.jacoco + jacoco-maven-plugin + 0.7.5.201505241946 + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.1 + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.7 + + true + utf-8 + 1.8 + + /rulesets/java/basic.xml + /rulesets/java/braces.xml + /rulesets/java/clone.xml + /rulesets/java/codesize.xml + /rulesets/java/design.xml + /rulesets/java/empty.xml + /rulesets/java/finalizers.xml + /rulesets/java/imports.xml + /rulesets/java/junit.xml + /rulesets/java/naming.xml + /rulesets/java/optimizations.xml + /rulesets/java/strictexception.xml + /rulesets/java/strings.xml + /rulesets/java/sunsecure.xml + /rulesets/java/typeresolution.xml + /rulesets/java/unnecessary.xml + /rulesets/java/unusedcode.xml + + + + + org.codehaus.mojo + javancss-maven-plugin + 2.1 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.8 + + + + dependencies + licenses + + + + + false + + + + + + diff --git a/sci-publications/src/main/java/org/scientificcms/SciPublicationsConstants.java b/sci-publications/src/main/java/org/scientificcms/SciPublicationsConstants.java new file mode 100644 index 0000000..b377345 --- /dev/null +++ b/sci-publications/src/main/java/org/scientificcms/SciPublicationsConstants.java @@ -0,0 +1,16 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.scientificcms; + +/** + * + * @author Jens Pelzetter + */ +public class SciPublicationsConstants { + + public static final String DB_SCHEMA = "SCI_PUBLICATIONS"; + +} diff --git a/sci-publications/src/main/java/org/scientificcms/publications/assets/Journal.java b/sci-publications/src/main/java/org/scientificcms/publications/assets/Journal.java new file mode 100644 index 0000000..9846c94 --- /dev/null +++ b/sci-publications/src/main/java/org/scientificcms/publications/assets/Journal.java @@ -0,0 +1,175 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.scientificcms.publications.assets; + +import org.hibernate.envers.Audited; +import org.libreccm.l10n.LocalizedString; +import org.librecms.contentsection.Asset; + +import java.util.Objects; + +import javax.persistence.AssociationOverride; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Table; + +import static org.scientificcms.SciPublicationsConstants.*; + +/** + * Asset for storing informations about a journal. + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "JOURNALS", schema = DB_SCHEMA) +@Audited +public class Journal extends Asset { + + private static final long serialVersionUID = 1L; + + /** + * Year in which the journal was published first. + */ + private Integer firstYear; + + /** + * Year in which the journal was published last + */ + private Integer lastYear; + + /** + * The ISSN of the journal. + */ + private String issn; + + /** + * A short description of the journal. + */ + @Embedded + @AssociationOverride( + name = "values", + joinTable = @JoinTable(name = "JOURNAL_DESCRIPTIONS", + schema = DB_SCHEMA, + joinColumns = { + @JoinColumn(name = "OBJECT_ID") + }) + ) + private LocalizedString description; + + /** + * The usual symbol/abbrevation used to refer to the journal. + */ + private String symbol; + + public Integer getFirstYear() { + return firstYear; + } + + public void setFirstYear(final Integer firstYear) { + this.firstYear = firstYear; + } + + public Integer getLastYear() { + return lastYear; + } + + public void setLastYear(final Integer lastYear) { + this.lastYear = lastYear; + } + + public String getIssn() { + return issn; + } + + public void setIssn(final String issn) { + this.issn = issn; + } + + public LocalizedString getDescription() { + return description; + } + + public void setDescription(final LocalizedString description) { + this.description = description; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(final String symbol) { + this.symbol = symbol; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 73 * hash + Objects.hashCode(firstYear); + hash = 73 * hash + Objects.hashCode(lastYear); + hash = 73 * hash + Objects.hashCode(issn); + hash = 73 * hash + Objects.hashCode(description); + hash = 73 * hash + Objects.hashCode(symbol); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof Journal)) { + return false; + } + final Journal other = (Journal) obj; + if (!other.canEqual(this)) { + return false; + } + if (!Objects.equals(firstYear, other.getFirstYear())) { + return false; + } + if (!Objects.equals(lastYear, other.getLastYear())) { + return false; + } + if (!Objects.equals(issn, other.getIssn())) { + return false; + } + if (!Objects.equals(symbol, other.getSymbol())) { + return false; + } + return Objects.equals(description, other.getDescription()); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof Journal; + } + + @Override + public String toString(final String data) { + + return super.toString(String.format( + ", firstYear = %s, " + + "lastYear = %s, " + + "issn = \"%s\", " + + "symbol = \"%s\", " + + "description = %s%s", + Objects.toString(firstYear), + Objects.toString(lastYear), + issn, + symbol, + description, + data)); + } + +} diff --git a/sci-publications/src/main/java/org/scientificcms/publications/assets/Publisher.java b/sci-publications/src/main/java/org/scientificcms/publications/assets/Publisher.java new file mode 100644 index 0000000..e497fd9 --- /dev/null +++ b/sci-publications/src/main/java/org/scientificcms/publications/assets/Publisher.java @@ -0,0 +1,109 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.scientificcms.publications.assets; + +import org.hibernate.envers.Audited; +import org.librecms.contentsection.Asset; + +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import static org.scientificcms.SciPublicationsConstants.*; + +/** + * An asset for storing the informations about a publisher required to create + * correct bibliographic references. + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "PUBLISHERS", schema = DB_SCHEMA) +@Audited +public class Publisher extends Asset { + + private static final long serialVersionUID = 1L; + + /** + * Name of the publisher. The title of the asset is only for internal use, + * this property should be used for name of the publisher which is displayed + * on public pages. + */ + @Column(name = "NAME", length = 2048, nullable = false) + private String name; + + /** + * The place of the publisher. + */ + @Column(name = "PLACE", length = 2048) + private String place; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getPlace() { + return place; + } + + public void setPlace(final String place) { + this.place = place; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 29 * hash + Objects.hashCode(name); + hash = 29 * hash + Objects.hashCode(place); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof Publisher)) { + return false; + } + final Publisher other = (Publisher) obj; + if (!other.canEqual(this)) { + return false; + } + if (!Objects.equals(name, other.getName())) { + return false; + } + return Objects.equals(place, other.getPlace()); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof Publisher; + } + + @Override + public String toString(final String data) { + return super.toString(String.format( + ", name = \"%s\", " + + "place = \"%s\"%s", + name, + place, + data)); + } + +} diff --git a/sci-publications/src/test/java/org/libreccm/security/SecurityEntitiesPrefabProvider.java b/sci-publications/src/test/java/org/libreccm/security/SecurityEntitiesPrefabProvider.java new file mode 100644 index 0000000..c4f826c --- /dev/null +++ b/sci-publications/src/test/java/org/libreccm/security/SecurityEntitiesPrefabProvider.java @@ -0,0 +1,53 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.libreccm.security; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * + * @author Jens Pelzetter + */ +public final class SecurityEntitiesPrefabProvider { + + private SecurityEntitiesPrefabProvider() { + // Nothing + } + + public static void addPrefabEntities(final EqualsVerifier verifier) { + + final Role role1 = new Role(); + role1.setRoleId(2001); + role1.setName("role1"); + + final Role role2 = new Role(); + role2.setRoleId(2002); + role2.setName("role2"); + + verifier.withPrefabValues(Role.class, role1, role2); + + final Group group1 = new Group(); + group1.setPartyId(3001); + group1.setName("group1"); + + final Group group2 = new Group(); + group2.setPartyId(3002); + group2.setName("group2"); + + verifier.withPrefabValues(Group.class, group1, group2); + + final User user1 = new User(); + user1.setPartyId(4001); + user1.setName("user1"); + + final User user2 = new User(); + user2.setPartyId(4002); + user2.setName("user2"); + + verifier.withPrefabValues(User.class, user1, user2); + } + +} diff --git a/sci-publications/src/test/java/org/scientificcms/publications/assets/EqualsAndHashCodeTest.java b/sci-publications/src/test/java/org/scientificcms/publications/assets/EqualsAndHashCodeTest.java new file mode 100644 index 0000000..6accc3f --- /dev/null +++ b/sci-publications/src/test/java/org/scientificcms/publications/assets/EqualsAndHashCodeTest.java @@ -0,0 +1,171 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.scientificcms.publications.assets; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.libreccm.categorization.Category; +import org.libreccm.core.CcmObject; +import org.libreccm.l10n.LocalizedString; +import org.libreccm.security.SecurityEntitiesPrefabProvider; +import org.libreccm.tests.categories.UnitTest; +import org.libreccm.testutils.EqualsVerifier; +import org.libreccm.workflow.Workflow; +import org.librecms.assets.Organization; +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentType; +import org.librecms.contentsection.ItemAttachment; +import org.librecms.lifecycle.Lifecycle; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; + +/** + * + * @author Jens Pelzetter + */ +@RunWith(Parameterized.class) +@org.junit.experimental.categories.Category(UnitTest.class) +public class EqualsAndHashCodeTest extends EqualsVerifier { + + @Parameterized.Parameters(name = "{0}") + public static Collection> data() { + + return Arrays.asList(new Class[]{ + Journal.class, + Publisher.class + }); + } + + public EqualsAndHashCodeTest(final Class clazz) { + super(clazz); + } + + @Override + protected void addPrefabValues( + final nl.jqno.equalsverifier.EqualsVerifier verifier) { + + final Journal journal1 = new Journal(); + journal1.setFirstYear(1953); + journal1.setSymbol("foo"); + + final Journal journal2 = new Journal(); + journal2.setSymbol("bar"); + + verifier.withPrefabValues(Journal.class, journal1, journal2); + + final Publisher publisher1 = new Publisher(); + publisher1.setName("Muster Verlag"); + publisher1.setPlace("Musterburg"); + + final Publisher publisher2 = new Publisher(); + publisher2.setName("Example Press"); + publisher2.setPlace("Riverton"); + + verifier.withPrefabValues(Publisher.class, publisher1, publisher2); + + final ContentSection contentSection1 = new ContentSection(); + contentSection1.setObjectId(401); + contentSection1.setDisplayName("section1"); + + final ContentSection contentSection2 = new ContentSection(); + contentSection2.setObjectId(402); + contentSection2.setDisplayName("section2"); + + verifier.withPrefabValues(ContentSection.class, + contentSection1, + contentSection2); + + final ContentType contentType1 = new ContentType(); + contentType1.setObjectId(501); + contentType1.setDisplayName("type-1"); + + final ContentType contentType2 = new ContentType(); + contentType2.setObjectId(502); + contentType2.setDisplayName("type-2"); + + verifier.withPrefabValues(ContentType.class, + contentType1, + contentType2); + + final ContentItem item1 = new ContentItem(); + item1.setObjectId(601); + item1.setDisplayName("item1"); + + final ContentItem item2 = new ContentItem(); + item2.setObjectId(602); + item2.setDisplayName("item2"); + + verifier.withPrefabValues(ContentItem.class, item1, item2); + + final Lifecycle lifecycle1 = new Lifecycle(); + lifecycle1.setLifecycleId(801); + lifecycle1.setStarted(true); + + final Lifecycle lifecycle2 = new Lifecycle(); + lifecycle2.setLifecycleId(802); + lifecycle2.setStarted(false); + + verifier.withPrefabValues(Lifecycle.class, lifecycle1, lifecycle2); + + final Workflow workflow1 = new Workflow(); + final LocalizedString workflow1Name = new LocalizedString(); + workflow1Name.addValue(Locale.ROOT, "workflow1"); + workflow1.setName(workflow1Name); + + final Workflow workflow2 = new Workflow(); + final LocalizedString workflow2Name = new LocalizedString(); + workflow2Name.addValue(Locale.ROOT, "workflow2"); + workflow2.setName(workflow2Name); + + verifier.withPrefabValues(Workflow.class, workflow1, workflow2); + + final CcmObject ccmObj1 = new CcmObject(); + ccmObj1.setObjectId(1001); + ccmObj1.setDisplayName("obj1"); + + final CcmObject ccmObj2 = new CcmObject(); + ccmObj2.setObjectId(1002); + ccmObj2.setDisplayName("obj2"); + + verifier.withPrefabValues(CcmObject.class, ccmObj1, ccmObj2); + + SecurityEntitiesPrefabProvider.addPrefabEntities(verifier); + + final Category category1 = new Category(); + category1.setObjectId(5001); + category1.setName("category1"); + + final Category category2 = new Category(); + category2.setCategoryOrder(5002); + category2.setName("category2"); + + verifier.withPrefabValues(Category.class, category1, category2); + + final Organization organization1 = new Organization(); + organization1.setName("orga1"); + + final Organization organization2 = new Organization(); + organization1.setName("orga2"); + + verifier.withPrefabValues(Organization.class, + organization1, + organization2); + + final ItemAttachment itemAttachment1 = new ItemAttachment<>(); + itemAttachment1.setUuid("927ac9de-029d-4233-9015-1135eb861c34"); + + final ItemAttachment itemAttachment2 = new ItemAttachment<>(); + itemAttachment2.setUuid("d1bd98a1-75c2-4e61-8f9f-2e2eadd30812"); + + verifier.withPrefabValues(ItemAttachment.class, + itemAttachment1, + itemAttachment2); + } + +}