diff --git a/ccm-cms/pom.xml b/ccm-cms/pom.xml index b7e0bc4dc..5989a42da 100644 --- a/ccm-cms/pom.xml +++ b/ccm-cms/pom.xml @@ -346,4 +346,179 @@ + + + wildfly-remote-h2-mem + + + org.wildfly + wildfly-arquillian-container-remote + + test + + + org.jacoco + org.jacoco.core + + test + + + org.jboss.arquillian.extension + arquillian-jacoco + 1.0.0.Alpha8 + + + net.sf.saxon + Saxon-HE + + + + + + + src/test/resources + + + src/test/resources-wildfly8-remote-h2-mem + + + ${project.build.directory}/generated-resources + + + + + + de.jpdigital + hibernate5-ddl-maven-plugin + + + h2 + postgresql9 + + + org.libreccm + + true + + + + + gen-ddl + + process-classes + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + always + 999 + true + + org.jboss.logmanager.LogManager + + + false + + org.libreccm.tests.categories.UnitTest, + org.libreccm.tests.categories.IntegrationTest + + + + + + + + + wildfly-remote-pgsql + + + org.wildfly + wildfly-arquillian-container-remote + + test + + + org.jacoco + org.jacoco.core + + test + + + + net.sf.saxon + Saxon-HE + + + + + + + src/test/resources + + + src/test/resources-wildfly8-remote-pgsql + + + ${project.build.directory}/generated-resources + + + + + + de.jpdigital + hibernate5-ddl-maven-plugin + + + h2 + postgresql9 + + + org.libreccm + + true + + + + + gen-ddl + + process-classes + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + always + 999 + true + + org.jboss.logmanager.LogManager + + + false + + org.libreccm.tests.categories.UnitTest, + org.libreccm.tests.categories.IntegrationTest + + + + + + + + + diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java index d8eddcdb9..75674b2dd 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java @@ -35,8 +35,12 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToOne; import javax.persistence.Table; + import org.libreccm.web.ApplicationType; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + import static org.librecms.CmsConstants.*; /** @@ -45,12 +49,17 @@ import static org.librecms.CmsConstants.*; */ @Entity @Table(name = "CONTENT_SECTIONS", schema = DB_SCHEMA) +@NamedQueries( + @NamedQuery( + name = "ContentSection.findByLabel", + query = "SELECT s FROM ContentSection s WHERE c.label = :label") +) @ApplicationType( - name = CONTENT_SECTION_APP_TYPE, - descBundle = "org.librecms.contentsection.ContentSectionResources", - singleton = false, - creator = ContentSectionCreator.class, - servlet = ContentSectionServlet.class) + name = CONTENT_SECTION_APP_TYPE, + descBundle = "org.librecms.contentsection.ContentSectionResources", + singleton = false, + creator = ContentSectionCreator.class, + servlet = ContentSectionServlet.class) public class ContentSection extends CcmApplication implements Serializable { private static final long serialVersionUID = -671718122153931727L; @@ -247,23 +256,23 @@ public class ContentSection extends CcmApplication implements Serializable { @Override public String toString(final String data) { return super.toString(String.format( - ", label = \"%s\", " - + "rootDocumentsFolder = \"%s\", " - + "rootAssetsFolder = \"%s\", " - + "pageResolverClass = \"%s\", " - + "itemResolverClass = \"%s\", " - + "templateResolverClass = \"%s\", " - + "xmlGeneratorClass = \"%s\", " - + "defaultLocale = \"%s\"%s", - label, - Objects.toString(rootDocumentsFolder), - Objects.toString(rootAssetsFolder), - pageResolverClass, - itemResolverClass, - templateResolverClass, - xmlGeneratorClass, - Objects.toString(defaultLocale), - data)); + ", label = \"%s\", " + + "rootDocumentsFolder = \"%s\", " + + "rootAssetsFolder = \"%s\", " + + "pageResolverClass = \"%s\", " + + "itemResolverClass = \"%s\", " + + "templateResolverClass = \"%s\", " + + "xmlGeneratorClass = \"%s\", " + + "defaultLocale = \"%s\"%s", + label, + Objects.toString(rootDocumentsFolder), + Objects.toString(rootAssetsFolder), + pageResolverClass, + itemResolverClass, + templateResolverClass, + xmlGeneratorClass, + Objects.toString(defaultLocale), + data)); } } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java index 7338fc215..e302a1c3e 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java @@ -208,7 +208,7 @@ public class ContentSectionManager { @AuthorizationRequired @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) - public void removeTypeToSection(final ContentType type, + public void removeTypeFromSection(final ContentType type, final ContentSection section) { throw new UnsupportedOperationException(); } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionRepository.java index d3652cd1e..0abc11225 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionRepository.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionRepository.java @@ -24,6 +24,7 @@ import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.RequiresPrivilege; import javax.enterprise.context.RequestScoped; +import javax.persistence.TypedQuery; import javax.transaction.Transactional; /** @@ -34,6 +35,20 @@ import javax.transaction.Transactional; public class ContentSectionRepository extends AbstractEntityRepository { + public ContentSection findByLabel(final String label) { + if (label == null || label.isEmpty()) { + throw new IllegalArgumentException( + "The label of a ContentSection can't be empty."); + } + + final TypedQuery query = getEntityManager() + .createNamedQuery("ContentSection.findByLabel", + ContentSection.class); + query.setParameter("label", label); + + return query.getSingleResult(); + } + @Override public Class getEntityClass() { return ContentSection.class; @@ -43,7 +58,7 @@ public class ContentSectionRepository public boolean isNew(final ContentSection section) { return section.getObjectId() == 0; } - + @AuthorizationRequired @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) @@ -51,7 +66,7 @@ public class ContentSectionRepository public void save(final ContentSection section) { super.save(section); } - + @AuthorizationRequired @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java index 3d001206f..7f13779fb 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java @@ -39,12 +39,16 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; +import org.libreccm.security.Role; +import org.libreccm.security.RoleRepository; import org.libreccm.tests.categories.IntegrationTest; import org.librecms.Cms; import java.io.File; -import static org.junit.Assert.*; +import javax.inject.Inject; + +import static org.librecms.CmsConstants.*; /** * @@ -57,6 +61,15 @@ import static org.junit.Assert.*; @CreateSchema({"create_ccm_cms_schema.sql"}) public class ContentSectionManagerTest { + @Inject + private ContentSectionRepository repository; + + @Inject + private ContentSectionManager manager; + + @Inject + private RoleRepository roleRepository; + public ContentSectionManagerTest() { } @@ -111,6 +124,7 @@ public class ContentSectionManagerTest { excludeColumns = {"section_id"}) @InSequence(100) public void createSection() { + manager.createContentSection("test"); } @Test @@ -122,7 +136,9 @@ public class ContentSectionManagerTest { excludeColumns = {"section_id"}) @InSequence(200) public void renameSection() { - //Rename main to content + final ContentSection section = repository.findByLabel("info"); + + manager.renameContentSection(section, "content"); } @Test @@ -134,9 +150,15 @@ public class ContentSectionManagerTest { excludeColumns = {"section_id"}) @InSequence(300) public void addRole() { + final ContentSection section = repository.findByLabel("info"); + manager.addRoleToContentSection(section, + "reviewer", + PRIVILEGE_ITEMS_VIEW_PUBLISHED, + PRIVILEGE_ITEMS_PREVIEW, + PRIVILEGE_ITEMS_APPROVE); } - + @Test @UsingDataSet("datasets/org/librecms/contentsection/" + "ContentSectionManagerTest/data.xml") @@ -146,7 +168,10 @@ public class ContentSectionManagerTest { excludeColumns = {"section_id"}) @InSequence(300) public void removeRole() { + final ContentSection section = repository.findByLabel("info"); + final Role role = roleRepository.findByName("info_publisher"); + manager.removeRoleFromContentSection(section, role); } }