diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index d986bb95a..ce2e42d2c 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -918,7 +918,7 @@ public class ContentItemManager { * {@code info:/research/computer-science/artificial-intelligence/neural-nets}. * * @param item The item whose path is generated. - * @param withContentSection Wether to include the content section into the + * @param withContentSection Whether to include the content section into the * path. * * @return The path of the content item @@ -940,7 +940,6 @@ public class ContentItemManager { Category current = result.get(0).getCategory(); tokens.add(current.getName()); - while (current.getParentCategory() != null) { current = current.getParentCategory(); tokens.add(current.getName()); @@ -953,7 +952,7 @@ public class ContentItemManager { final String sectionName = item.getContentType(). getContentSection().getDisplayName(); return String.format( - "%s/%s", sectionName, path); + "%s:/%s", sectionName, path); } else { return String.format("/%s", path); } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/Folder.java b/ccm-cms/src/main/java/org/librecms/contentsection/Folder.java index 34a352b8b..e85111620 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/Folder.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/Folder.java @@ -24,14 +24,16 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import org.libreccm.categorization.Category; -import org.libreccm.core.CcmObject; +import java.util.Collections; +import java.util.List; import java.util.Objects; -import java.util.Optional; +import java.util.stream.Collectors; import javax.persistence.Column; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.JoinTable; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -58,7 +60,12 @@ public class Folder extends Category { private static final long serialVersionUID = 1L; @OneToOne - @JoinColumn(name = "CONTENT_SECTION_ID") +// @JoinColumn(name = "CONTENT_SECTION_ID") + @JoinTable(name = "FOLDER_CONTENT_SECTION_MAP", schema = DB_SCHEMA, + inverseJoinColumns = { + @JoinColumn(name = "CONTENT_SECTION_ID")}, + joinColumns = { + @JoinColumn(name = "FOLDER_ID")}) private ContentSection section; @Column(name = "TYPE", nullable = false) @@ -81,6 +88,29 @@ public class Folder extends Category { this.type = type; } + /** + * A convenient method for getting all sub folders of folder. + * + * @return The sub folders of this folder. + */ + public List getSubFolders() { + return Collections.unmodifiableList( + getSubCategories() + .stream() + .filter(subCategory -> subCategory instanceof Folder) + .map(subCategory -> (Folder) subCategory) + .collect(Collectors.toList())); + } + + public Folder getParentFolder() { + final Category parent = getParentCategory(); + if (parent == null) { + return null; + } else { + return (Folder) getParentCategory(); + } + } + @Override public int hashCode() { int hash = super.hashCode(); diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java index c7282e31a..64773ded7 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java @@ -18,17 +18,250 @@ */ package org.librecms.contentsection; +import com.arsdigita.kernel.KernelConfig; + +import org.libreccm.categorization.CategoryManager; +import org.libreccm.configuration.ConfigurationManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; /** + * Provides several methods for managing {@link Folder}s. * * @author Jens Pelzetter -*/ + */ @RequestScoped public class FolderManager { - - //createFolder - //deleteFolder - //moveFolder - + + @Inject + private ConfigurationManager confManager; + + @Inject + private FolderRepository folderRepo; + + @Inject + private CategoryManager categoryManager; + + @Inject + private ContentItemManager itemManager; + + /** + * Creates new folder as sub folder of the provided parent folder. The type + * and the content section to which the folder belongs are the same as for + * the provided parent folder. + * + * @param name The name of the new folder. + * @param parent The folder in which the new folder is generated. + * + * @return The new folder. + */ + @Transactional(Transactional.TxType.REQUIRED) + public Folder createFolder(final String name, final Folder parent) { + if (parent == null) { + throw new IllegalArgumentException( + "Can't create a folder without a parent folder."); + } + + if (name == null || name.trim().isEmpty()) { + throw new IllegalArgumentException( + "Can't create a folder with an empty name"); + } + + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + + final Folder folder = new Folder(); + folder.setName(name); + folder.setDisplayName(name); + folder.getTitle().addValue(kernelConfig.getDefaultLocale(), name); + folder.setSection(parent.getSection()); + folder.setType(parent.getType()); + folderRepo.save(folder); + + categoryManager.addSubCategoryToCategory(folder, parent); + + return folder; + } + + /** + * Deletes a empty, none-root folder. + * + * @param folder The folder to delete. + */ + @Transactional(Transactional.TxType.REQUIRED) + public void deleteFolder(final Folder folder) { + if (folder == null) { + throw new IllegalArgumentException("Can't delete folder null"); + } + + if (!folder.getSubCategories().isEmpty()) { + throw new IllegalArgumentException(String.format( + "Can't delete folder \"%s\" because the folder is not empty", + getFolderPath(folder, true))); + } + + if (!folder.getObjects().isEmpty()) { + throw new IllegalArgumentException(String.format( + "Can't delete folder \"%s\" because the folder is not empty.", + getFolderPath(folder))); + } + + if (folder.getParentFolder() == null) { + throw new IllegalArgumentException( + "The folder to delete is a root folder can can't be deleted."); + } + + folderRepo.delete(folder); + } + + /** + * Moves a none-root folder to another folder. If there any live + * {@link ContentItem}s in the folder and its sub folder the folder can't be + * moved. Also the target folder must belong to the same + * {@link ContentSection} than the folder to move. + * + * @param folder The folder to move. + * @param target The target folder. + */ + @Transactional(Transactional.TxType.REQUIRED) + public void moveFolder(final Folder folder, final Folder target) { + if (folder == null) { + throw new IllegalArgumentException("Can't move folder null"); + } + + if (target == null) { + throw new IllegalArgumentException( + "Can't move a folder to folder null"); + } + + if (folder.getParentFolder() == null) { + throw new IllegalArgumentException(String.format( + "The folder \"%s\" to move is a root folder can can't be moved.", + getFolderPath(folder))); + } + + if (folder.equals(target)) { + throw new IllegalArgumentException( + "The folder to move and the target folder are the same folder."); + } + + if (!folder.getSection().equals(target.getSection())) { + throw new IllegalArgumentException(String.format( + "Folders can't be moved between content section. The " + + "folder \"%s\" to move belongs to section \"%s\", " + + "the target folder \"%s\" belongs to section \"%s\".", + getFolderPath(folder), + folder.getSection().getDisplayName(), + getFolderPath(target), + target.getSection().getDisplayName())); + } + + if (folder.getType() != target.getType()) { + throw new IllegalArgumentException("The folder to move is a \"%s\"," + + "but the target folder is a \"%s\" folder."); + } + + if (liveItemsInFolder(folder)) { + throw new IllegalArgumentException(String.format( + "Can't move folder \"%s\" because some items in the folder or" + + "its sub folder are live.", + getFolderPath(folder, true))); + } + + final Folder source = folder.getParentFolder(); + categoryManager.removeSubCategoryFromCategory(folder, source); + final boolean sameName = target.getSubCategories() + .stream() + .anyMatch(subCategory -> folder.getName().equals(subCategory + .getName())); + if (sameName) { + final String name = String.format("%s_1", folder.getName()); + folder.setName(name); + folder.setDisplayName(name); + + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + folder.getTitle().addValue(kernelConfig.getDefaultLocale(), name); + } + categoryManager.addSubCategoryToCategory(folder, target); + } + + /** + * Internal helper method for checking if there any live items in a given + * folder or its sub folders. + * + * @param folder The folder to check for live items. + * + * @return {@code true} if there any live items in the folder or its sub + * folders, {@code false} if not. + */ + private boolean liveItemsInFolder(final Folder folder) { + final boolean liveItemsInFolder = folder.getObjects() + .stream() + .map(categorization -> categorization.getCategorizedObject()) + .filter(object -> object instanceof ContentItem) + .map(object -> (ContentItem) object) + .anyMatch(item -> itemManager.isLive(item)); + + final boolean liveItemsInSubFolders = folder.getSubFolders() + .stream() + .anyMatch(subFolder -> liveItemsInFolder(subFolder)); + + return liveItemsInFolder || liveItemsInSubFolders; + } + + /** + * Returns the path of folder. + * + * @param folder The folder. + * + * @return The path of the folder as a UNIX-like path, but without the + * content section as prefix. + */ + public String getFolderPath(final Folder folder) { + return getFolderPath(folder, false); + } + + /** + * Returns the path of folder. + * + * @param folder The folder. + * @param withContentSection Whether to include the content section in the + * path. + * + * @return The path of the folder as a UNIX-like path, optionally with the + * content section the folder belongs to as prefix.. + */ + public String getFolderPath(final Folder folder, + final boolean withContentSection) { + if (folder == null) { + throw new IllegalArgumentException("Can't generate a path for null."); + } + + final List tokens = new ArrayList<>(); + + tokens.add(folder.getName()); + Folder current = folder; + while (current.getParentFolder() != null) { + current = current.getParentFolder(); + tokens.add(current.getName()); + } + + Collections.reverse(tokens); + final String path = String.join("/", tokens); + + if (withContentSection) { + final String sectionName = folder.getSection().getDisplayName(); + return String.format("%s:/%s/", sectionName, path); + } else { + return String.format("/%s/", path); + } + } + } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java index d67bd0afd..3c91a97f3 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderRepository.java @@ -75,7 +75,7 @@ public class FolderRepository extends AbstractEntityRepository { public List getRootAssetFolders() { final TypedQuery query = getEntityManager().createNamedQuery( "Folder.rootFolders", Folder.class); - query.setParameter("type", FolderType.ASSET_FOLDER); + query.setParameter("type", FolderType.ASSETS_FOLDER); return query.getResultList(); } @@ -143,7 +143,7 @@ public class FolderRepository extends AbstractEntityRepository { final String[] tokens = normalizedPath.split("/"); Folder current; switch(type) { - case ASSET_FOLDER: + case ASSETS_FOLDER: current = section.getRootAssetsFolder(); break; case DOCUMENTS_FOLDER: diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderType.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderType.java index 10914055f..a191abb0e 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderType.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderType.java @@ -25,6 +25,6 @@ package org.librecms.contentsection; public enum FolderType { DOCUMENTS_FOLDER, - ASSET_FOLDER, + ASSETS_FOLDER, } diff --git a/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/h2/V7_0_0_7__create_folders.sql b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/h2/V7_0_0_7__create_folders.sql new file mode 100644 index 000000000..923de0540 --- /dev/null +++ b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/h2/V7_0_0_7__create_folders.sql @@ -0,0 +1,32 @@ + create table CCM_CMS.FOLDER_CONTENT_SECTION_MAP ( + CONTENT_SECTION_ID bigint, + FOLDER_ID bigint not null, + primary key (FOLDER_ID) + ); + + create table CCM_CMS.FOLDERS ( + TYPE varchar(255) not null, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + +alter table CCM_CMS.CONTENT_SECTIONS + drop constraint if exists FKajweudfxaf7g2ydr2hcgqwcib; + +alter table CCM_CMS.CONTENT_SECTIONS + drop constraint if exists FK6g7kw4b6diqa0nks45ilp0vhs; + +alter table CCM_CMS.CONTENT_SECTIONS + add constraint FKavcn4aakxsb7kt7hmqlx0ecu6 + foreign key (ROOT_ASSETS_FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKmmb7728dp707dljq282ch47k3 + foreign key (FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDERS + add constraint FK2ag06r5ywtuji2pkt68etlg48 + foreign key (OBJECT_ID) + references CCM_CORE.CATEGORIES; diff --git a/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_7__create_folders.sql b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_7__create_folders.sql new file mode 100644 index 000000000..a8534c32d --- /dev/null +++ b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_7__create_folders.sql @@ -0,0 +1,42 @@ + create table CCM_CMS.FOLDER_CONTENT_SECTION_MAP ( + CONTENT_SECTION_ID int8, + FOLDER_ID int8 not null, + primary key (FOLDER_ID) + ); + + create table CCM_CMS.FOLDERS ( + TYPE varchar(255) not null, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + +alter table CCM_CMS.CONTENT_SECTIONS + drop constraint if exists FKajweudfxaf7g2ydr2hcgqwcib; + +alter table CCM_CMS.CONTENT_SECTIONS + drop constraint if exists FK6g7kw4b6diqa0nks45ilp0vhs; + + alter table CCM_CMS.CONTENT_SECTIONS + add constraint FKavcn4aakxsb7kt7hmqlx0ecu6 + foreign key (ROOT_ASSETS_FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.CONTENT_SECTIONS + add constraint FKd5sahsfsycq3i5icf3122ne8e + foreign key (ROOT_DOCUMENTS_FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKnof2m7o4f0ufrugeh4g5wt3g9 + foreign key (CONTENT_SECTION_ID) + references CCM_CMS.CONTENT_SECTIONS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKmmb7728dp707dljq282ch47k3 + foreign key (FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDERS + add constraint FK2ag06r5ywtuji2pkt68etlg48 + foreign key (OBJECT_ID) + references CCM_CORE.CATEGORIES; 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 516f7be64..62a815ff9 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentSectionManagerTest.java @@ -102,53 +102,58 @@ public class ContentSectionManagerTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, - "LibreCCM-org.libreccm.cms.contentsection.ContentSectionManagerTest.war"). - addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) - .addPackage(org.libreccm.categorization.Categorization.class - .getPackage()) - .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) - .addPackage(org.libreccm.configuration.Configuration.class - .getPackage()) - .addPackage(org.libreccm.core.CcmCore.class.getPackage()) - .addPackage(org.libreccm.jpa.EntityManagerProducer.class - .getPackage()) - .addPackage(org.libreccm.l10n.LocalizedString.class - .getPackage()) - .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class. - getPackage()) - .addPackage(org.libreccm.security.Permission.class.getPackage()) - .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) - .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) - .addPackage(com.arsdigita.bebop.Component.class.getPackage()) - .addPackage(com.arsdigita.bebop.util.BebopConstants.class - .getPackage()) - .addClass(com.arsdigita.kernel.KernelConfig.class) - .addClass(com.arsdigita.runtime.CCMResourceManager.class) - .addClass( - com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class) - .addClass( - com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class) - .addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class) - .addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) - .addPackage(com.arsdigita.cms.dispatcher.ItemResolver.class. - getPackage()) - .addPackage(com.arsdigita.util.Lockable.class.getPackage()) - .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) - .addPackage(org.librecms.Cms.class.getPackage()) - .addPackage(org.librecms.assets.Asset.class.getPackage()) - .addPackage(org.librecms.attachments.AttachmentList.class - .getPackage()) - .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) - .addPackage(ContentSection.class.getPackage()) - .addAsLibraries(getModuleDependencies()) - .addAsLibraries(getCcmCoreDependencies()) - .addAsResource("test-persistence.xml", - "META-INF/persistence.xml") - .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + .create(WebArchive.class, + "LibreCCM-org.libreccm.cms.contentsection.ContentSectionManagerTest.war") + .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) + .addPackage(org.libreccm.categorization.Categorization.class + .getPackage()) + .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) + .addPackage(org.libreccm.configuration.Configuration.class + .getPackage()) + .addPackage(org.libreccm.core.CcmCore.class.getPackage()) + .addPackage(org.libreccm.jpa.EntityManagerProducer.class + .getPackage()) + .addPackage(org.libreccm.l10n.LocalizedString.class + .getPackage()) + .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class. + getPackage()) + .addPackage(org.libreccm.security.Permission.class.getPackage()) + .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) + .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) + .addPackage(com.arsdigita.bebop.Component.class.getPackage()) + .addPackage(com.arsdigita.bebop.util.BebopConstants.class + .getPackage()) + .addClass(com.arsdigita.kernel.KernelConfig.class) + .addClass(com.arsdigita.runtime.CCMResourceManager.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) + .addClass(org.libreccm.modules.Module.class) + .addClass(org.libreccm.modules.RequiredModule.class) + .addClass(org.libreccm.portation.Marshals.class) + .addPackage(com.arsdigita.cms.dispatcher.ItemResolver.class. + getPackage()) + .addPackage(com.arsdigita.util.Lockable.class.getPackage()) + .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) + .addPackage(org.librecms.Cms.class.getPackage()) + .addPackage(org.librecms.assets.Asset.class.getPackage()) + .addPackage(org.librecms.attachments.AttachmentList.class + .getPackage()) + .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) + .addPackage(ContentSection.class.getPackage()) + .addPackage(org.libreccm.tests.categories.IntegrationTest.class + .getPackage()) + //.addAsLibraries(getModuleDependencies()) + .addAsLibraries(getCcmCoreDependencies()) + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); } @Test @@ -171,21 +176,21 @@ public class ContentSectionManagerTest { @Test @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/data.xml") + + "ContentSectionManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/after-create.xml", - excludeColumns = {"object_id", - "root_assets_folder_id", - "root_documents_folder_id", - "permission_id", - "role_id", - "grantee_id", - "unique_id", - "uuid", - "created", - "section_id", - "creation_date"}) + value = "datasets/org/librecms/contentsection/" + + "ContentSectionManagerTest/after-create.xml", + excludeColumns = {"object_id", + "root_assets_folder_id", + "root_documents_folder_id", + "permission_id", + "role_id", + "grantee_id", + "unique_id", + "uuid", + "created", + "section_id", + "creation_date"}) @InSequence(100) public void createSection() { manager.createContentSection("test"); @@ -193,11 +198,11 @@ public class ContentSectionManagerTest { @Test @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/data.xml") + + "ContentSectionManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/after-rename.xml", - excludeColumns = {"object_id"}) + value = "datasets/org/librecms/contentsection/" + + "ContentSectionManagerTest/after-rename.xml", + excludeColumns = {"object_id"}) @InSequence(200) public void renameSection() { final ContentSection section = repository.findByLabel("info"); @@ -205,9 +210,9 @@ public class ContentSectionManagerTest { manager.renameContentSection(section, "content"); final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); + KernelConfig.class); final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + .getDefaultLanguage()); section.getTitle().addValue(defaultLocale, "content"); repository.save(section); @@ -215,12 +220,12 @@ public class ContentSectionManagerTest { section.getRootDocumentsFolder().setName("content_root"); section.getRootDocumentsFolder().setDisplayName("content_root"); section.getRootDocumentsFolder().getTitle().addValue( - defaultLocale, "content_root"); + defaultLocale, "content_root"); section.getRootAssetsFolder().setName("content_assets"); section.getRootAssetsFolder().setDisplayName("content_assets"); section.getRootAssetsFolder().getTitle().addValue( - defaultLocale, "content_assets"); + defaultLocale, "content_assets"); categoryRepo.save(section.getRootDocumentsFolder()); categoryRepo.save(section.getRootAssetsFolder()); @@ -228,15 +233,15 @@ public class ContentSectionManagerTest { @Test @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/data.xml") + + "ContentSectionManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/after-add-role.xml", - excludeColumns = {"object_id", - "role_id", - "permission_id", - "creation_date", - "grantee_id"}) + value = "datasets/org/librecms/contentsection/" + + "ContentSectionManagerTest/after-add-role.xml", + excludeColumns = {"object_id", + "role_id", + "permission_id", + "creation_date", + "grantee_id"}) @InSequence(300) public void addRole() { final ContentSection section = repository.findByLabel("info"); @@ -250,11 +255,11 @@ public class ContentSectionManagerTest { @Test @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/data.xml") + + "ContentSectionManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentSectionManagerTest/after-remove-role.xml", - excludeColumns = {"object_id"}) + value = "datasets/org/librecms/contentsection/" + + "ContentSectionManagerTest/after-remove-role.xml", + excludeColumns = {"object_id"}) @InSequence(300) public void removeRole() { final ContentSection section = repository.findByLabel("info"); diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java index c7835d7f7..56ddd2b50 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java @@ -60,7 +60,16 @@ public class DatasetsTest extends DatasetsVerifier { "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml", "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml", "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml", - "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml"}); + "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml", + + "/datasets/org/librecms/contentsection/FolderManagerTest/data.xml", + "/datasets/org/librecms/contentsection/FolderManagerTest/after-create-docs-folder.xml", + "/datasets/org/librecms/contentsection/FolderManagerTest/after-create-assets-folder.xml", + "/datasets/org/librecms/contentsection/FolderManagerTest/after-delete-folder.xml", + "/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder.xml", + "/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml", + + }); } public DatasetsTest(final String datasetPath) { diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/FolderManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/FolderManagerTest.java new file mode 100644 index 000000000..f20f8f1ee --- /dev/null +++ b/ccm-cms/src/test/java/org/librecms/contentsection/FolderManagerTest.java @@ -0,0 +1,578 @@ +/* + * Copyright (C) 2016 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.librecms.contentsection; + +import static org.libreccm.testutils.DependenciesHelpers.*; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.persistence.CreateSchema; +import org.jboss.arquillian.persistence.PersistenceTest; +import org.jboss.arquillian.persistence.ShouldMatchDataSet; +import org.jboss.arquillian.persistence.UsingDataSet; +import org.jboss.arquillian.transaction.api.annotation.TransactionMode; +import org.jboss.arquillian.transaction.api.annotation.Transactional; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +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.junit.runner.RunWith; +import org.libreccm.tests.categories.IntegrationTest; + +import javax.inject.Inject; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +/** + * + * @author Jens Pelzetter + */ +@Category(IntegrationTest.class) +@RunWith(Arquillian.class) +@PersistenceTest +@Transactional(TransactionMode.COMMIT) +@CreateSchema({"create_ccm_cms_schema.sql"}) +public class FolderManagerTest { + + @Inject + private FolderRepository folderRepo; + + @Inject + private FolderManager folderManager; + + public FolderManagerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap + .create(WebArchive.class, + "LibreCCM-org.libreccm.cms.contentsection.ContentSectionManagerTest.war") + .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) + .addPackage(org.libreccm.categorization.Categorization.class + .getPackage()) + .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) + .addPackage(org.libreccm.configuration.Configuration.class + .getPackage()) + .addPackage(org.libreccm.core.CcmCore.class.getPackage()) + .addPackage(org.libreccm.jpa.EntityManagerProducer.class + .getPackage()) + .addPackage(org.libreccm.l10n.LocalizedString.class + .getPackage()) + .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class. + getPackage()) + .addPackage(org.libreccm.security.Permission.class.getPackage()) + .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) + .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) + .addPackage(com.arsdigita.bebop.Component.class.getPackage()) + .addPackage(com.arsdigita.bebop.util.BebopConstants.class + .getPackage()) + .addClass(com.arsdigita.kernel.KernelConfig.class) + .addClass(com.arsdigita.runtime.CCMResourceManager.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) + .addPackage(com.arsdigita.cms.dispatcher.ItemResolver.class. + getPackage()) + .addPackage(com.arsdigita.util.Lockable.class.getPackage()) + .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) + .addPackage(org.librecms.Cms.class.getPackage()) + .addPackage(org.librecms.assets.Asset.class.getPackage()) + .addPackage(org.librecms.attachments.AttachmentList.class + .getPackage()) + .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) + .addPackage(ContentSection.class.getPackage()) + .addPackage(org.libreccm.tests.categories.IntegrationTest.class + .getPackage()) + // .addAsLibraries(getModuleDependencies()) + .addAsLibraries(getCcmCoreDependencies()) + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsResource("configs/shiro.ini", "shiro.ini") + .addAsWebInfResource("test-web.xml", "web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + } + + @Test + @InSequence(10) + public void checkInjection() { + assertThat(folderRepo, is(not(nullValue()))); + assertThat(folderManager, is(not(nullValue()))); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/after-create-docs-folder.xml", + excludeColumns = {"object_id", + "folder_id", + "uuid", + "unique_id", + "category_order", + "content_section_id"}) + @InSequence(1000) + public void createDocumentsFolder() { + final Folder parent = folderRepo.findById(-2005L); + assertThat(parent, is(not(nullValue()))); + + final Folder test = folderManager.createFolder("test", parent); + + assertThat(test, is(not(nullValue()))); + assertThat(test.getName(), is(equalTo("test"))); + assertThat(test.getSection().getObjectId(), is(-1100L)); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/after-create-assets-folder.xml", + excludeColumns = {"object_id", + "folder_id", + "uuid", + "unique_id", + "category_order", + "content_section_id"}) + @InSequence(1100) + public void createAssetsFolder() { + final Folder parent = folderRepo.findById(-2013L); + assertThat(parent, is(not(nullValue()))); + + final Folder test = folderManager.createFolder("test", parent); + + assertThat(test, is(not(nullValue()))); + assertThat(test.getName(), is(equalTo("test"))); + assertThat(test.getSection().getObjectId(), is(-1100L)); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(1400) + public void createFolderNoParent() { + folderManager.createFolder("test", null); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(1500) + public void createFolderNullName() { + final Folder parent = folderRepo.findById(-2005L); + assertThat(parent, is(not(nullValue()))); + + final Folder test = folderManager.createFolder(null, parent); + + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(1500) + public void createFolderEmptyName() { + final Folder parent = folderRepo.findById(-2005L); + assertThat(parent, is(not(nullValue()))); + + final Folder test = folderManager.createFolder(" ", parent); + + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/after-delete-folder.xml", + excludeColumns = {"object_id"}) + @InSequence(2000) + public void deleteFolder() { + //docs-1-1-1 + final Folder folder = folderRepo.findById(-2007L); + folderManager.deleteFolder(folder); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(2100) + public void deleteNonEmptyFolder() { + final Folder folder = folderRepo.findById(-2008L); + folderManager.deleteFolder(folder); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(2100) + public void deleteNonEmptySubFolder() { + final Folder folder = folderRepo.findById(-2006L); + folderManager.deleteFolder(folder); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(2210) + public void deleteRootFolder() { + final Folder folder = folderRepo.findById(-2003L); + folderManager.deleteFolder(folder); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(2220) + public void deleteNullFolder() { + folderManager.deleteFolder(null); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/after-move-folder.xml", + excludeColumns = {"category_order"}) + @InSequence(3000) + public void moveFolder() { + //docs-1-1-2 to docs-2 + final Folder folder = folderRepo.findById(-2008L); + final Folder target = folderRepo.findById(-2010L); + + folderManager.moveFolder(folder, target); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/after-move-folder-same-name.xml", + excludeColumns = {"category_order"}) + @InSequence(3010) + public void moveFolderTargetFolderSameName() { + //docs-1/downloads to /docs-2/ + + final Folder folder = folderRepo.findById(-2009L); + final Folder target = folderRepo.findById(-2010L); + + folderManager.moveFolder(folder, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3100) + public void moveDocumentsFolderToAssetsFolder() { + final Folder folder = folderRepo.findById(-2009L); + final Folder target = folderRepo.findById(-2014L); + + folderManager.moveFolder(folder, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3110) + public void moveAssetsFolderToDocumentsFolder() { + final Folder folder = folderRepo.findById(-2014L); + final Folder target = folderRepo.findById(-2010L); + + folderManager.moveFolder(folder, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3110) + public void moveFolderToItself() { + final Folder folder = folderRepo.findById(-2008L); + + folderManager.moveFolder(folder, folder); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3200) + public void moveFolderNull() { + final Folder target = folderRepo.findById(-2010L); + folderManager.moveFolder(null, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3210) + public void moveFolderTargetNull() { + final Folder folder = folderRepo.findById(-2008L); + + folderManager.moveFolder(folder, null); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3300) + public void moveFolderWithLiveItems() { + final Folder folder = folderRepo.findById(-2011L); + final Folder target = folderRepo.findById(-2010L); + + folderManager.moveFolder(folder, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3310) + public void moveFolderWithLiveItemsInSubFolder() { + final Folder folder = folderRepo.findById(-2010L); + final Folder target = folderRepo.findById(-2005L); + + folderManager.moveFolder(folder, target); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3320) + public void moveFolderToOtherSection() { + final Folder folder = folderRepo.findById(-2008L); + final Folder target = folderRepo.findById(-2003L); + + folderManager.moveFolder(folder, target); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @InSequence(3400) + public void getFolderPath() { + final Folder infoRoot = folderRepo.findById(-2001L); + final Folder infoAssets = folderRepo.findById(-2002L); + final Folder projectsRoot = folderRepo.findById(-2003L); + final Folder projectsAssets = folderRepo.findById(-2004L); + final Folder docs1 = folderRepo.findById(-2005L); + final Folder docs11 = folderRepo.findById(-2006L); + final Folder docs111 = folderRepo.findById(-2007L); + final Folder docs112 = folderRepo.findById(-2008L); + final Folder downloads1 = folderRepo.findById(-2009L); + final Folder docs2 = folderRepo.findById(-2010L); + final Folder docs21 = folderRepo.findById(-2011L); + final Folder downloads2 = folderRepo.findById(-2012L); + final Folder assets1 = folderRepo.findById(-2013L); + final Folder assets11 = folderRepo.findById(-2014L); + final Folder assets12 = folderRepo.findById(-2015L); + + assertThat(folderManager.getFolderPath(infoRoot), + is(equalTo("/info_root/"))); + assertThat(folderManager.getFolderPath(infoAssets), + is(equalTo("/info_assets/"))); + assertThat(folderManager.getFolderPath(projectsRoot), + is(equalTo("/projects_root/"))); + assertThat(folderManager.getFolderPath(projectsAssets), + is(equalTo("/projects_assets/"))); + assertThat(folderManager.getFolderPath(docs1), + is(equalTo("/info_root/docs-1/"))); + assertThat(folderManager.getFolderPath(docs11), + is(equalTo("/info_root/docs-1/docs-1-1/"))); + assertThat(folderManager.getFolderPath(docs111), + is(equalTo("/info_root/docs-1/docs-1-1/docs-1-1-1/"))); + assertThat(folderManager.getFolderPath(docs112), + is(equalTo("/info_root/docs-1/docs-1-1/docs-1-1-2/"))); + assertThat(folderManager.getFolderPath(downloads1), + is(equalTo("/info_root/docs-1/downloads/"))); + assertThat(folderManager.getFolderPath(docs2), + is(equalTo("/info_root/docs-2/"))); + assertThat(folderManager.getFolderPath(docs21), + is(equalTo("/info_root/docs-2/docs-2-1/"))); + assertThat(folderManager.getFolderPath(downloads2), + is(equalTo("/info_root/docs-2/downloads/"))); + assertThat(folderManager.getFolderPath(assets1), + is(equalTo("/info_assets/assets-1/"))); + assertThat(folderManager.getFolderPath(assets11), + is(equalTo("/info_assets/assets-1/assets-1-1/"))); + assertThat(folderManager.getFolderPath(assets12), + is(equalTo("/info_assets/assets-1/assets-1-2/"))); + } + + @Test + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @InSequence(3410) + public void getFolderPathWithContentSection() { + final Folder infoRoot = folderRepo.findById(-2001L); + final Folder infoAssets = folderRepo.findById(-2002L); + final Folder projectsRoot = folderRepo.findById(-2003L); + final Folder projectsAssets = folderRepo.findById(-2004L); + final Folder docs1 = folderRepo.findById(-2005L); + final Folder docs11 = folderRepo.findById(-2006L); + final Folder docs111 = folderRepo.findById(-2007L); + final Folder docs112 = folderRepo.findById(-2008L); + final Folder downloads1 = folderRepo.findById(-2009L); + final Folder docs2 = folderRepo.findById(-2010L); + final Folder docs21 = folderRepo.findById(-2011L); + final Folder downloads2 = folderRepo.findById(-2012L); + final Folder assets1 = folderRepo.findById(-2013L); + final Folder assets11 = folderRepo.findById(-2014L); + final Folder assets12 = folderRepo.findById(-2015L); + + assertThat(folderManager.getFolderPath(infoRoot, true), + is(equalTo("info:/info_root/"))); + assertThat(folderManager.getFolderPath(infoAssets, true), + is(equalTo("info:/info_assets/"))); + assertThat(folderManager.getFolderPath(projectsRoot, true), + is(equalTo("projects:/projects_root/"))); + assertThat(folderManager.getFolderPath(projectsAssets, true), + is(equalTo("projects:/projects_assets/"))); + assertThat(folderManager.getFolderPath(docs1, true), + is(equalTo("info:/info_root/docs-1/"))); + assertThat(folderManager.getFolderPath(docs11, true), + is(equalTo("info:/info_root/docs-1/docs-1-1/"))); + assertThat(folderManager.getFolderPath(docs111, true), + is(equalTo("info:/info_root/docs-1/docs-1-1/docs-1-1-1/"))); + assertThat(folderManager.getFolderPath(docs112, true), + is(equalTo("info:/info_root/docs-1/docs-1-1/docs-1-1-2/"))); + assertThat(folderManager.getFolderPath(downloads1, true), + is(equalTo("info:/info_root/docs-1/downloads/"))); + assertThat(folderManager.getFolderPath(docs2, true), + is(equalTo("info:/info_root/docs-2/"))); + assertThat(folderManager.getFolderPath(docs21, true), + is(equalTo("info:/info_root/docs-2/docs-2-1/"))); + assertThat(folderManager.getFolderPath(downloads2, true), + is(equalTo("info:/info_root/docs-2/downloads/"))); + assertThat(folderManager.getFolderPath(assets1, true), + is(equalTo("info:/info_assets/assets-1/"))); + assertThat(folderManager.getFolderPath(assets11, true), + is(equalTo("info:/info_assets/assets-1/assets-1-1/"))); + assertThat(folderManager.getFolderPath(assets12, true), + is(equalTo("info:/info_assets/assets-1/assets-1-2/"))); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3410) + public void getFolderPathNull() { + folderManager.getFolderPath(null); + } + + @Test(expected = IllegalArgumentException.class) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "FolderManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + @InSequence(3410) + public void getFolderPathNullWithContentSection() { + folderManager.getFolderPath(null, true); + } + +} diff --git a/ccm-cms/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_cms_schema.sql b/ccm-cms/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_cms_schema.sql index 22df38715..36ecde772 100644 --- a/ccm-cms/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_cms_schema.sql +++ b/ccm-cms/src/test/resources-wildfly-remote-h2-mem/scripts/create_ccm_cms_schema.sql @@ -512,6 +512,18 @@ CREATE SCHEMA ccm_cms; primary key (ASSET_ID, REV) ); + create table CCM_CMS.FOLDER_CONTENT_SECTION_MAP ( + CONTENT_SECTION_ID bigint, + FOLDER_ID bigint not null, + primary key (FOLDER_ID) + ); + + create table CCM_CMS.FOLDERS ( + TYPE varchar(255) not null, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + create table CCM_CMS.IMAGES ( HEIGHT bigint, WIDTH bigint, @@ -1361,11 +1373,11 @@ CREATE SCHEMA ccm_cms; SETTING_ID bigint not null, CONFIGURATION_CLASS varchar(512) not null, NAME varchar(512) not null, + SETTING_VALUE_LONG bigint, + SETTING_VALUE_BOOLEAN boolean, + SETTING_VALUE_BIG_DECIMAL decimal(19,2), SETTING_VALUE_STRING varchar(1024), SETTING_VALUE_DOUBLE double, - SETTING_VALUE_BOOLEAN boolean, - SETTING_VALUE_LONG bigint, - SETTING_VALUE_BIG_DECIMAL decimal(19,2), primary key (SETTING_ID) ); @@ -1787,14 +1799,14 @@ create sequence hibernate_sequence start with 1 increment by 1; references CCM_CMS.CONTENT_SECTIONS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FKajweudfxaf7g2ydr2hcgqwcib + add constraint FKavcn4aakxsb7kt7hmqlx0ecu6 foreign key (ROOT_ASSETS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FK6g7kw4b6diqa0nks45ilp0vhs + add constraint FKd5sahsfsycq3i5icf3122ne8e foreign key (ROOT_DOCUMENTS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS add constraint FK72jh0axiiru87i61mppvaiv96 @@ -1981,6 +1993,21 @@ create sequence hibernate_sequence start with 1 increment by 1; foreign key (ASSET_ID, REV) references CCM_CMS.BINARY_ASSETS_AUD; + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKnof2m7o4f0ufrugeh4g5wt3g9 + foreign key (CONTENT_SECTION_ID) + references CCM_CMS.CONTENT_SECTIONS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKmmb7728dp707dljq282ch47k3 + foreign key (FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDERS + add constraint FK2ag06r5ywtuji2pkt68etlg48 + foreign key (OBJECT_ID) + references CCM_CORE.CATEGORIES; + alter table CCM_CMS.IMAGES add constraint FK51ja1101epvl74auenv6sqyev foreign key (LEGAL_METADATA_ID) diff --git a/ccm-cms/src/test/resources-wildfly-remote-pgsql/scripts/create_ccm_cms_schema.sql b/ccm-cms/src/test/resources-wildfly-remote-pgsql/scripts/create_ccm_cms_schema.sql index 07ea59be2..99f3a1fb0 100644 --- a/ccm-cms/src/test/resources-wildfly-remote-pgsql/scripts/create_ccm_cms_schema.sql +++ b/ccm-cms/src/test/resources-wildfly-remote-pgsql/scripts/create_ccm_cms_schema.sql @@ -7,6 +7,7 @@ CREATE SCHEMA ccm_core; CREATE SCHEMA ccm_cms; + create table CCM_CMS.ARTICLE_LEADS ( OBJECT_ID int8 not null, LOCALIZED_VALUE text, @@ -512,6 +513,18 @@ CREATE SCHEMA ccm_cms; primary key (ASSET_ID, REV) ); + create table CCM_CMS.FOLDER_CONTENT_SECTION_MAP ( + CONTENT_SECTION_ID int8, + FOLDER_ID int8 not null, + primary key (FOLDER_ID) + ); + + create table CCM_CMS.FOLDERS ( + TYPE varchar(255) not null, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + create table CCM_CMS.IMAGES ( HEIGHT int8, WIDTH int8, @@ -1361,11 +1374,11 @@ CREATE SCHEMA ccm_cms; SETTING_ID int8 not null, CONFIGURATION_CLASS varchar(512) not null, NAME varchar(512) not null, + SETTING_VALUE_LONG int8, + SETTING_VALUE_BOOLEAN boolean, + SETTING_VALUE_BIG_DECIMAL numeric(19, 2), SETTING_VALUE_STRING varchar(1024), SETTING_VALUE_DOUBLE float8, - SETTING_VALUE_BOOLEAN boolean, - SETTING_VALUE_LONG int8, - SETTING_VALUE_BIG_DECIMAL numeric(19, 2), primary key (SETTING_ID) ); @@ -1787,14 +1800,14 @@ create sequence hibernate_sequence start 1 increment 1; references CCM_CMS.CONTENT_SECTIONS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FKajweudfxaf7g2ydr2hcgqwcib + add constraint FKavcn4aakxsb7kt7hmqlx0ecu6 foreign key (ROOT_ASSETS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FK6g7kw4b6diqa0nks45ilp0vhs + add constraint FKd5sahsfsycq3i5icf3122ne8e foreign key (ROOT_DOCUMENTS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS add constraint FK72jh0axiiru87i61mppvaiv96 @@ -1981,6 +1994,21 @@ create sequence hibernate_sequence start 1 increment 1; foreign key (ASSET_ID, REV) references CCM_CMS.BINARY_ASSETS_AUD; + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKnof2m7o4f0ufrugeh4g5wt3g9 + foreign key (CONTENT_SECTION_ID) + references CCM_CMS.CONTENT_SECTIONS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKmmb7728dp707dljq282ch47k3 + foreign key (FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDERS + add constraint FK2ag06r5ywtuji2pkt68etlg48 + foreign key (OBJECT_ID) + references CCM_CORE.CATEGORIES; + alter table CCM_CMS.IMAGES add constraint FK51ja1101epvl74auenv6sqyev foreign key (LEGAL_METADATA_ID) diff --git a/ccm-cms/src/test/resources/datasets/create_ccm_cms_schema.sql b/ccm-cms/src/test/resources/datasets/create_ccm_cms_schema.sql index 22df38715..17eefa88c 100644 --- a/ccm-cms/src/test/resources/datasets/create_ccm_cms_schema.sql +++ b/ccm-cms/src/test/resources/datasets/create_ccm_cms_schema.sql @@ -6,7 +6,6 @@ DROP SEQUENCE IF EXISTS hibernate_sequence; CREATE SCHEMA ccm_core; CREATE SCHEMA ccm_cms; - create table CCM_CMS.ARTICLE_LEADS ( OBJECT_ID bigint not null, LOCALIZED_VALUE longvarchar, @@ -512,6 +511,18 @@ CREATE SCHEMA ccm_cms; primary key (ASSET_ID, REV) ); + create table CCM_CMS.FOLDER_CONTENT_SECTION_MAP ( + CONTENT_SECTION_ID bigint, + FOLDER_ID bigint not null, + primary key (FOLDER_ID) + ); + + create table CCM_CMS.FOLDERS ( + TYPE varchar(255) not null, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + create table CCM_CMS.IMAGES ( HEIGHT bigint, WIDTH bigint, @@ -1361,11 +1372,11 @@ CREATE SCHEMA ccm_cms; SETTING_ID bigint not null, CONFIGURATION_CLASS varchar(512) not null, NAME varchar(512) not null, + SETTING_VALUE_LONG bigint, + SETTING_VALUE_BOOLEAN boolean, + SETTING_VALUE_BIG_DECIMAL decimal(19,2), SETTING_VALUE_STRING varchar(1024), SETTING_VALUE_DOUBLE double, - SETTING_VALUE_BOOLEAN boolean, - SETTING_VALUE_LONG bigint, - SETTING_VALUE_BIG_DECIMAL decimal(19,2), primary key (SETTING_ID) ); @@ -1787,14 +1798,14 @@ create sequence hibernate_sequence start with 1 increment by 1; references CCM_CMS.CONTENT_SECTIONS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FKajweudfxaf7g2ydr2hcgqwcib + add constraint FKavcn4aakxsb7kt7hmqlx0ecu6 foreign key (ROOT_ASSETS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS - add constraint FK6g7kw4b6diqa0nks45ilp0vhs + add constraint FKd5sahsfsycq3i5icf3122ne8e foreign key (ROOT_DOCUMENTS_FOLDER_ID) - references CCM_CORE.CATEGORIES; + references CCM_CMS.FOLDERS; alter table CCM_CMS.CONTENT_SECTIONS add constraint FK72jh0axiiru87i61mppvaiv96 @@ -1981,6 +1992,21 @@ create sequence hibernate_sequence start with 1 increment by 1; foreign key (ASSET_ID, REV) references CCM_CMS.BINARY_ASSETS_AUD; + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKnof2m7o4f0ufrugeh4g5wt3g9 + foreign key (CONTENT_SECTION_ID) + references CCM_CMS.CONTENT_SECTIONS; + + alter table CCM_CMS.FOLDER_CONTENT_SECTION_MAP + add constraint FKmmb7728dp707dljq282ch47k3 + foreign key (FOLDER_ID) + references CCM_CMS.FOLDERS; + + alter table CCM_CMS.FOLDERS + add constraint FK2ag06r5ywtuji2pkt68etlg48 + foreign key (OBJECT_ID) + references CCM_CORE.CATEGORIES; + alter table CCM_CMS.IMAGES add constraint FK51ja1101epvl74auenv6sqyev foreign key (LEGAL_METADATA_ID) diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-other-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-other-folder.xml index d2fddefdc..f577216a0 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-other-folder.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-other-folder.xml @@ -198,11 +198,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml index dc0d5111f..cc96c26a0 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml @@ -199,11 +199,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml index 995cfaff8..05ee7763c 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml @@ -222,11 +222,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml index 605687643..a408686f3 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml @@ -235,11 +235,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move.xml index 91c3eaf48..082ab7eae 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move.xml @@ -189,11 +189,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml index 04f791474..1bd38b4cb 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml @@ -198,11 +198,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml index 0e9085521..e633d0449 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml @@ -201,11 +201,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml index 010d0a6ed..310c6af63 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml @@ -191,11 +191,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml index d0b3533ae..d270cf467 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml @@ -189,11 +189,29 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemRepositoryTest/after-save.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemRepositoryTest/after-save.xml index 4e6071b3a..625e40cb5 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemRepositoryTest/after-save.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemRepositoryTest/after-save.xml @@ -87,10 +87,20 @@ application_type="org.librecms.contentsection.ContentSection" primary_url="info" /> + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-add-role.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-add-role.xml index 7036a476e..6dcb35b98 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-add-role.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-add-role.xml @@ -46,12 +46,22 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-create-docs-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-create-docs-folder.xml new file mode 100644 index 000000000..c631b24c4 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-create-docs-folder.xml @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-delete-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-delete-folder.xml new file mode 100644 index 000000000..283ad286b --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-delete-folder.xml @@ -0,0 +1,408 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml new file mode 100644 index 000000000..4822445d3 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder.xml new file mode 100644 index 000000000..013d41929 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/data.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/data.xml new file mode 100644 index 000000000..7ecc054e5 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/FolderManagerTest/data.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/scripts/h2-cleanup.sql b/ccm-cms/src/test/resources/scripts/h2-cleanup.sql index 8c1fdfd1f..10ead7235 100644 --- a/ccm-cms/src/test/resources/scripts/h2-cleanup.sql +++ b/ccm-cms/src/test/resources/scripts/h2-cleanup.sql @@ -72,10 +72,14 @@ DELETE FROM ccm_cms.lifecycle_phase_definitions; DELETE FROM ccm_cms.lifecyle_definitions; +DELETE FROM ccm_cms.folder_content_section_map; + DELETE FROM ccm_cms.content_section_roles; DELETE FROM ccm_cms.content_sections; +DELETE FROM ccm_cms.folders; + DELETE FROM ccm_core.settings_string_list; DELETE FROM ccm_core.settings_l10n_str_values; diff --git a/ccm-core/src/main/java/org/libreccm/core/Resource.java b/ccm-core/src/main/java/org/libreccm/core/Resource.java index ab36befac..161645f43 100644 --- a/ccm-core/src/main/java/org/libreccm/core/Resource.java +++ b/ccm-core/src/main/java/org/libreccm/core/Resource.java @@ -218,7 +218,10 @@ public class Resource extends CcmObject implements Serializable { if (!Objects.equals(description, other.getDescription())) { return false; } - if (!Objects.equals(created, other.getCreated())) { + //Note: Objects.equals(created, other.getCreated() returns false even + //if the dates are true because Hibernate sets the value with a sub + //class of date. Solved by using getCreated()... + if (!Objects.equals(getCreated(), other.getCreated())) { return false; } return Objects.equals(parent, other.getParent());