CCM NG/ccm-cms: Still working on the FolderManipulator
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4613 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: d23818c69c
pull/2/head
parent
6a503b37a5
commit
159abff396
|
|
@ -60,6 +60,10 @@ import javax.transaction.Transactional;
|
|||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.Order;
|
||||
import javax.persistence.criteria.Path;
|
||||
import org.hibernate.tool.schema.internal.TargetFileImpl;
|
||||
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.librecms.contentsection.FolderManager;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
|
|
@ -77,6 +81,9 @@ public class FolderBrowserController {
|
|||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Inject
|
||||
private CcmObjectRepository ccmObjectRepo;
|
||||
|
||||
@Inject
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
|
|
@ -104,6 +111,9 @@ public class FolderBrowserController {
|
|||
@Inject
|
||||
private FolderRepository folderRepo;
|
||||
|
||||
@Inject
|
||||
private FolderManager folderManager;
|
||||
|
||||
private Locale defaultLocale;
|
||||
|
||||
/**
|
||||
|
|
@ -629,14 +639,14 @@ public class FolderBrowserController {
|
|||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
final List<List<String>> subFolderIds = sourceFolderIds
|
||||
.stream()
|
||||
.map(sourceFolderId -> findSubFolderIds(sourceFolderId))
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.map(sourceFolderId -> findSubFolderIds(sourceFolderId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<String> invalidTargetIds = new ArrayList<>();
|
||||
invalidTargetIds.addAll(sourceFolderIds);
|
||||
invalidTargetIds.addAll(parentFolderIds);
|
||||
for(final List<String> subFolderIdList : subFolderIds) {
|
||||
for (final List<String> subFolderIdList : subFolderIds) {
|
||||
invalidTargetIds.addAll(subFolderIdList);
|
||||
}
|
||||
|
||||
|
|
@ -690,8 +700,8 @@ public class FolderBrowserController {
|
|||
return findSubFolders(folder)
|
||||
.stream()
|
||||
.map(subFolder -> String.format("%s%d",
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||
subFolder.getObjectId()))
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||
subFolder.getObjectId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
@ -700,12 +710,12 @@ public class FolderBrowserController {
|
|||
Objects.requireNonNull(folder);
|
||||
|
||||
if (folder.getSubFolders() == null
|
||||
|| folder.getSubFolders().isEmpty()) {
|
||||
|| folder.getSubFolders().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<Folder> subFolders = new ArrayList<>();
|
||||
for(final Folder subFolder : folder.getSubFolders()) {
|
||||
for (final Folder subFolder : folder.getSubFolders()) {
|
||||
subFolders.add(subFolder);
|
||||
subFolders.addAll(findSubFolders(subFolder));
|
||||
}
|
||||
|
|
@ -713,4 +723,110 @@ public class FolderBrowserController {
|
|||
return subFolders;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void moveObjects(final Folder targetFolder,
|
||||
final String[] objectIds) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
Objects.requireNonNull(objectIds);
|
||||
|
||||
for (final String objectId : objectIds) {
|
||||
if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
moveFolder(targetFolder,
|
||||
Long.parseLong(objectId.substring(
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())));
|
||||
} else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ITEM)) {
|
||||
moveItem(targetFolder,
|
||||
Long.parseLong(objectId.substring(
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM.length())));
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"ID '%s' does not start with '%s' or '%s'.",
|
||||
objectId,
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFolder(final Folder targetFolder, final long folderId) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
|
||||
final Folder folder = folderRepo.findById(folderId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No folder with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
folderId)));
|
||||
|
||||
folderManager.moveFolder(folder, targetFolder);
|
||||
}
|
||||
|
||||
private void moveItem(final Folder targetFolder, final long itemId) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
|
||||
final ContentItem item = itemRepo.findById(itemId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No content item with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
itemId)));
|
||||
|
||||
itemManager.move(item, targetFolder);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void copyObjects(final Folder targetFolder,
|
||||
final String[] objectIds) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
Objects.requireNonNull(objectIds);
|
||||
|
||||
for (final String objectId : objectIds) {
|
||||
if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
copyFolder(targetFolder,
|
||||
Long.parseLong(objectId.substring(
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())));
|
||||
} else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ITEM)) {
|
||||
copyItem(targetFolder,
|
||||
Long.parseLong(objectId.substring(
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM.length())));
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"ID '%s' does not start with '%s' or '%s'.",
|
||||
objectId,
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFolder(final Folder targetFolder,
|
||||
final long folderId) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
|
||||
final Folder folder = folderRepo.findById(folderId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No folder with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
folderId)));
|
||||
|
||||
folderManager.copyFolder(folder, targetFolder);
|
||||
}
|
||||
|
||||
private void copyItem(final Folder targetFolder,
|
||||
final long itemId) {
|
||||
|
||||
Objects.requireNonNull(targetFolder);
|
||||
|
||||
final ContentItem item = itemRepo.findById(itemId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No content item with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
itemId)));
|
||||
|
||||
itemManager.copy(item, targetFolder);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,55 +203,22 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
return (String) state.getValue(actionParam);
|
||||
}
|
||||
|
||||
protected void moveItems(final Category target,
|
||||
final String[] itemIds) {
|
||||
protected void moveObjects(final Folder target, final String[] objectIds) {
|
||||
|
||||
for (String itemId : itemIds) {
|
||||
|
||||
changeItemParent(itemId, target);
|
||||
|
||||
}
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderBrowserController controller = cdiUtil.findBean(
|
||||
FolderBrowserController.class);
|
||||
|
||||
controller.moveObjects(target, objectIds);
|
||||
}
|
||||
|
||||
private void changeItemParent(final String itemId,
|
||||
final Category newParent) {
|
||||
protected void copyObjects(final Folder target, final String[] objectIds) {
|
||||
|
||||
//ToDo
|
||||
throw new UnsupportedOperationException();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderBrowserController controller = cdiUtil.findBean(
|
||||
FolderBrowserController.class);
|
||||
|
||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final ContentItemRepository itemRepo = cdiUtil.findBean(
|
||||
// ContentItemRepository.class);
|
||||
// final ContentItemManager itemManager = cdiUtil.findBean(
|
||||
// ContentItemManager.class);
|
||||
// final CategoryManager categoryManager = cdiUtil.findBean(
|
||||
// CategoryManager.class);
|
||||
// final ContentItem item = itemRepo.findById(itemId);
|
||||
// final Category itemFolder = itemManager.getItemFolders(item).
|
||||
// item.addCategory(newParent);
|
||||
// item.setParent(newParent);
|
||||
// item.save();
|
||||
}
|
||||
|
||||
protected void copyItems(final Category target,
|
||||
final String[] itemIds) {
|
||||
|
||||
//ToDo
|
||||
throw new UnsupportedOperationException();
|
||||
//
|
||||
// if (LOGGER.isDebugEnabled()) {
|
||||
// LOGGER.debug("Copying items " + Arrays.asList(itemIds) + " to "
|
||||
// + target);
|
||||
// }
|
||||
// for (BigDecimal itemId : itemIds) {
|
||||
//
|
||||
// final ContentItem source = retrieveSourceItem(itemId);
|
||||
//
|
||||
// final ContentItem newItem = source.copy(target, true);
|
||||
// Assert.isEqual(target, newItem.getParent());
|
||||
//
|
||||
// }
|
||||
controller.copyObjects(target, objectIds);
|
||||
}
|
||||
|
||||
// protected void publishItems(final BigDecimal[] itemIds) {
|
||||
|
|
@ -450,13 +417,13 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
itemView.setVisible(state, true);
|
||||
targetSelector.setVisible(state, false);
|
||||
|
||||
final Category folder = targetSelector.getTarget(state);
|
||||
final Folder folder = targetSelector.getTarget(state);
|
||||
final String[] itemIds = getSources(state);
|
||||
|
||||
if (isCopy(state)) {
|
||||
copyItems(folder, itemIds);
|
||||
copyObjects(folder, itemIds);
|
||||
} else if (isMove(state)) {
|
||||
moveItems(folder, itemIds);
|
||||
moveObjects(folder, itemIds);
|
||||
}
|
||||
|
||||
reset(state);
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ import com.arsdigita.cms.CMS;
|
|||
import com.arsdigita.ui.CcmObjectSelectionModel;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
|
||||
/**
|
||||
* Keeps track of the selection of an item in a folder. The objects that are
|
||||
* selected by this model are all subclasses of {@link
|
||||
|
|
@ -50,7 +50,7 @@ public class FolderSelectionModel extends CcmObjectSelectionModel<Folder> {
|
|||
@Override
|
||||
public Long getSelectedKey(final PageState state) {
|
||||
// FIXME: this code will go away once parameter models support init listeners
|
||||
Long result = super.getSelectedKey(state);
|
||||
final Long result = super.getSelectedKey(state);
|
||||
if (result == null) {
|
||||
result = getRootFolderID(state);
|
||||
setSelectedKey(state, result);
|
||||
|
|
@ -63,10 +63,24 @@ public class FolderSelectionModel extends CcmObjectSelectionModel<Folder> {
|
|||
super.setSelectedKey(state, key);
|
||||
}
|
||||
|
||||
public void setSelectedKey(final PageState state, final String key) {
|
||||
if (!key.startsWith(CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The string '%s' does not contain a folder id "
|
||||
+ "(it does not start with '%s').",
|
||||
key,
|
||||
CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER));
|
||||
}
|
||||
|
||||
final long keyAsLong = Long.parseLong(key.substring(
|
||||
CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()));
|
||||
setSelectedKey(state, keyAsLong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the selection by resetting it to the root folder id.
|
||||
*
|
||||
* @param state represents the cuerent request.
|
||||
* @param state represents the current request.
|
||||
*/
|
||||
@Override
|
||||
public void clearSelection(final PageState state) {
|
||||
|
|
@ -93,6 +107,7 @@ public class FolderSelectionModel extends CcmObjectSelectionModel<Folder> {
|
|||
/**
|
||||
* Return true, since this selection model will always have a folder
|
||||
* selected in it
|
||||
*
|
||||
* @param state
|
||||
* @return
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -113,11 +114,12 @@ public class FolderManager {
|
|||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Folder> getParentFolder(final Folder folder) {
|
||||
Objects.requireNonNull(folder);
|
||||
final Optional<Folder> theFolder = folderRepo.findById(folder.getObjectId());
|
||||
final Optional<Folder> theFolder = folderRepo.findById(folder.
|
||||
getObjectId());
|
||||
if (!theFolder.isPresent()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"The folder %s should be in the database but is not.",
|
||||
Objects.toString(folder)));
|
||||
"The folder %s should be in the database but is not.",
|
||||
Objects.toString(folder)));
|
||||
}
|
||||
final Category parentCategory = theFolder.get().getParentCategory();
|
||||
if (parentCategory == null) {
|
||||
|
|
@ -132,7 +134,7 @@ public class FolderManager {
|
|||
* 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 name The name of the new folder.
|
||||
* @param parent The folder in which the new folder is generated.
|
||||
*
|
||||
* @return The new folder.
|
||||
|
|
@ -141,16 +143,16 @@ public class FolderManager {
|
|||
public Folder createFolder(final String name, final Folder parent) {
|
||||
if (parent == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't create a folder without a parent folder.");
|
||||
"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");
|
||||
"Can't create a folder with an empty name");
|
||||
}
|
||||
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
KernelConfig.class);
|
||||
|
||||
final Folder folder = new Folder();
|
||||
folder.setName(name);
|
||||
|
|
@ -168,7 +170,7 @@ public class FolderManager {
|
|||
public FolderIsDeletable folderIsDeletable(final Folder folder) {
|
||||
if (folder == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't check if null is deletable.");
|
||||
"Can't check if null is deletable.");
|
||||
}
|
||||
|
||||
if (!folder.getSubCategories().isEmpty()) {
|
||||
|
|
@ -204,20 +206,20 @@ public class FolderManager {
|
|||
break;
|
||||
case HAS_SUBCATEGORIES:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Can't delete folder \"%s\" because the folder is not empty",
|
||||
getFolderPath(folder, true)));
|
||||
"Can't delete folder \"%s\" because the folder is not empty",
|
||||
getFolderPath(folder, true)));
|
||||
case IS_NOT_EMPTY:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Can't delete folder \"%s\" because the folder is not empty.",
|
||||
getFolderPath(folder)));
|
||||
"Can't delete folder \"%s\" because the folder is not empty.",
|
||||
getFolderPath(folder)));
|
||||
case IS_ROOT_FOLDER:
|
||||
throw new IllegalArgumentException(
|
||||
"The folder to delete is a root folder can can't be deleted.");
|
||||
"The folder to delete is a root folder can can't be deleted.");
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Unexpected return value from #folderIsDeletable: "
|
||||
+ "\"%s\".",
|
||||
status.toString()));
|
||||
"Unexpected return value from #folderIsDeletable: "
|
||||
+ "\"%s\".",
|
||||
status.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,15 +235,8 @@ public class FolderManager {
|
|||
@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");
|
||||
}
|
||||
Objects.requireNonNull(folder, "Can't move folder null");
|
||||
Objects.requireNonNull(target, "Can't move a folder to folder null");
|
||||
|
||||
final FolderIsMovable status = folderIsMovable(folder, target);
|
||||
switch (status) {
|
||||
|
|
@ -249,18 +244,17 @@ public class FolderManager {
|
|||
final Folder source = getParentFolder(folder).get();
|
||||
categoryManager.removeSubCategoryFromCategory(folder, source);
|
||||
final boolean sameName = target.getSubCategories()
|
||||
.stream()
|
||||
.anyMatch(subCategory -> folder.getName().equals(
|
||||
subCategory
|
||||
.getName()));
|
||||
.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);
|
||||
findConfiguration(
|
||||
KernelConfig.class);
|
||||
folder.getTitle().addValue(kernelConfig.getDefaultLocale(),
|
||||
name);
|
||||
}
|
||||
|
|
@ -269,36 +263,36 @@ public class FolderManager {
|
|||
}
|
||||
case IS_ROOT_FOLDER:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The folder \"%s\" to move is a root folder can can't "
|
||||
+ "be moved.",
|
||||
getFolderPath(folder)));
|
||||
"The folder \"%s\" to move is a root folder can can't "
|
||||
+ "be moved.",
|
||||
getFolderPath(folder)));
|
||||
case SAME_FOLDER:
|
||||
throw new IllegalArgumentException(
|
||||
"The folder to move and the target folder are the same "
|
||||
+ "folder.");
|
||||
"The folder to move and the target folder are the same "
|
||||
+ "folder.");
|
||||
case DIFFERENT_SECTIONS:
|
||||
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()));
|
||||
"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()));
|
||||
case DIFFERENT_TYPES:
|
||||
throw new IllegalArgumentException(
|
||||
"The folder to move is a \"%s\","
|
||||
+ "but the target folder is a \"%s\" folder.");
|
||||
"The folder to move is a \"%s\","
|
||||
+ "but the target folder is a \"%s\" folder.");
|
||||
case HAS_LIVE_ITEMS:
|
||||
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)));
|
||||
"Can't move folder \"%s\" because some items in the "
|
||||
+ "folder or its sub folder are live.",
|
||||
getFolderPath(folder, true)));
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Unexpected return value from #folderIsMovable: %s",
|
||||
status.toString()));
|
||||
"Unexpected return value from #folderIsMovable: %s",
|
||||
status.toString()));
|
||||
}
|
||||
|
||||
// if (folder.getParentFolder()
|
||||
|
|
@ -366,7 +360,7 @@ public class FolderManager {
|
|||
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't check if a server can be moved to null.");
|
||||
"Can't check if a server can be moved to null.");
|
||||
}
|
||||
|
||||
if (!getParentFolder(folder).isPresent()) {
|
||||
|
|
@ -392,6 +386,28 @@ public class FolderManager {
|
|||
return FolderIsMovable.YES;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void copyFolder(final Folder folder, final Folder target) {
|
||||
|
||||
Objects.requireNonNull(folder, "Can't move null to a folder.");
|
||||
Objects.requireNonNull(target, "Can't move a folder to null.");
|
||||
|
||||
final Folder copy = createFolder(folder.getName(), target);
|
||||
final List<ContentItem> items = folder.getObjects()
|
||||
.stream()
|
||||
.map(categorization -> categorization.getCategorizedObject())
|
||||
.filter(object -> object instanceof ContentItem)
|
||||
.map(object -> (ContentItem) object)
|
||||
.collect(Collectors.toList());
|
||||
for (final ContentItem item : items) {
|
||||
itemManager.copy(item, target);
|
||||
}
|
||||
|
||||
for(final Folder subFolder : folder.getSubFolders()) {
|
||||
copyFolder(subFolder, copy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper method for checking if there any live items in a given
|
||||
* folder or its sub folders.
|
||||
|
|
@ -399,19 +415,19 @@ public class FolderManager {
|
|||
* @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.
|
||||
* 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));
|
||||
.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));
|
||||
.stream()
|
||||
.anyMatch(subFolder -> liveItemsInFolder(subFolder));
|
||||
|
||||
return liveItemsInFolder || liveItemsInSubFolders;
|
||||
}
|
||||
|
|
@ -422,7 +438,7 @@ public class FolderManager {
|
|||
* @param folder The folder.
|
||||
*
|
||||
* @return The path of the folder as a UNIX-like path, but without the
|
||||
* content section as prefix.
|
||||
* content section as prefix.
|
||||
*/
|
||||
public String getFolderPath(final Folder folder) {
|
||||
return getFolderPath(folder, false);
|
||||
|
|
@ -431,12 +447,12 @@ public class FolderManager {
|
|||
/**
|
||||
* Returns the path of folder.
|
||||
*
|
||||
* @param folder The folder.
|
||||
* @param folder The folder.
|
||||
* @param withContentSection Whether to include the content section in the
|
||||
* path.
|
||||
* path.
|
||||
*
|
||||
* @return The path of the folder as a UNIX-like path, optionally with the
|
||||
* content section the folder belongs to as prefix..
|
||||
* content section the folder belongs to as prefix..
|
||||
*/
|
||||
public String getFolderPath(final Folder folder,
|
||||
final boolean withContentSection) {
|
||||
|
|
@ -476,13 +492,13 @@ public class FolderManager {
|
|||
|
||||
if (folder == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't create a list of parent folder for folder null.");
|
||||
"Can't create a list of parent folder for folder null.");
|
||||
}
|
||||
|
||||
final List<Folder> folders = new ArrayList<>();
|
||||
if (getParentFolder(folder).isPresent()) {
|
||||
Optional<Folder> currentFolder = getParentFolder(folder);
|
||||
while(currentFolder.isPresent()) {
|
||||
while (currentFolder.isPresent()) {
|
||||
folders.add(currentFolder.get());
|
||||
currentFolder = getParentFolder(currentFolder.get());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,3 +123,5 @@ cms.contenttypes.ui.name=Name (URL fragment)
|
|||
cms.ui.content_section=Content Section:
|
||||
cms.ui.folderform.error.child.name_not_unique=The current folder already contains a child with the name {0}.
|
||||
cms.ui.folderform.error.parent.name_not_unique=The parent folder of the selected folder already contains a child with the name {0}.
|
||||
cms.ui.choose_target_folder=Choose target folder
|
||||
cms.ui.folder.copy=Copy {0} items from {1}
|
||||
|
|
|
|||
|
|
@ -122,3 +122,5 @@ cms.contenttypes.ui.name=Name (URL-Fragment)
|
|||
cms.ui.content_section=Content Section:
|
||||
cms.ui.folderform.error.child.name_not_unique=Der derzeit ausgew\u00e4hlte Ordner enth\u00e4lt bereits einen Ordner oder ein Dokument mit dem Namen {0}.
|
||||
cms.ui.folderform.error.parent.name_not_unique=Der \u00fcbergeordnete Ordner enth\u00e4lt bereits einen ein Objekt mit dem Namen {0}.
|
||||
cms.ui.choose_target_folder=Zielordner ausw\u00e4hlen
|
||||
cms.ui.folder.copy=Kopiere {0} Dokumente von {1} nach
|
||||
|
|
|
|||
|
|
@ -91,3 +91,5 @@ cms.contenttypes.ui.name=Name (URL fragment)
|
|||
cms.ui.content_section=Content Section:
|
||||
cms.ui.folderform.error.child.name_not_unique=The current folder already contains a child with the name {0}.
|
||||
cms.ui.folderform.error.parent.name_not_unique=The parent folder of the selected folder already contains a child with the name {0}.
|
||||
cms.ui.choose_target_folder=Choose target folder
|
||||
cms.ui.folder.copy=Copy {0} items from {1}
|
||||
|
|
|
|||
Loading…
Reference in New Issue