CCM NG: ContentSectionManager
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4201 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
92a8f8cc58
commit
c780d6e43b
175
ccm-cms/pom.xml
175
ccm-cms/pom.xml
|
|
@ -346,4 +346,179 @@
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>wildfly-remote-h2-mem</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly</groupId>
|
||||||
|
<artifactId>wildfly-arquillian-container-remote</artifactId>
|
||||||
|
<!--<version>8.2.1.Final</version>-->
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>org.jacoco.core</artifactId>
|
||||||
|
<!--<version>0.7.5.201505241946</version>-->
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.arquillian.extension</groupId>
|
||||||
|
<artifactId>arquillian-jacoco</artifactId>
|
||||||
|
<version>1.0.0.Alpha8</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.saxon</groupId>
|
||||||
|
<artifactId>Saxon-HE</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>src/test/resources</directory>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<directory>src/test/resources-wildfly8-remote-h2-mem</directory>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<directory>${project.build.directory}/generated-resources</directory>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>de.jpdigital</groupId>
|
||||||
|
<artifactId>hibernate5-ddl-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<dialects>
|
||||||
|
<param>h2</param>
|
||||||
|
<param>postgresql9</param>
|
||||||
|
</dialects>
|
||||||
|
<packages>
|
||||||
|
<param>org.libreccm</param>
|
||||||
|
</packages>
|
||||||
|
<useEnvers>true</useEnvers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>gen-ddl</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>process-classes</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.19.1</version>
|
||||||
|
<configuration>
|
||||||
|
<forkMode>always</forkMode>
|
||||||
|
<forkCount>999</forkCount>
|
||||||
|
<reuseForks>true</reuseForks>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
|
<!--<jboss.home>${project.basedir}/target/wildfly-8.2.0.Final</jboss.home>
|
||||||
|
<module.path>${project.basedir}/target/wildfly-8.2.0.Final/modules</module.path>-->
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<redirectTestOutputToFile>false</redirectTestOutputToFile>
|
||||||
|
<groups>
|
||||||
|
org.libreccm.tests.categories.UnitTest,
|
||||||
|
org.libreccm.tests.categories.IntegrationTest
|
||||||
|
</groups>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>wildfly-remote-pgsql</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly</groupId>
|
||||||
|
<artifactId>wildfly-arquillian-container-remote</artifactId>
|
||||||
|
<!--<version>8.2.1.Final</version>-->
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>org.jacoco.core</artifactId>
|
||||||
|
<!--<version>0.7.5.201505241946</version>-->
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>org.jboss.arquillian.extension</groupId>
|
||||||
|
<artifactId>arquillian-jacoco</artifactId>
|
||||||
|
<version>1.0.0.Alpha8</version>
|
||||||
|
</dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.saxon</groupId>
|
||||||
|
<artifactId>Saxon-HE</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>src/test/resources</directory>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<directory>src/test/resources-wildfly8-remote-pgsql</directory>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<directory>${project.build.directory}/generated-resources</directory>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>de.jpdigital</groupId>
|
||||||
|
<artifactId>hibernate5-ddl-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<dialects>
|
||||||
|
<param>h2</param>
|
||||||
|
<param>postgresql9</param>
|
||||||
|
</dialects>
|
||||||
|
<packages>
|
||||||
|
<param>org.libreccm</param>
|
||||||
|
</packages>
|
||||||
|
<useEnvers>true</useEnvers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>gen-ddl</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>process-classes</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.19.1</version>
|
||||||
|
<configuration>
|
||||||
|
<forkMode>always</forkMode>
|
||||||
|
<forkCount>999</forkCount>
|
||||||
|
<reuseForks>true</reuseForks>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
|
<!--<jboss.home>${project.basedir}/target/wildfly-8.2.0.Final</jboss.home>
|
||||||
|
<module.path>${project.basedir}/target/wildfly-8.2.0.Final/modules</module.path>-->
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<redirectTestOutputToFile>false</redirectTestOutputToFile>
|
||||||
|
<groups>
|
||||||
|
org.libreccm.tests.categories.UnitTest,
|
||||||
|
org.libreccm.tests.categories.IntegrationTest
|
||||||
|
</groups>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
</profiles>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,12 @@ import javax.persistence.JoinTable;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.libreccm.web.ApplicationType;
|
import org.libreccm.web.ApplicationType;
|
||||||
|
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,12 +49,17 @@ import static org.librecms.CmsConstants.*;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "CONTENT_SECTIONS", schema = DB_SCHEMA)
|
@Table(name = "CONTENT_SECTIONS", schema = DB_SCHEMA)
|
||||||
|
@NamedQueries(
|
||||||
|
@NamedQuery(
|
||||||
|
name = "ContentSection.findByLabel",
|
||||||
|
query = "SELECT s FROM ContentSection s WHERE c.label = :label")
|
||||||
|
)
|
||||||
@ApplicationType(
|
@ApplicationType(
|
||||||
name = CONTENT_SECTION_APP_TYPE,
|
name = CONTENT_SECTION_APP_TYPE,
|
||||||
descBundle = "org.librecms.contentsection.ContentSectionResources",
|
descBundle = "org.librecms.contentsection.ContentSectionResources",
|
||||||
singleton = false,
|
singleton = false,
|
||||||
creator = ContentSectionCreator.class,
|
creator = ContentSectionCreator.class,
|
||||||
servlet = ContentSectionServlet.class)
|
servlet = ContentSectionServlet.class)
|
||||||
public class ContentSection extends CcmApplication implements Serializable {
|
public class ContentSection extends CcmApplication implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -671718122153931727L;
|
private static final long serialVersionUID = -671718122153931727L;
|
||||||
|
|
@ -247,23 +256,23 @@ public class ContentSection extends CcmApplication implements Serializable {
|
||||||
@Override
|
@Override
|
||||||
public String toString(final String data) {
|
public String toString(final String data) {
|
||||||
return super.toString(String.format(
|
return super.toString(String.format(
|
||||||
", label = \"%s\", "
|
", label = \"%s\", "
|
||||||
+ "rootDocumentsFolder = \"%s\", "
|
+ "rootDocumentsFolder = \"%s\", "
|
||||||
+ "rootAssetsFolder = \"%s\", "
|
+ "rootAssetsFolder = \"%s\", "
|
||||||
+ "pageResolverClass = \"%s\", "
|
+ "pageResolverClass = \"%s\", "
|
||||||
+ "itemResolverClass = \"%s\", "
|
+ "itemResolverClass = \"%s\", "
|
||||||
+ "templateResolverClass = \"%s\", "
|
+ "templateResolverClass = \"%s\", "
|
||||||
+ "xmlGeneratorClass = \"%s\", "
|
+ "xmlGeneratorClass = \"%s\", "
|
||||||
+ "defaultLocale = \"%s\"%s",
|
+ "defaultLocale = \"%s\"%s",
|
||||||
label,
|
label,
|
||||||
Objects.toString(rootDocumentsFolder),
|
Objects.toString(rootDocumentsFolder),
|
||||||
Objects.toString(rootAssetsFolder),
|
Objects.toString(rootAssetsFolder),
|
||||||
pageResolverClass,
|
pageResolverClass,
|
||||||
itemResolverClass,
|
itemResolverClass,
|
||||||
templateResolverClass,
|
templateResolverClass,
|
||||||
xmlGeneratorClass,
|
xmlGeneratorClass,
|
||||||
Objects.toString(defaultLocale),
|
Objects.toString(defaultLocale),
|
||||||
data));
|
data));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ public class ContentSectionManager {
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void removeTypeToSection(final ContentType type,
|
public void removeTypeFromSection(final ContentType type,
|
||||||
final ContentSection section) {
|
final ContentSection section) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,6 +35,20 @@ import javax.transaction.Transactional;
|
||||||
public class ContentSectionRepository
|
public class ContentSectionRepository
|
||||||
extends AbstractEntityRepository<Long, ContentSection> {
|
extends AbstractEntityRepository<Long, ContentSection> {
|
||||||
|
|
||||||
|
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<ContentSection> query = getEntityManager()
|
||||||
|
.createNamedQuery("ContentSection.findByLabel",
|
||||||
|
ContentSection.class);
|
||||||
|
query.setParameter("label", label);
|
||||||
|
|
||||||
|
return query.getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ContentSection> getEntityClass() {
|
public Class<ContentSection> getEntityClass() {
|
||||||
return ContentSection.class;
|
return ContentSection.class;
|
||||||
|
|
@ -43,7 +58,7 @@ public class ContentSectionRepository
|
||||||
public boolean isNew(final ContentSection section) {
|
public boolean isNew(final ContentSection section) {
|
||||||
return section.getObjectId() == 0;
|
return section.getObjectId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -51,7 +66,7 @@ public class ContentSectionRepository
|
||||||
public void save(final ContentSection section) {
|
public void save(final ContentSection section) {
|
||||||
super.save(section);
|
super.save(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,16 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import org.libreccm.security.RoleRepository;
|
||||||
import org.libreccm.tests.categories.IntegrationTest;
|
import org.libreccm.tests.categories.IntegrationTest;
|
||||||
import org.librecms.Cms;
|
import org.librecms.Cms;
|
||||||
|
|
||||||
import java.io.File;
|
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"})
|
@CreateSchema({"create_ccm_cms_schema.sql"})
|
||||||
public class ContentSectionManagerTest {
|
public class ContentSectionManagerTest {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository repository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionManager manager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
public ContentSectionManagerTest() {
|
public ContentSectionManagerTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,6 +124,7 @@ public class ContentSectionManagerTest {
|
||||||
excludeColumns = {"section_id"})
|
excludeColumns = {"section_id"})
|
||||||
@InSequence(100)
|
@InSequence(100)
|
||||||
public void createSection() {
|
public void createSection() {
|
||||||
|
manager.createContentSection("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -122,7 +136,9 @@ public class ContentSectionManagerTest {
|
||||||
excludeColumns = {"section_id"})
|
excludeColumns = {"section_id"})
|
||||||
@InSequence(200)
|
@InSequence(200)
|
||||||
public void renameSection() {
|
public void renameSection() {
|
||||||
//Rename main to content
|
final ContentSection section = repository.findByLabel("info");
|
||||||
|
|
||||||
|
manager.renameContentSection(section, "content");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -134,9 +150,15 @@ public class ContentSectionManagerTest {
|
||||||
excludeColumns = {"section_id"})
|
excludeColumns = {"section_id"})
|
||||||
@InSequence(300)
|
@InSequence(300)
|
||||||
public void addRole() {
|
public void addRole() {
|
||||||
|
final ContentSection section = repository.findByLabel("info");
|
||||||
|
|
||||||
|
manager.addRoleToContentSection(section,
|
||||||
|
"reviewer",
|
||||||
|
PRIVILEGE_ITEMS_VIEW_PUBLISHED,
|
||||||
|
PRIVILEGE_ITEMS_PREVIEW,
|
||||||
|
PRIVILEGE_ITEMS_APPROVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||||
+ "ContentSectionManagerTest/data.xml")
|
+ "ContentSectionManagerTest/data.xml")
|
||||||
|
|
@ -146,7 +168,10 @@ public class ContentSectionManagerTest {
|
||||||
excludeColumns = {"section_id"})
|
excludeColumns = {"section_id"})
|
||||||
@InSequence(300)
|
@InSequence(300)
|
||||||
public void removeRole() {
|
public void removeRole() {
|
||||||
|
final ContentSection section = repository.findByLabel("info");
|
||||||
|
final Role role = roleRepository.findByName("info_publisher");
|
||||||
|
|
||||||
|
manager.removeRoleFromContentSection(section, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue