CCM NG: Several small things

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4556 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2017-02-08 15:01:21 +00:00
parent 59235f45af
commit e9bcd0c0ff
29 changed files with 231 additions and 212 deletions

View File

@ -29,6 +29,7 @@ import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.contentsection.FolderManager;
class FolderEditForm extends FolderBaseForm {
@ -52,7 +53,11 @@ class FolderEditForm extends FolderBaseForm {
final FolderRequestLocal parent = new FolderRequestLocal(null) {
@Override
protected final Object initialValue(final PageState state) {
return folder.getFolder(state).getParentFolder();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final FolderManager folderManager = cdiUtil.findBean(
FolderManager.class);
return folderManager.getParentFolder(getFolder(state))
.orElse(null);
}
};

View File

@ -21,14 +21,17 @@ package com.arsdigita.cms.ui.permissions;
import com.arsdigita.cms.CMS;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Permission;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
@ -42,6 +45,9 @@ import javax.transaction.Transactional;
@RequestScoped
class CMSPermissionsTableController {
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private PermissionManager permissionManager;
@ -52,7 +58,14 @@ class CMSPermissionsTableController {
public List<CMSPermissionsTableRow> buildDirectPermissionsRows(
final CcmObject object) {
final List<Role> roles = CMS.getContext().getContentSection().getRoles();
final Optional<ContentSection> section = sectionRepo.findById(CMS
.getContext().getContentSection().getObjectId());
final List<Role> roles = section
.orElseThrow(() -> new UnexpectedErrorException(String.format(
"The content section %s from the CMS context was not found in"
+ "the database.",
Objects.toString(CMS.getContext().getContentSection()))))
.getRoles();
return roles.stream()
.map(role -> buildRow(role, object))
@ -63,7 +76,7 @@ class CMSPermissionsTableController {
}
private CMSPermissionsTableRow buildRow(final Role role,
final CcmObject object) {
final CcmObject object) {
final List<String> privileges = permissionManager
.listDefiniedPrivileges(ItemPrivileges.class);
@ -79,8 +92,8 @@ class CMSPermissionsTableController {
}
private CMSPermissionsTableColumn buildColumn(final Role role,
final CcmObject object,
final String privilege) {
final CcmObject object,
final String privilege) {
final CMSPermissionsTableColumn column = new CMSPermissionsTableColumn();
column.setPrivilege(privilege);

View File

@ -24,6 +24,7 @@ import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.Configuration;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.Setting;
import org.libreccm.core.UnexpectedErrorException;
import org.librecms.dispatcher.ItemResolver;
import org.librecms.dispatcher.SimpleItemResolver;
@ -695,7 +696,7 @@ public class CMSConfig {
resolverClasses.add((Class<ItemResolver>) Class.forName(
className));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(String.format(
throw new UnexpectedErrorException(String.format(
"ItemResolver class \"%s\" not found.", className), ex);
}
}
@ -720,7 +721,7 @@ public class CMSConfig {
// resolverClasses.add((Class<TemplateResolver>) Class.forName(
// className));
// } catch (ClassNotFoundException ex) {
// throw new UncheckedWrapperException(String.format(
// throw new UnexpectedErrorException(String.format(
// "ItemResolver class \"%s\" not found.", className), ex);
// }
// }

View File

@ -18,8 +18,6 @@
*/
package org.librecms.contentsection;
import com.arsdigita.util.UncheckedWrapperException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -45,6 +43,7 @@ import org.librecms.contentsection.privileges.AssetPrivileges;
import java.util.Objects;
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.LocalizedString;
import java.beans.BeanInfo;
@ -68,7 +67,7 @@ import static org.librecms.CmsConstants.*;
public class AssetManager {
private static final Logger LOGGER = LogManager.
getLogger(AssetManager.class);
getLogger(AssetManager.class);
@Inject
private EntityManager entityManager;
@ -94,15 +93,15 @@ public class AssetManager {
* thrown.
*
*
* @param asset The {@link Asset} to share.
* @param asset The {@link Asset} to share.
* @param folder The {@link Folder} in which the {@link Asset} is created.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public void shareAsset(
final Asset asset,
@RequiresPrivilege(AssetPrivileges.CREATE_NEW)
final Folder folder) {
final Asset asset,
@RequiresPrivilege(AssetPrivileges.CREATE_NEW)
final Folder folder) {
if (asset == null) {
throw new IllegalArgumentException("Can't share asset null.");
@ -114,14 +113,14 @@ public class AssetManager {
if (isShared(asset)) {
throw new IllegalArgumentException(String.format(
"The asset %s is already shared.",
Objects.toString(asset)));
"The asset %s is already shared.",
Objects.toString(asset)));
}
categoryManager.addObjectToCategory(
asset,
folder,
CmsConstants.CATEGORIZATION_TYPE_FOLDER);
asset,
folder,
CmsConstants.CATEGORIZATION_TYPE_FOLDER);
}
/**
@ -132,12 +131,12 @@ public class AssetManager {
* @param asset The asset the check.
*
* @return {@code true} is the {@link Asset} is shared,
* {@code false if not}.
* {@code false if not}.
*/
public boolean isShared(final Asset asset) {
if (asset == null) {
throw new IllegalArgumentException(
"Can't determine if null is a shared asset.");
"Can't determine if null is a shared asset.");
}
return getAssetFolder(asset).isPresent();
@ -153,9 +152,9 @@ public class AssetManager {
final List<Asset> assets = assetRepo.findAll();
final List<Asset> orphaned = assets.stream()
.filter(asset -> asset.getCategories().isEmpty()
&& asset.getItemAttachments().isEmpty()).
collect(Collectors.toList());
.filter(asset -> asset.getCategories().isEmpty()
&& asset.getItemAttachments().isEmpty()).
collect(Collectors.toList());
orphaned.forEach(orphan -> assetRepo.delete(orphan));
}
@ -163,17 +162,17 @@ public class AssetManager {
/**
* Moves an {@link Asset} to an folder.
*
* @param asset The {@link Asset} to move.
* @param asset The {@link Asset} to move.
* @param targetFolder The folder to which the {@link Asset} is moved. Must
* be an asset folder.
* be an asset folder.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public void move(
@RequiresPrivilege(AssetPrivileges.EDIT)
final Asset asset,
@RequiresPrivilege(AssetPrivileges.CREATE_NEW)
final Folder targetFolder) {
@RequiresPrivilege(AssetPrivileges.EDIT)
final Asset asset,
@RequiresPrivilege(AssetPrivileges.CREATE_NEW)
final Folder targetFolder) {
if (asset == null) {
throw new IllegalArgumentException("No asset to move provided.");
@ -185,8 +184,8 @@ public class AssetManager {
if (targetFolder.getType() != FolderType.ASSETS_FOLDER) {
throw new IllegalArgumentException(String.format(
"The provided target folder %s is not an asset folder.",
Objects.toString(targetFolder)));
"The provided target folder %s is not an asset folder.",
Objects.toString(targetFolder)));
}
final Optional<Folder> currentFolder = getAssetFolder(asset);
@ -196,7 +195,7 @@ public class AssetManager {
categoryManager.removeObjectFromCategory(asset,
currentFolder.get());
} catch (ObjectNotAssignedToCategoryException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}
@ -208,7 +207,7 @@ public class AssetManager {
/**
* Copies an {@link Asset}.
*
* @param asset The {@link Asset} to copy.
* @param asset The {@link Asset} to copy.
* @param targetFolder The folder to which the {@link Asset} is copied.
*
* @return The copy of the {@code asset}.
@ -230,26 +229,26 @@ public class AssetManager {
if (targetFolder.getType() != FolderType.ASSETS_FOLDER) {
throw new IllegalArgumentException(String.format(
"The provided target folder %s is not an asset folder.",
Objects.toString(targetFolder)));
"The provided target folder %s is not an asset folder.",
Objects.toString(targetFolder)));
}
final Asset copy;
try {
copy = asset.getClass().newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(asset.getClass());
} catch (IntrospectionException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
for (final PropertyDescriptor propertyDescriptor : beanInfo
.getPropertyDescriptors()) {
.getPropertyDescriptors()) {
if (propertyIsExcluded(propertyDescriptor.getName())) {
continue;
}
@ -269,49 +268,49 @@ public class AssetManager {
source = (LocalizedString) readMethod.invoke(asset);
target = (LocalizedString) readMethod.invoke(copy);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
| IllegalArgumentException
| InvocationTargetException ex) {
throw new RuntimeException(ex);
}
source.getAvailableLocales().forEach(
locale -> target.addValue(locale,
source.getValue(locale)));
locale -> target.addValue(locale,
source.getValue(locale)));
} else if (propType != null
&& propType.isAssignableFrom(Asset.class)) {
&& propType.isAssignableFrom(Asset.class)) {
final Asset linkedAsset;
try {
linkedAsset = (Asset) readMethod.invoke(asset);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
try {
writeMethod.invoke(copy, linkedAsset);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
} else if (propType != null
&& propType.isAssignableFrom(List.class)) {
&& propType.isAssignableFrom(List.class)) {
final List<Object> source;
final List<Object> target;
try {
source = (List<Object>) readMethod.invoke(asset);
target = (List<Object>) readMethod.invoke(copy);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
target.addAll(source);
} else if (propType != null
&& propType.isAssignableFrom(Map.class)) {
&& propType.isAssignableFrom(Map.class)) {
final Map<Object, Object> source;
final Map<Object, Object> target;
@ -319,14 +318,14 @@ public class AssetManager {
source = (Map<Object, Object>) readMethod.invoke(asset);
target = (Map<Object, Object>) readMethod.invoke(copy);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new RuntimeException(ex);
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
source.forEach((key, value) -> target.put(key, value));
} else if (propType != null
&& propType.isAssignableFrom(Set.class)) {
&& propType.isAssignableFrom(Set.class)) {
final Set<Object> source;
final Set<Object> target;
@ -334,8 +333,8 @@ public class AssetManager {
source = (Set<Object>) readMethod.invoke(asset);
target = (Set<Object>) readMethod.invoke(copy);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
| IllegalArgumentException
| InvocationTargetException ex) {
throw new RuntimeException(ex);
}
@ -346,17 +345,17 @@ public class AssetManager {
value = readMethod.invoke(asset);
writeMethod.invoke(copy, value);
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
}
}
if (targetFolder.equals(getAssetFolder(asset).orElse(null))) {
final long number = assetRepo.countFilterByFolderAndName(
targetFolder, String.format("%s_copy",
asset.getDisplayName()));
targetFolder, String.format("%s_copy",
asset.getDisplayName()));
final long index = number + 1;
copy.setDisplayName(String.format("%s_copy%d",
copy.getDisplayName(),
@ -395,7 +394,7 @@ public class AssetManager {
* @param asset The {@link Asset} to check for usage.
*
* @return {@code true} if the {@link Asset} is in use, {@link false} if
* not.
* not.
*/
@Transactional(Transactional.TxType.REQUIRED)
public boolean isAssetInUse(final Asset asset) {
@ -414,7 +413,7 @@ public class AssetManager {
* @param asset The {@link Assset} for which the path is generated.
*
* @return The path of the {@link Asset}. If the {@link Asset} is a non
* shared asset the path is empty.
* shared asset the path is empty.
*
* @see #getAssetPath(org.librecms.assets.Asset, boolean)
*/
@ -425,23 +424,24 @@ public class AssetManager {
/**
* Returns the path of an item as String.
*
* @param asset The {@link Asset} for which the path is generated.
* @param asset The {@link Asset} for which the path is
* generated.
* @param withContentSection Whether to include the content section into the
* path or not.
* path or not.
*
* @return The path of the asset. For non shared assets this is an empty
* string.
* string.
*
* @see #getAssetPath(org.librecms.assets.Asset)
*/
public String getAssetPath(final Asset asset,
final boolean withContentSection) {
final List<Categorization> result = asset.getCategories().stream()
.filter(categorization -> {
return CATEGORIZATION_TYPE_FOLDER.equals(
categorization.getType());
})
.collect(Collectors.toList());
.filter(categorization -> {
return CATEGORIZATION_TYPE_FOLDER.equals(
categorization.getType());
})
.collect(Collectors.toList());
if (result.isEmpty()) {
return "";
@ -459,9 +459,16 @@ public class AssetManager {
final String path = String.join("/", tokens);
if (withContentSection) {
final String sectionName
= ((Folder) result.get(0).getCategory()).
getSection().getDisplayName();
final Category category = result.get(0).getCategory();
final Optional<Folder> folder = folderRepo.findById(
category.getObjectId());
final String sectionName;
if (folder.isPresent()) {
sectionName = folder.get().getSection().getDisplayName();
} else {
sectionName = "?";
}
return String.format("%s:/%s", sectionName, path);
} else {
return String.format("/%s", path);
@ -475,15 +482,15 @@ public class AssetManager {
* @param asset
*
* @return A list of the folders which form the path of the asset. For non
* shared assets an empty list is returned.
* shared assets an empty list is returned.
*/
public List<Folder> getAssetFolders(final Asset asset) {
final List<Categorization> result = asset.getCategories().stream()
.filter(categorization -> {
return CATEGORIZATION_TYPE_FOLDER.equals(categorization
.getType());
})
.collect(Collectors.toList());
.filter(categorization -> {
return CATEGORIZATION_TYPE_FOLDER.equals(categorization
.getType());
})
.collect(Collectors.toList());
final List<Folder> folders = new ArrayList<>();
if (!result.isEmpty()) {
@ -492,12 +499,12 @@ public class AssetManager {
folders.add((Folder) current);
} else {
throw new IllegalArgumentException(String.format(
"The asset %s is assigned to the category %s with the"
+ "categorization type \"%s\", but the Category is not"
"The asset %s is assigned to the category %s with the"
+ "categorization type \"%s\", but the Category is not"
+ "a folder. This is no supported.",
asset.getUuid(),
current.getUuid(),
CATEGORIZATION_TYPE_FOLDER));
asset.getUuid(),
current.getUuid(),
CATEGORIZATION_TYPE_FOLDER));
}
while (current.getParentCategory() != null) {
@ -506,12 +513,12 @@ public class AssetManager {
folders.add((Folder) current);
} else {
throw new IllegalArgumentException(String.format(
"The asset %s is assigned to the category %s with the"
"The asset %s is assigned to the category %s with the"
+ "categorization type \"%s\", but the Category is not"
+ "a folder. This is no supported.",
asset.getUuid(),
current.getUuid(),
CATEGORIZATION_TYPE_FOLDER));
+ "a folder. This is no supported.",
asset.getUuid(),
current.getUuid(),
CATEGORIZATION_TYPE_FOLDER));
}
}
}
@ -526,27 +533,29 @@ public class AssetManager {
* @param asset The asset.
*
* @return The folder in which the asset is placed. If the asset is a non
* shared asset an empty {@link Optional} is returned.
* shared asset an empty {@link Optional} is returned.
*/
public Optional<Folder> getAssetFolder(final Asset asset) {
if (asset == null) {
throw new IllegalArgumentException(
"Can't retrieve the folder for asset null.");
"Can't retrieve the folder for asset null.");
}
if (asset.getCategories() == null) {
return Optional.empty();
}
return asset.getCategories().stream()
.filter(categorization -> {
return CATEGORIZATION_TYPE_FOLDER.equals(
categorization.getType());
})
.map(categorization -> {
return (Folder) categorization.getCategory();
})
.findFirst();
final Optional<Category> category = asset.getCategories().stream()
.filter(categorization -> CATEGORIZATION_TYPE_FOLDER.equals(
categorization.getType()))
.map(categorization -> categorization.getCategory())
.findFirst();
if (category.isPresent()) {
return folderRepo.findById(category.get().getObjectId());
} else {
return Optional.empty();
}
}
}

View File

@ -18,13 +18,13 @@
*/
package org.librecms.contentsection;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.auditing.AbstractAuditedEntityRepository;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.core.CcmObjectRepository;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
import org.librecms.contentsection.privileges.AssetPrivileges;
@ -130,7 +130,7 @@ public class AssetRepository
try {
categoryManager.removeObjectFromCategory(asset, category);
} catch (ObjectNotAssignedToCategoryException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}

View File

@ -19,14 +19,13 @@
package org.librecms.contentsection;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.RequiresPrivilege;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.beans.IntrospectionException;
@ -91,7 +90,7 @@ public class ContentItemL10NManager {
LocalizedString.class))
.collect(Collectors.toList());
} catch (IntrospectionException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}
@ -102,7 +101,7 @@ public class ContentItemL10NManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}

View File

@ -19,7 +19,6 @@
package org.librecms.contentsection;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -42,6 +41,7 @@ import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
@ -68,8 +68,8 @@ import java.util.UUID;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.librecms.contentsection.privileges.TypePrivileges;
/**
@ -615,7 +615,7 @@ public class ContentItemManager {
try {
target = source.getClass().newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
copyAsset(source, target);
@ -655,7 +655,7 @@ public class ContentItemManager {
try {
beanInfo = Introspector.getBeanInfo(source.getClass());
} catch (IntrospectionException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
for (final PropertyDescriptor propertyDescriptor : beanInfo.
@ -685,7 +685,7 @@ public class ContentItemManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
copyLocalizedString(sourceStr, targetStr);
@ -697,7 +697,7 @@ public class ContentItemManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}
}
@ -860,7 +860,7 @@ public class ContentItemManager {
targetAsset = sourceAttachment.getAsset().getClass()
.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
copyAsset(sourceAsset, targetAsset);

View File

@ -19,11 +19,11 @@
package org.librecms.contentsection;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.CoreConstants;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.Permission;
import org.libreccm.security.PermissionManager;
@ -459,14 +459,14 @@ public class ContentSectionManager {
itemResolverClazz);
if (instance.isUnsatisfied()) {
throw new UncheckedWrapperException(String.format(
throw new UnexpectedErrorException(String.format(
"No ItemResolver \"{}\" found.",
itemResolverClazz.getName()));
} else {
return instance.get();
}
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}

View File

@ -107,14 +107,14 @@ public class Folder extends Category implements Serializable {
.collect(Collectors.toList()));
}
public Folder getParentFolder() {
final Category parent = getParentCategory();
if (parent == null) {
return null;
} else {
return (Folder) getParentCategory();
}
}
// public Folder getParentFolder() {
// final Category parent = getParentCategory();
// if (parent == null) {
// return null;
// } else {
// return (Folder) getParentCategory();
// }
// }
@Override
public int hashCode() {

View File

@ -20,12 +20,14 @@ package org.librecms.contentsection;
import com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.configuration.ConfigurationManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
@ -106,6 +108,15 @@ public class FolderManager {
HAS_LIVE_ITEMS
}
public Optional<Folder> getParentFolder(final Folder folder) {
final Category parentCategory = folder.getParentCategory();
if (parentCategory == null) {
return Optional.empty();
} else {
return folderRepo.findById(parentCategory.getObjectId());
}
}
/**
* 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
@ -158,7 +169,7 @@ public class FolderManager {
return FolderIsDeletable.IS_NOT_EMPTY;
}
if (folder.getParentFolder() == null) {
if (!getParentFolder(folder).isPresent()) {
return FolderIsDeletable.IS_ROOT_FOLDER;
}
@ -225,7 +236,7 @@ public class FolderManager {
final FolderIsMovable status = folderIsMovable(folder, target);
switch (status) {
case YES: {
final Folder source = folder.getParentFolder();
final Folder source = getParentFolder(folder).get();
categoryManager.removeSubCategoryFromCategory(folder, source);
final boolean sameName = target.getSubCategories()
.stream()
@ -348,7 +359,7 @@ public class FolderManager {
"Can't check if a server can be moved to null.");
}
if (folder.getParentFolder() == null) {
if (!getParentFolder(folder).isPresent()) {
return FolderIsMovable.IS_ROOT_FOLDER;
}
@ -427,8 +438,8 @@ public class FolderManager {
tokens.add(folder.getName());
Folder current = folder;
while (current.getParentFolder() != null) {
current = current.getParentFolder();
while (getParentFolder(current).isPresent()) {
current = getParentFolder(current).get();
tokens.add(current.getName());
}
@ -458,11 +469,11 @@ public class FolderManager {
}
final List<Folder> folders = new ArrayList<>();
if (folder.getParentFolder() != null) {
Folder currentFolder = folder.getParentFolder();
while(currentFolder != null) {
folders.add(currentFolder);
currentFolder = folder.getParentFolder();
if (getParentFolder(folder).isPresent()) {
Optional<Folder> currentFolder = getParentFolder(folder);
while(currentFolder.isPresent()) {
folders.add(currentFolder.get());
currentFolder = getParentFolder(currentFolder.get());
}
}

View File

@ -19,8 +19,8 @@
package org.librecms.workflow;
import com.arsdigita.cms.workflow.TaskURLGenerator;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.core.UnexpectedErrorException;
import org.librecms.contentsection.ContentItem;
import javax.enterprise.context.RequestScoped;
@ -48,7 +48,7 @@ public class CmsTaskManager {
urlGenerator = urlGeneratorClass.newInstance();
} catch (IllegalAccessException
| InstantiationException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
return urlGenerator.generateURL(item.getObjectId(), task.getTaskId());

View File

@ -18,11 +18,10 @@
*/
package org.libreccm.pagemodel;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.core.CoreConstants;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.modules.CcmModule;
import org.libreccm.modules.Module;
import org.libreccm.security.AuthorizationRequired;
@ -301,7 +300,7 @@ public class PageModelManager {
try {
liveModel = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
liveModel.setModelUuid(draftModel.getModelUuid());
@ -310,7 +309,7 @@ public class PageModelManager {
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
for (final PropertyDescriptor propertyDescriptor : beanInfo.
@ -338,7 +337,7 @@ public class PageModelManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
target.addAll(source);
@ -354,7 +353,7 @@ public class PageModelManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
source.forEach((key, value) -> target.put(key, value));
@ -371,7 +370,7 @@ public class PageModelManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
target.addAll(source);
@ -383,7 +382,7 @@ public class PageModelManager {
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
}
}

View File

@ -35,9 +35,8 @@ import java.util.List;
/**
* Abstract class responsible for ex- and importing entity-objects to several
* file-formats. Every entity-class (e.g. DocRepo.File) needs to have its own
* extension of this class to override the abstract methods, making it
* possible to ex- or import that extending entity-class (e.g. DocRepo
* .FileMarshal).
* extension of this class to override the abstract methods, making it possible
* to ex- or import that extending entity-class (e.g. DocRepo .FileMarshal).
*
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
* @version created the 2/10/16
@ -45,8 +44,8 @@ import java.util.List;
*/
public abstract class AbstractMarshaller<P extends Portable> {
private static final Logger LOGGER = LogManager.getLogger(AbstractMarshaller
.class);
private static final Logger LOGGER = LogManager.getLogger(
AbstractMarshaller.class);
private Format format;
private String filename;
@ -55,13 +54,13 @@ public abstract class AbstractMarshaller<P extends Portable> {
ObjectMapper xmlMapper;
/**
* Prepares import and export routine. Sets the format in which the ex-
* or import will take place and sets the name of the file exported to or
* Prepares import and export routine. Sets the format in which the ex- or
* import will take place and sets the name of the file exported to or
* imported from. Furthermore it is possible to decide for or against
* indentation in the output file.
*
* @param format The format of the ex-/import
* @param filename The filename of the file exported to or imported from
* @param format The format of the ex-/import
* @param filename The filename of the file exported to or imported from
* @param indentation whether or not indentation
*/
public void prepare(final Format format,
@ -83,20 +82,19 @@ public abstract class AbstractMarshaller<P extends Portable> {
break;
default:
break;
}
}
/**
* Same as {@code prepare}-methode above. Adds distinction between path
* and filename.
* Same as {@code prepare}-methode above. Adds distinction between path and
* filename.
*
* @param format The format of the ex-/import
* @param folderPath The folderPath of the file exported to or imported
* from
* @param filename The filename of the file exported to or imported from
* @param format The format of the ex-/import
* @param folderPath The folderPath of the file exported to or imported
* from
* @param filename The filename of the file exported to or imported from
* @param indentation whether or not indentation
*/
public void prepare(final Format format,
@ -108,7 +106,6 @@ public abstract class AbstractMarshaller<P extends Portable> {
}
}
/**
* Export routine for lists with the same object type {@code P}. Creates a
* new file with the prepared filename and starts, depending on the set
@ -123,8 +120,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
try {
fileWriter = new FileWriter(file);
} catch (IOException e) {
LOGGER.error("Unable to open a fileWriter for the file" +
" with the name {}.", file.getName());
LOGGER.error("Unable to open a fileWriter for the file"
+ " with the name {}.", file.getName());
LOGGER.error(e);
}
if (fileWriter != null) {
@ -137,9 +134,9 @@ public abstract class AbstractMarshaller<P extends Portable> {
line = xmlMapper.writeValueAsString(object);
//LOGGER.info(line);
} catch (IOException e) {
LOGGER.error("Unable to write objetct " +
"of class {} as XML string with name {}.",
object.getClass(), file.getName());
LOGGER.error("Unable to write objetct "
+ "of class {} as XML string with name {}.",
object.getClass(), file.getName());
LOGGER.error(e);
}
break;
@ -152,8 +149,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
fileWriter.write(line);
fileWriter.write(System.getProperty("line.separator"));
} catch (IOException e) {
LOGGER.error("Unable to write to file with" +
" the name {}.", file.getName());
LOGGER.error("Unable to write to file with"
+ " the name {}.", file.getName());
LOGGER.error(e);
}
}
@ -161,8 +158,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
try {
fileWriter.close();
} catch (IOException e) {
LOGGER.error("Unable to close a fileWriter for the" +
" file with the name {}.", file.getName());
LOGGER.error("Unable to close a fileWriter for the"
+ " file with the name {}.", file.getName());
LOGGER.error(e);
}
}
@ -170,8 +167,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
/**
* Import routine for files containing objects of the same type {@code P}.
* Creates a new list of strings to read the file line by line. Each line
* of the list represents an object of the file. Then retrieves each object
* Creates a new list of strings to read the file line by line. Each line of
* the list represents an object of the file. Then retrieves each object
* from the corresponding string in the list.
*
* @return If error occurs true, otherwise false.
@ -184,8 +181,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
try {
lines = Files.readAllLines(file.toPath());
} catch (IOException e) {
LOGGER.error("Unable to read lines of the file with " +
"name {}.", file.getName());
LOGGER.error("Unable to read lines of the file with " + "name {}.",
file.getName());
LOGGER.error(e);
error = true;
}
@ -200,8 +197,8 @@ public abstract class AbstractMarshaller<P extends Portable> {
try {
object = xmlMapper.readValue(line, getObjectClass());
} catch (IOException e) {
LOGGER.error("Unable to read objects " +
"from XML line:\n \"{}\"", line);
LOGGER.error("Unable to read objects "
+ "from XML line:\n \"{}\"", line);
LOGGER.error(e);
error = true;
}
@ -215,7 +212,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
insertIntoDb(object);
objects.add(object);
} else {
emptyObjects+=1;
emptyObjects += 1;
LOGGER.info("Count of empty objects: {}", emptyObjects);
error = true;
}
@ -237,4 +234,5 @@ public abstract class AbstractMarshaller<P extends Portable> {
* @param portableObject An object of type {@code P}
*/
protected abstract void insertIntoDb(P portableObject);
}

View File

@ -18,7 +18,6 @@
*/
package org.libreccm.security;
import com.arsdigita.util.UncheckedWrapperException;
import java.util.List;
@ -29,6 +28,7 @@ import javax.persistence.TypedQuery;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CoreConstants;
import org.libreccm.core.UnexpectedErrorException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@ -241,7 +241,7 @@ public class PermissionManager {
try {
value = field.get(owner);
} catch (IllegalAccessException ex) {
throw new UncheckedWrapperException(ex);
throw new UnexpectedErrorException(ex);
}
if (value == null) {

View File

@ -45,10 +45,15 @@ public class RoleMembershipMarshaller extends AbstractMarshaller<RoleMembership>
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected void insertIntoDb(RoleMembership portableObject) {
// if (portableObject.getMembershipId() == 0) {
entityManager.persist(portableObject);
// portableObject.setMembershipId(0);
portableObject.setMembershipId(portableObject.getMembershipId() * -1);
// entityManager.persist(portableObject);
entityManager.merge(portableObject);
// } else {
// entityManager.merge(portableObject);
// }
}
}

View File

@ -119,7 +119,6 @@ public class CcmObjectRepositoryTest {
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addClass(com.arsdigita.util.UncheckedWrapperException.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")

View File

@ -108,8 +108,6 @@ public class CoreDataImportTest {
.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer
.class.getPackage())
.addClass(com.arsdigita.util.UncheckedWrapperException
.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")

View File

@ -55,7 +55,7 @@ import javax.inject.Inject;
*/
@RequestScoped
class ImportHelper {
private String repoPath = "/home/tosmers/Svn/libreccm/";
private String repoPath = "/home/jensp/pwi/libreccm/ccm/";
//private String repoPath = "";
private String projectPath = "ccm_ng/ccm-core/src/test/resources/" +
"portation/trunk-iaw-exports";

View File

@ -121,8 +121,6 @@ public class AuthorizationInterceptorTest {
.getPackage())
.addPackage(com.arsdigita.runtime.CCMResourceManager.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(com.arsdigita.web.CCMApplicationContextListener.class
.getPackage())
.addPackage(com.arsdigita.xml.XML.class.getPackage())
@ -130,6 +128,7 @@ public class AuthorizationInterceptorTest {
.getPackage())
.addClass(com.arsdigita.kernel.KernelConfig.class)
.addClass(org.libreccm.portation.Portable.class)
.addClass(com.arsdigita.util.UncheckedWrapperException.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")

View File

@ -118,8 +118,6 @@ public class GroupManagerTest {
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(com.arsdigita.kernel.KernelConfig.class)
.addClass(com.arsdigita.kernel.security.SecurityConfig.class)

View File

@ -122,7 +122,6 @@ public class GroupRepositoryTest {
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addClass(com.arsdigita.util.UncheckedWrapperException.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsResource("test-persistence.xml",

View File

@ -129,8 +129,6 @@ public class PermissionCheckerTest {
.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",

View File

@ -129,8 +129,6 @@ public class PermissionManagerTest {
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage()).
addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())

View File

@ -117,8 +117,6 @@ public class RoleManagerTest {
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())

View File

@ -128,7 +128,6 @@ public class RoleRepositoryTest {
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addClass(com.arsdigita.util.UncheckedWrapperException.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsResource("test-persistence.xml",

View File

@ -145,8 +145,6 @@ public class SecuredCollectionTest {
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",

View File

@ -147,8 +147,6 @@ public class SecuredIteratorTest {
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",

View File

@ -121,7 +121,6 @@ public class ShiroTest {
.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addClass(org.libreccm.security.authorization.LabBean.class)
.addClass(com.arsdigita.util.UncheckedWrapperException.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")

View File

@ -120,8 +120,6 @@ public class UserManagerTest {
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())