diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/AdminServlet.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/AdminServlet.java index 0e4f57478..b0ba2ce02 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/AdminServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/AdminServlet.java @@ -25,13 +25,11 @@ import com.arsdigita.dispatcher.AccessDeniedException; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.templating.Templating; import com.arsdigita.util.Assert; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.BaseApplicationServlet; import com.arsdigita.web.LoginSignal; import com.arsdigita.xml.Document; import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.PermissionChecker; import org.libreccm.web.CcmApplication; @@ -108,14 +106,8 @@ public class AdminServlet extends BaseApplicationServlet implements // /////// Some preparational steps /////////////// /* Determine access privilege: only logged in users may access */ final CdiUtil cdiUtil = new CdiUtil(); - final Subject subject; - final PermissionChecker permissionChecker; - try { - subject = cdiUtil.findBean(Subject.class); - permissionChecker = cdiUtil.findBean(PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final Subject subject = cdiUtil.findBean(Subject.class); + final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); if (!subject.isAuthenticated()) { throw new LoginSignal(sreq); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/ApplicationsAdministrationTab.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/ApplicationsAdministrationTab.java index 5ece31a0d..cdc41f052 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/ApplicationsAdministrationTab.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/ApplicationsAdministrationTab.java @@ -35,11 +35,11 @@ import com.arsdigita.ui.admin.applications.BaseApplicationPane; import com.arsdigita.ui.admin.applications.MultiInstanceApplicationPane; import com.arsdigita.ui.admin.applications.SingletonApplicationPane; import com.arsdigita.ui.admin.applications.tree.ApplicationTreeModelBuilder; -import com.arsdigita.util.UncheckedWrapperException; + import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.libreccm.cdi.utils.CdiLookupException; + import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.web.ApplicationRepository; import org.libreccm.web.ApplicationType; @@ -52,13 +52,13 @@ import org.libreccm.web.CcmApplication; * @author Jens Pelzetter */ public class ApplicationsAdministrationTab extends LayoutPanel implements - AdminConstants { + AdminConstants { private final Tree applicationTree; private final Map appPanes - = new HashMap<>(); - private final Map instancePanes = new HashMap<>(); + private final Map instancePanes + = new HashMap<>(); private final BoxPanel appPanel; /** @@ -79,21 +79,16 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements setLeft(applicationTree); final CdiUtil cdiUtil = new CdiUtil(); - final org.libreccm.web.ApplicationManager appManager; - try { - appManager = cdiUtil.findBean( - org.libreccm.web.ApplicationManager.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final org.libreccm.web.ApplicationManager appManager = cdiUtil.findBean( + org.libreccm.web.ApplicationManager.class); final Collection applicationTypes = appManager. - getApplicationTypes().values(); + getApplicationTypes().values(); final Map> appManagers - = ApplicationManagers. - getInstance(). - getApplicationManagers(); + = ApplicationManagers. + getInstance(). + getApplicationManagers(); for (ApplicationType appType : applicationTypes) { if (appType.singleton()) { @@ -110,7 +105,7 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements } for (Map.Entry entry : instancePanes. - entrySet()) { + entrySet()) { appPanel.add(entry.getValue()); } @@ -128,18 +123,18 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements pane = new SingletonApplicationPane(applicationType, null); } else { pane = new SingletonApplicationPane( - applicationType, appManagers.get(appObjectType). - getApplicationAdminForm()); + applicationType, appManagers.get(appObjectType). + getApplicationAdminForm()); } appPanes.put(appObjectType, pane); } @SuppressWarnings({"rawtypes", "unchecked"}) private void createAppPane( - final ApplicationType applicationType, - final Map> appManagers) { + final ApplicationType applicationType, + final Map> appManagers) { final ApplicationManager appManager = appManagers.get( - applicationType.name()); + applicationType.name()); final Form createForm; if (appManager == null) { createForm = null; @@ -147,24 +142,25 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements createForm = appManager.getApplicationCreateForm(); } - final MultiInstanceApplicationPane appPane = new MultiInstanceApplicationPane( + final MultiInstanceApplicationPane appPane + = new MultiInstanceApplicationPane( applicationType, createForm); appPanes.put(applicationType.name(), appPane); createInstancePane(applicationType, appManagers); } private void createInstancePane( - final ApplicationType applicationType, - final Map> managementForms) { + final ApplicationType applicationType, + final Map> managementForms) { final ApplicationManager manager = managementForms.get( - applicationType.name()); + applicationType.name()); final ApplicationInstancePane instPane; if (manager == null) { instPane = new ApplicationInstancePane(new Placeholder()); } else { instPane = new ApplicationInstancePane(managementForms.get( - applicationType.name()). - getApplicationAdminForm()); + applicationType.name()). + getApplicationAdminForm()); } instancePanes.put(applicationType.name(), instPane); @@ -178,7 +174,7 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements page.setVisibleDefault(entry.getValue(), false); } for (Map.Entry entry : instancePanes. - entrySet()) { + entrySet()) { page.setVisibleDefault(entry.getValue(), false); } } @@ -189,7 +185,7 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements entry.getValue().setVisible(state, false); } for (Map.Entry entry : instancePanes. - entrySet()) { + entrySet()) { entry.getValue().setVisible(state, false); } @@ -207,7 +203,7 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements final PageState state = event.getPageState(); final String selectedKey = (String) applicationTree.getSelectedKey( - state); + state); if (selectedKey != null) { if (selectedKey.contains(".")) { // Selected key is a classname and therefore the key of an ApplicationPane @@ -218,20 +214,16 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements } else { // Selected key is the name of a instance pane final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); + final CcmApplication application = appRepo - .retrieveApplicationForPath(selectedKey); - + .retrieveApplicationForPath(selectedKey); + final ApplicationInstancePane pane; if (application != null) { pane = instancePanes.get(application.getClass(). - getName()); + getName()); if (pane != null) { pane.setApplication(application); } @@ -253,9 +245,10 @@ public class ApplicationsAdministrationTab extends LayoutPanel implements public Placeholder() { super(); final Label label = new Label(GlobalizationUtil.globalize( - "ui.admin.applications.placeholder")); + "ui.admin.applications.placeholder")); add(label); } } + } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/EmailList.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/EmailList.java index e259e7ba5..3c0b04b41 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/EmailList.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/EmailList.java @@ -30,15 +30,11 @@ import com.arsdigita.bebop.list.ListCellRenderer; import com.arsdigita.bebop.list.ListModel; import com.arsdigita.bebop.list.ListModelBuilder; import com.arsdigita.util.LockableImpl; -import com.arsdigita.util.UncheckedWrapperException; -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.core.EmailAddress; import static com.arsdigita.ui.admin.AdminConstants.*; -import java.math.BigDecimal; import java.util.Iterator; /** @@ -105,11 +101,8 @@ class EmailList extends List if (userId != null) { // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // final User user = userRepository.findById(userId); // if (user == null) { @@ -198,11 +191,8 @@ class EmailListModelBuilder extends LockableImpl // } else { // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // final User user = userRepository.findById(userId); // // return new EmailListModel(user.getEmailAddresses().iterator()); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/ExistingGroupAddPane.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/ExistingGroupAddPane.java index 2823a381c..7b0c324c9 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/ExistingGroupAddPane.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/ExistingGroupAddPane.java @@ -1,6 +1,5 @@ package com.arsdigita.ui.admin; -import java.math.BigDecimal; import org.apache.log4j.Logger; @@ -14,10 +13,6 @@ import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.Tree; import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; //import org.libreccm.core.Group; //import org.libreccm.core.GroupRepository; @@ -60,12 +55,8 @@ public class ExistingGroupAddPane extends SimpleContainer implements // // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // // group = groupRepository.findById(id); // } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAddForm.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAddForm.java index acf5317ef..7bcab896a 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAddForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAddForm.java @@ -19,21 +19,13 @@ package com.arsdigita.ui.admin; import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.Tree; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; import static com.arsdigita.ui.admin.AdminConstants.*; -import java.math.BigDecimal; - -import javax.mail.internet.InternetAddress; /** * Add group form. @@ -96,12 +88,8 @@ class GroupAddForm extends GroupForm implements FormProcessListener { //// } // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // groupRepository.save(group); // //// if (parentGroup != null) { diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAdministrationTab.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAdministrationTab.java index 774b28002..7826bd4c0 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAdministrationTab.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupAdministrationTab.java @@ -22,7 +22,6 @@ import com.arsdigita.bebop.ActionLink; import com.arsdigita.bebop.BoxPanel; import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.List; import com.arsdigita.bebop.Page; @@ -45,14 +44,11 @@ import com.arsdigita.toolbox.ui.LayoutPanel; import static com.arsdigita.ui.admin.AdminConstants.*; import com.arsdigita.util.LockableImpl; -import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; import java.util.ArrayList; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; /** * Constructs the panel for administration of groups. @@ -147,13 +143,9 @@ class GroupAdministrationTab extends LayoutPanel implements AdminConstants, // // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil // .findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // // group = groupRepository.findById(id); // @@ -373,13 +365,9 @@ class GroupAdministrationTab extends LayoutPanel implements AdminConstants, // final Long groupId = Long.parseLong(key); // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil // .findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // // final Group group = groupRepository.findById(groupId); // final Group parent = getGroup(state); @@ -540,11 +528,8 @@ class GroupAdministrationTab extends LayoutPanel implements AdminConstants, // if (group != null) { // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // groupRepository.delete(group); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupEditForm.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupEditForm.java index 4b659fd71..e7154b243 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupEditForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupEditForm.java @@ -23,14 +23,9 @@ import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.PageState; -import java.math.BigDecimal; - -import javax.mail.internet.InternetAddress; import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.util.UncheckedWrapperException; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; //import org.libreccm.core.Group; //import org.libreccm.core.GroupRepository; @@ -72,13 +67,9 @@ class GroupEditForm extends GroupForm implements FormInitListener, // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; // -// try { + // groupRepository = cdiUtil.findBean( // GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // // final Group group = groupRepository.findById(id); // @@ -97,12 +88,7 @@ class GroupEditForm extends GroupForm implements FormInitListener, final Long id = (Long) state.getValue(GROUP_ID_PARAM); final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } if (id == null) { throw new FormProcessException(GlobalizationUtil.globalize( diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupSearchForm.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupSearchForm.java index feae2eb33..d0d116297 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupSearchForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupSearchForm.java @@ -18,7 +18,6 @@ */ package com.arsdigita.ui.admin; -import java.util.List; import org.apache.log4j.Logger; @@ -38,12 +37,6 @@ import com.arsdigita.bebop.parameters.StringParameter; import static com.arsdigita.ui.admin.AdminConstants.*; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; - -import java.util.Collections; /** * @author cgyg9330 @@ -94,12 +87,7 @@ public class GroupSearchForm extends Form implements FormProcessListener, // // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // results = groupRepository.searchGroupByName(search); // // diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupTreeModel.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupTreeModel.java index 0ede8822a..a3ae4eccf 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupTreeModel.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/GroupTreeModel.java @@ -22,16 +22,10 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.tree.TreeModel; import com.arsdigita.bebop.tree.TreeNode; -import com.arsdigita.util.UncheckedWrapperException; -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.Group; -import java.math.BigDecimal; - import java.util.Iterator; -import java.util.List; /** * @@ -110,12 +104,8 @@ public class GroupTreeModel implements TreeModel { // // final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup GroupRepository", ex); -// } // final List groups = groupRepository.findAll(); // // return groups.iterator(); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/SubMemberPanel.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/SubMemberPanel.java index 64ce8449e..6e174aad7 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/SubMemberPanel.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/SubMemberPanel.java @@ -26,13 +26,10 @@ import com.arsdigita.bebop.BoxPanel; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.list.ListCellRenderer; import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.Label; import com.arsdigita.bebop.ControlLink; import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.util.UncheckedWrapperException; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import static com.arsdigita.ui.admin.AdminConstants.*; @@ -88,13 +85,10 @@ class SubMemberPanel extends BoxPanel { // final UserRepository userRepository; // final GroupManager groupManager; // final GroupRepository groupRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); // groupManager = cdiUtil.findBean(GroupManager.class); // groupRepository = cdiUtil.findBean(GroupRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // final User user = userRepository.findById(userID); // final Group group = m_mainTab.getGroup(state); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserBrowsePane.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserBrowsePane.java index be8a5006e..60d1e600b 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserBrowsePane.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserBrowsePane.java @@ -56,13 +56,11 @@ import com.arsdigita.web.RedirectSignal; import static com.arsdigita.ui.admin.AdminConstants.*; import com.arsdigita.util.LockableImpl; -import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; import java.util.ArrayList; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.User; @@ -117,11 +115,8 @@ class UserBrowsePane extends SegmentedPanel // final PageState state = event.getPageState(); // final CdiUtil cdiUtil = new CdiUtil(); // final CcmSessionContext sessionContext; -// try { + // sessionContext = cdiUtil.findBean(CcmSessionContext.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // final Subject subject = sessionContext.getCurrentSubject(); // @@ -150,11 +145,8 @@ class UserBrowsePane extends SegmentedPanel // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // final User user = userRepository.findById(id); // if (user == null) { @@ -356,12 +348,9 @@ class UserBrowsePane extends SegmentedPanel // // final CdiUtil cdiUtil = new CdiUtil(); // final LoginManager loginManager; -// try { + // loginManager = cdiUtil.findBean( // LoginManager.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // loginManager.login(CLASS, CLASS); // @@ -434,11 +423,8 @@ class UserBrowsePane extends SegmentedPanel // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // userRepository.delete(user); @@ -477,11 +463,8 @@ class UserBrowsePane extends SegmentedPanel // // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // userRepository.save(user); } // End ActionPerformed method @@ -511,11 +494,8 @@ class UserBrowsePane extends SegmentedPanel // // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // userRepository.save(user); } // End ActionPerformed method @@ -694,12 +674,9 @@ class UserBrowsePane extends SegmentedPanel if (id != null) { final CdiUtil cdiUtil = new CdiUtil(); // final GroupRepository groupRepository; -// try { + // groupRepository = cdiUtil // .findBean(GroupRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // final Group group = groupRepository.findById(Long.parseLong( // id)); // m_groupAdministrationTab.setGroup(ps, group); @@ -731,11 +708,8 @@ class UserTableModel implements TableModel { public UserTableModel() { final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // users = userRepository.findAll(); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserForm.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserForm.java index 31d31f1f5..7eeb9fe43 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserForm.java @@ -33,7 +33,6 @@ import com.arsdigita.bebop.parameters.EmailParameter; import com.arsdigita.bebop.parameters.NotEmptyValidationListener; import com.arsdigita.bebop.parameters.StringLengthValidationListener; import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.parameters.URLParameter; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; @@ -41,15 +40,11 @@ import static com.arsdigita.ui.admin.AdminConstants.*; import com.arsdigita.ui.login.PasswordValidationListener; import com.arsdigita.util.StringUtils; -import com.arsdigita.util.UncheckedWrapperException; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; -import java.io.UncheckedIOException; import java.math.BigDecimal; -import javax.mail.internet.InternetAddress; import javax.servlet.http.HttpServletRequest; /** @@ -244,11 +239,8 @@ class UserForm extends Form implements FormValidationListener, AdminConstants { */ final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // // final String screenName = (String) m_screenName.getValue(ps); // final User userByScreenname = userRepository.findByScreenName( diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserPasswordForm.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserPasswordForm.java index ab817dd7a..338318510 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/UserPasswordForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/UserPasswordForm.java @@ -38,14 +38,12 @@ import com.arsdigita.mail.Mail; import static com.arsdigita.ui.admin.AdminConstants.*; import com.arsdigita.ui.login.PasswordValidationListener; -import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.User; @@ -137,11 +135,8 @@ class UserPasswordForm extends Form // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // final User user = userRepository.findById((Long) state.getValue( // USER_ID_PARAM)); // @@ -164,11 +159,8 @@ class UserPasswordForm extends Form // final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // final User user = userRepository.findById((Long) state.getValue( // USER_ID_PARAM)); // if (user == null) { @@ -217,12 +209,9 @@ class UserPasswordForm extends Form final CdiUtil cdiUtil = new CdiUtil(); // final UserRepository userRepository; // final UserManager userManager; -// try { + // userRepository = cdiUtil.findBean(UserRepository.class); // userManager = cdiUtil.findBean(UserManager.class); -// } catch(CdiLookupException ex) { -// throw new UncheckedWrapperException(ex); -// } // final User user = userRepository.findById((Long) state.getValue( // USER_ID_PARAM)); // if (user == null) { diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInfoPropertySheetModel.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInfoPropertySheetModel.java index edb7e983e..414873079 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInfoPropertySheetModel.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInfoPropertySheetModel.java @@ -18,12 +18,13 @@ */ package com.arsdigita.ui.admin.applications; +import com.arsdigita.bebop.PropertySheet; import com.arsdigita.bebop.PropertySheetModel; import com.arsdigita.ui.admin.GlobalizationUtil; import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.UncheckedWrapperException; + import java.util.List; -import org.libreccm.cdi.utils.CdiLookupException; + import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.web.ApplicationRepository; import org.libreccm.web.ApplicationType; @@ -48,7 +49,7 @@ public class ApplicationInfoPropertySheetModel implements PropertySheetModel { private int currentIndex = -1; public ApplicationInfoPropertySheetModel( - final ApplicationType applicationType) { + final ApplicationType applicationType) { this.applicationType = applicationType; } @@ -70,24 +71,24 @@ public class ApplicationInfoPropertySheetModel implements PropertySheetModel { switch (currentIndex) { case APP_TITLE: return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.title.label"). - localize(); + "ui.admin.applications.ApplicationInfoSection.title.label"). + localize(); case APP_CLASS: return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.app_class.label"). - localize(); + "ui.admin.applications.ApplicationInfoSection.app_class.label") + .localize(); case APP_SINGLETON: return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton.label"). - localize(); + "ui.admin.applications.ApplicationInfoSection.singleton.label") + .localize(); case APP_DESC: return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.desc.label"). - localize(); + "ui.admin.applications.ApplicationInfoSection.desc.label"). + localize(); case SINGLETON_PATH: return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label"). - localize(); + "ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label") + .localize(); default: return "unknown"; } @@ -97,19 +98,19 @@ public class ApplicationInfoPropertySheetModel implements PropertySheetModel { switch (currentIndex) { case APP_TITLE: return GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.title.label"); + "ui.admin.applications.ApplicationInfoSection.title.label"); case APP_CLASS: return GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.app_class.label"); + "ui.admin.applications.ApplicationInfoSection.app_class.label"); case APP_SINGLETON: return GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton.label"); + "ui.admin.applications.ApplicationInfoSection.singleton.label"); case APP_DESC: return GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.desc.label"); + "ui.admin.applications.ApplicationInfoSection.desc.label"); case SINGLETON_PATH: return GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label"); + "ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label"); default: return GlobalizationUtil.globalize("unknown"); } @@ -125,33 +126,29 @@ public class ApplicationInfoPropertySheetModel implements PropertySheetModel { case APP_SINGLETON: if (applicationType.singleton()) { return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton.yes"). - localize(); + "ui.admin.applications.ApplicationInfoSection.singleton.yes") + .localize(); } else { return (String) GlobalizationUtil.globalize( - "ui.admin.applications.ApplicationInfoSection.singleton.no"). - localize(); + "ui.admin.applications.ApplicationInfoSection.singleton.no") + .localize(); } case APP_DESC: return applicationType.description(); case SINGLETON_PATH: final String path; final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); final List instances - = appRepo.findByType( - applicationType.name()); + = appRepo.findByType( + applicationType.name()); if (instances.isEmpty()) { path = ""; } else { path = instances.get(0).getPrimaryUrl(); } - + return path; default: return ""; diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/MultiInstanceApplicationPane.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/MultiInstanceApplicationPane.java index d49962952..31436f4f3 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/MultiInstanceApplicationPane.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/MultiInstanceApplicationPane.java @@ -27,10 +27,10 @@ import com.arsdigita.bebop.table.TableModel; import com.arsdigita.bebop.table.TableModelBuilder; import com.arsdigita.ui.admin.GlobalizationUtil; import com.arsdigita.util.LockableImpl; -import com.arsdigita.util.UncheckedWrapperException; + import java.util.ArrayList; import java.util.List; -import org.libreccm.cdi.utils.CdiLookupException; + import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.web.ApplicationRepository; import org.libreccm.web.ApplicationType; @@ -137,12 +137,7 @@ public class MultiInstanceApplicationPane final String appType) { this.table = table; final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final ApplicationRepository appRepo = cdiUtil.findBean(ApplicationRepository.class); final List applications = appRepo. findByType(appType); for (CcmApplication application : applications) { diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/tree/ApplicationTreeModel.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/tree/ApplicationTreeModel.java index f3c064982..372a35b23 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/tree/ApplicationTreeModel.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/tree/ApplicationTreeModel.java @@ -22,11 +22,11 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.tree.TreeModel; import com.arsdigita.bebop.tree.TreeNode; import com.arsdigita.ui.admin.ApplicationsAdministrationTab; -import com.arsdigita.util.UncheckedWrapperException; + import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.libreccm.cdi.utils.CdiLookupException; + import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.web.ApplicationManager; import org.libreccm.web.ApplicationRepository; @@ -34,9 +34,11 @@ import org.libreccm.web.ApplicationType; import org.libreccm.web.CcmApplication; /** - * A {@link TreeModel} for the tree of applications in {@link ApplicationsAdministrationTab}. The tree consists of two - * different types of nodes: Nodes for {@link ApplicationTypes} and nodes for {@link Application} instances. - * + * A {@link TreeModel} for the tree of applications in + * {@link ApplicationsAdministrationTab}. The tree consists of two different + * types of nodes: Nodes for {@link ApplicationTypes} and nodes for + * {@link CCmApplication} instances. + * * @author Jens Pelzetter * @version $Id: ApplicationTreeModel.java 2406 2013-10-31 19:52:22Z jensp $ */ @@ -56,7 +58,8 @@ public class ApplicationTreeModel implements TreeModel { if (node instanceof RootTreeNode) { return true; } else if (node instanceof ApplicationTypeTreeNode) { - final ApplicationTypeTreeNode typeTreeNode = (ApplicationTypeTreeNode) node; + final ApplicationTypeTreeNode typeTreeNode + = (ApplicationTypeTreeNode) node; //if (typeTreeNode.getApplicationType().isSingleton()) { if (typeTreeNode.isSingleton()) { @@ -64,14 +67,15 @@ public class ApplicationTreeModel implements TreeModel { } else { //return !retrieveApplicationInstances(typeTreeNode.getApplicationType()).isEmpty(); //return !retrieveApplicationInstances(typeTreeNode.getApplicationType()).isEmpty(); - return !retrieveApplicationInstances(typeTreeNode.getObjecType()).isEmpty(); + return !retrieveApplicationInstances(typeTreeNode.getObjecType()) + .isEmpty(); } } else if (node instanceof ApplicationInstanceTreeNode) { return false; } else { throw new IllegalArgumentException( - "The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and" - + "ApplicationInstanceTreeNodes."); + "The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and" + + "ApplicationInstanceTreeNodes."); } } @@ -79,63 +83,49 @@ public class ApplicationTreeModel implements TreeModel { public Iterator getChildren(final TreeNode node, final PageState state) { if (node instanceof RootTreeNode) { final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationManager appManager; - try { - appManager = cdiUtil.findBean(ApplicationManager.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - - final Collection appTypes = appManager.getApplicationTypes().values(); - + final ApplicationManager appManager = cdiUtil.findBean( + ApplicationManager.class); + + final Collection appTypes = appManager + .getApplicationTypes().values(); + return new AppTypesIterator(appTypes); } else if (node instanceof ApplicationTypeTreeNode) { - final ApplicationTypeTreeNode typeTreeNode = (ApplicationTypeTreeNode) node; + final ApplicationTypeTreeNode typeTreeNode + = (ApplicationTypeTreeNode) node; final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); + final List applications = appRepo.findByType( - typeTreeNode.getObjecType()); + typeTreeNode.getObjecType()); return new AppIterator(applications); } else if (node instanceof ApplicationInstanceTreeNode) { return null; } else { throw new IllegalArgumentException( - "The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and" - + "ApplicationInstanceTreeNodes."); + "The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and" + + "ApplicationInstanceTreeNodes."); } } private List retrieveApplicationInstances( - final ApplicationType applicationType) { + final ApplicationType applicationType) { final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); + return appRepo.findByType(applicationType.name()); } private List retrieveApplicationInstances( - final String appObjectType) { + final String appObjectType) { final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean(ApplicationRepository.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); + return appRepo.findByType(appObjectType); } @@ -206,4 +196,5 @@ public class ApplicationTreeModel implements TreeModel { } } + } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/ChangePasswordForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/ChangePasswordForm.java index 14e369f52..0c948b2c9 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/ChangePasswordForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/ChangePasswordForm.java @@ -36,29 +36,21 @@ import com.arsdigita.bebop.form.Hidden; import com.arsdigita.bebop.form.Password; import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.URLParameter; import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.ui.UI; -import com.arsdigita.web.Web; import com.arsdigita.web.URL; import com.arsdigita.web.ReturnSignal; -import com.arsdigita.mail.Mail; -import com.arsdigita.util.UncheckedWrapperException; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.User; -import java.util.logging.Level; import org.apache.shiro.subject.Subject; import org.libreccm.security.Shiro; import org.libreccm.security.UserManager; -import org.libreccm.security.UserRepository; /** * A Form that allows a user to change their password by entering their old @@ -131,14 +123,8 @@ public class ChangePasswordForm extends Form add(m_returnURL); final CdiUtil cdiUtil = new CdiUtil(); - final Subject subject; - final Shiro shiro; - try { - subject = cdiUtil.findBean(Subject.class); - shiro = cdiUtil.findBean(Shiro.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final Subject subject = cdiUtil.findBean(Subject.class); + final Shiro shiro = cdiUtil.findBean(Shiro.class); final KernelConfig kernelConfig = KernelConfig.getConfig(); final User user = shiro.getUser(); @@ -207,15 +193,9 @@ public class ChangePasswordForm extends Form String confirmPassword = (String) m_confirmPassword.getValue(state); //check oldPassword - final Shiro shiro; - final UserManager userManager; - try { - final CdiUtil cdiUtil = new CdiUtil(); - shiro = cdiUtil.findBean(Shiro.class); - userManager = cdiUtil.findBean(UserManager.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final CdiUtil cdiUtil = new CdiUtil(); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + final UserManager userManager = cdiUtil.findBean(UserManager.class); final User user = shiro.getUser(); if (!userManager.verifyPassword(user, oldPassword)) { @@ -261,16 +241,9 @@ public class ChangePasswordForm extends Form return; } - final UserManager userManager; - final Shiro shiro; - try { - final CdiUtil cdiUtil = new CdiUtil(); - userManager = cdiUtil.findBean(UserManager.class); - shiro = cdiUtil.findBean(Shiro.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final UserManager userManager = cdiUtil.findBean(UserManager.class); + final Shiro shiro = cdiUtil.findBean(Shiro.class); final User user = shiro.getUser(); final String newPassword = (String) m_newPassword.getValue(state); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/EmailInitListener.java b/ccm-core/src/main/java/com/arsdigita/ui/login/EmailInitListener.java index fc5df69a2..c2b1d4de5 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/EmailInitListener.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/EmailInitListener.java @@ -18,19 +18,13 @@ */ package com.arsdigita.ui.login; -import com.arsdigita.web.Web; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.parameters.EmailParameter; -import com.arsdigita.util.UncheckedWrapperException; - -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; import org.apache.log4j.Logger; import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.Shiro; import org.libreccm.security.User; @@ -59,16 +53,10 @@ public class EmailInitListener implements FormInitListener { s_log.debug("START"); - final Subject subject; - final Shiro shiro; - try { - final CdiUtil cdiUtil = new CdiUtil(); - subject = cdiUtil.findBean(Subject.class); - shiro = cdiUtil.findBean(Shiro.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final Subject subject = cdiUtil.findBean(Subject.class); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + if (!subject.isAuthenticated()) { s_log.debug("FAILURE not logged in"); return; diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/ScreenNameInitListener.java b/ccm-core/src/main/java/com/arsdigita/ui/login/ScreenNameInitListener.java index 2d4f9604c..99e903d06 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/ScreenNameInitListener.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/ScreenNameInitListener.java @@ -23,60 +23,50 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.web.Web; import org.apache.log4j.Logger; import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.Shiro; import org.libreccm.security.User; - // Note: Previously used SiteNodeRequestContext, nows using KernelRequestContext // may be one cause that Login doesn't survive if the brwoser window is // closed. /** - * Initializes the value of the given parameter to the current user's - * screen name. Strangely similar to EmailInitListener. + * Initializes the value of the given parameter to the current user's screen + * name. Strangely similar to EmailInitListener. * * @author Crag Wolfe * @version $Id$ */ public class ScreenNameInitListener implements FormInitListener { - private static Logger s_log = - Logger.getLogger(ScreenNameInitListener.class.getName()); + private static Logger s_log = Logger.getLogger(ScreenNameInitListener.class + .getName()); private StringParameter m_param; /** - * - * @param param + * + * @param param */ public ScreenNameInitListener(StringParameter param) { m_param = param; } - + /** - * - * @param event + * + * @param event */ public void init(FormSectionEvent event) { PageState state = event.getPageState(); FormData data = event.getFormData(); s_log.debug("START"); - - final Subject subject; - final Shiro shiro; - try { - final CdiUtil cdiUtil = new CdiUtil(); - subject = cdiUtil.findBean(Subject.class); - shiro = cdiUtil.findBean(Shiro.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + + final CdiUtil cdiUtil = new CdiUtil(); + final Subject subject = cdiUtil.findBean(Subject.class); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + if (!subject.isAuthenticated()) { s_log.debug("FAILURE not logged in"); return; @@ -87,8 +77,9 @@ public class ScreenNameInitListener implements FormInitListener { s_log.debug("FAILURE null screen name"); return; } - + data.put(m_param.getName(), user.getName()); s_log.debug("SUCCESS"); } + } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserAuthenticationListener.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserAuthenticationListener.java index 4f8f2c0d8..bfe08c620 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserAuthenticationListener.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserAuthenticationListener.java @@ -25,14 +25,12 @@ import com.arsdigita.kernel.security.Util; import com.arsdigita.web.Web; import com.arsdigita.web.LoginSignal; -import com.arsdigita.util.UncheckedWrapperException; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.User; import javax.servlet.http.HttpServletRequest; + import org.apache.shiro.subject.Subject; /** @@ -52,7 +50,7 @@ import org.apache.shiro.subject.Subject; public class UserAuthenticationListener implements RequestListener { private static final Logger s_log = Logger.getLogger( - UserAuthenticationListener.class); + UserAuthenticationListener.class); /** * If the user is logged in, returns the User object. @@ -62,22 +60,15 @@ public class UserAuthenticationListener implements RequestListener { * @return the User object for the logged in user * * @throws IllegalStateException if user is not logged in. Call isLoggedIn() - * to check for this case. + * to check for this case. */ public Subject getUser(final PageState state) { if (!isLoggedIn(state)) { throw new IllegalStateException("User is not logged in"); } - // Note: aborts processing with an internal error if user not logged in! - // Not suiteable just to check log in status. - final Subject subject; - try { - final CdiUtil cdiUtil = new CdiUtil(); - subject = cdiUtil.findBean(Subject.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final CdiUtil cdiUtil = new CdiUtil(); + final Subject subject = cdiUtil.findBean(Subject.class); return subject; } @@ -102,11 +93,11 @@ public class UserAuthenticationListener implements RequestListener { @Override public void pageRequested(final RequestEvent event) { PageState state = event.getPageState(); - + if (!isLoggedIn(state)) { s_log.debug("User is not logged in"); redirectToLoginPage(state); - + } } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java index 653c9240e..d36e0ee42 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java @@ -36,7 +36,6 @@ import com.arsdigita.web.ReturnSignal; import javax.servlet.http.HttpServletRequest; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.core.EmailAddress; import org.libreccm.security.User; @@ -46,7 +45,7 @@ import org.libreccm.security.UserRepository; /** * Edits a user. If returnURL is passed in to the form, then redirects to that - URL_MSG; otherwise redirects to the user workspace. + * URL_MSG; otherwise redirects to the user workspace. * * * @author Sameer Ajmani @@ -66,15 +65,10 @@ public class UserEditForm extends UserForm @Override public Object initialValue(final PageState ps) { - final User result; - try { - final CdiUtil cdiUtil = new CdiUtil(); - final Shiro shiro = cdiUtil.findBean(Shiro.class); - result = shiro.getUser(); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + final User result = shiro.getUser(); + return result; } @@ -109,14 +103,10 @@ public class UserEditForm extends UserForm FormData data = event.getFormData(); PageState state = event.getPageState(); - final UserRepository userRepository; - try { - final CdiUtil cdiUtil = new CdiUtil(); - userRepository = cdiUtil.findBean(UserRepository.class); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final UserRepository userRepository = cdiUtil.findBean( + UserRepository.class); + User user = getUser(state); if (user == null) { throw new UncheckedWrapperException( @@ -130,7 +120,7 @@ public class UserEditForm extends UserForm newAddress.setAddress(data.get(FORM_EMAIL).toString()); user.setPrimaryEmailAddress(newAddress); userRepository.save(user); - + // redirect to workspace or return URL_MSG, if specified final HttpServletRequest req = state.getRequest(); final String path = UI.getWorkspaceURL(); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java index 900f5d39a..e6ca0e840 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java @@ -37,10 +37,8 @@ import com.arsdigita.bebop.parameters.NotEmptyValidationListener; import com.arsdigita.bebop.parameters.StringLengthValidationListener; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.util.UncheckedWrapperException; import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.User; import org.libreccm.security.UserRepository; @@ -257,14 +255,9 @@ public abstract class UserForm extends Form final PageState state = event.getPageState(); final FormData data = event.getFormData(); - final UserRepository userRepository; - try { - final CdiUtil cdiUtil = new CdiUtil(); - userRepository = cdiUtil.findBean(UserRepository.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final UserRepository userRepository = cdiUtil.findBean(UserRepository.class); + try { if (m_newUser) { // Verify that password and confirmation match diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserInfo.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserInfo.java index 980b6c816..583612086 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserInfo.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserInfo.java @@ -24,7 +24,6 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SimpleComponent; import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.dispatcher.DispatcherHelper; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.URL; import com.arsdigita.xml.Element; @@ -32,8 +31,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; -import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.Shiro; import org.libreccm.security.User; @@ -109,15 +106,9 @@ public class UserInfo extends SimpleContainer { m_contentCenters = new ArrayList<>(); final CdiUtil cdiUtil = new CdiUtil(); - final ApplicationRepository appRepo; - try { - appRepo = cdiUtil.findBean( + final ApplicationRepository appRepo = cdiUtil.findBean( ApplicationRepository.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException( - "Failed to lookup ApplicationRepository", ex); - } - + m_contentCenters = appRepo.findByType( "com.arsdigita.cms.ContentCenter"); } @@ -217,14 +208,9 @@ public class UserInfo extends SimpleContainer { throw new IllegalStateException("user is not logged in"); } - final User user; - try { - final CdiUtil cdiUtil = new CdiUtil(); - final Shiro shiro = cdiUtil.findBean(Shiro.class); - user = shiro.getUser(); - } catch(CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final CdiUtil cdiUtil = new CdiUtil(); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + final User user = shiro.getUser(); return user; } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java index 75b43f1aa..b9bed8131 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java @@ -45,7 +45,6 @@ import com.arsdigita.bebop.parameters.URLParameter; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.ui.UI; -import com.arsdigita.util.UncheckedWrapperException; import static com.arsdigita.ui.login.LoginConstants.*; @@ -53,14 +52,12 @@ import com.arsdigita.web.ParameterMap; import com.arsdigita.web.RedirectSignal; import com.arsdigita.web.ReturnSignal; import com.arsdigita.web.URL; -import javax.security.auth.login.FailedLoginException; -import javax.security.auth.login.LoginException; + import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.apache.shiro.subject.Subject; @@ -142,14 +139,14 @@ public class UserLoginForm extends Form implements LoginConstants, add(m_timestamp); m_returnURL = new Hidden(new URLParameter( - LoginHelper.RETURN_URL_PARAM_NAME)); + LoginHelper.RETURN_URL_PARAM_NAME)); m_returnURL.setPassIn(true); add(m_returnURL); setupLogin(); add(new Label(LoginHelper.getMessage( - "login.userRegistrationForm.password"))); + "login.userRegistrationForm.password"))); m_password = new Password(new StringParameter(FORM_PASSWORD)); // Since new users should not enter a password, allow null. //m_password.addValidationListener(new NotNullValidationListener()); @@ -158,7 +155,7 @@ public class UserLoginForm extends Form implements LoginConstants, SimpleContainer cookiePanel = new BoxPanel(BoxPanel.HORIZONTAL); m_isPersistent = new CheckboxGroup(FORM_PERSISTENT_LOGIN_P); Label optLabel = new Label(LoginHelper.getMessage( - "login.userRegistrationForm.cookieOption")); + "login.userRegistrationForm.cookieOption")); Option opt = new Option(FORM_PERSISTENT_LOGIN_P_DEFAULT, optLabel); m_isPersistent.addOption(opt); if (KernelConfig.getConfig().isLoginRemembered()) { @@ -167,8 +164,8 @@ public class UserLoginForm extends Form implements LoginConstants, cookiePanel.add(m_isPersistent); cookiePanel.add(new DynamicLink( - "login.userRegistrationForm.explainCookieLink", - LoginServlet.getCookiesExplainPageURL())); + "login.userRegistrationForm.explainCookieLink", + LoginServlet.getCookiesExplainPageURL())); add(cookiePanel); add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH); @@ -192,8 +189,8 @@ public class UserLoginForm extends Form implements LoginConstants, */ private void setupLogin() { SimpleContainer loginMessage = new SimpleContainer( - "subsite:loginPromptMsg", - LoginServlet.SUBSITE_NS_URI); + "subsite:loginPromptMsg", + LoginServlet.SUBSITE_NS_URI); if (KernelConfig.getConfig().emailIsPrimaryIdentifier()) { loginMessage.setClassAttr("email"); @@ -205,17 +202,17 @@ public class UserLoginForm extends Form implements LoginConstants, if (KernelConfig.getConfig().emailIsPrimaryIdentifier()) { add(new Label(LoginHelper.getMessage( - "login.userRegistrationForm.email"))); + "login.userRegistrationForm.email"))); m_loginName = new TextField(new EmailParameter(FORM_LOGIN)); addInitListener(new EmailInitListener((EmailParameter) m_loginName. - getParameterModel())); + getParameterModel())); } else { add(new Label(LoginHelper.getMessage( - "login.userRegistrationForm.screenName"))); + "login.userRegistrationForm.screenName"))); m_loginName = new TextField(new StringParameter(FORM_LOGIN)); addInitListener(new ScreenNameInitListener( - (StringParameter) m_loginName. - getParameterModel())); + (StringParameter) m_loginName. + getParameterModel())); } m_loginName.addValidationListener(new NotNullValidationListener()); add(m_loginName); @@ -229,14 +226,14 @@ public class UserLoginForm extends Form implements LoginConstants, */ @Override public void init(FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { s_log.info("In init"); if (KernelConfig.getConfig().isSSOenabled()) { // try SSO login s_log.info("trying SSO"); // try { throw new UnsupportedOperationException( - "SSO currently not supported"); + "SSO currently not supported"); // Web.getUserContext().loginSSO(); // s_log.info("loginSSO ok, now processing redirect_url"); // process(event); @@ -267,7 +264,7 @@ public class UserLoginForm extends Form implements LoginConstants, */ @Override public void validate(FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { s_log.debug("In validate"); @@ -306,7 +303,7 @@ public class UserLoginForm extends Form implements LoginConstants, */ @Override public void process(final FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { s_log.debug("In process"); final PageState state = event.getPageState(); @@ -332,26 +329,20 @@ public class UserLoginForm extends Form implements LoginConstants, * */ protected void loginUser(final FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { PageState state = event.getPageState(); final CdiUtil cdiUtil = new CdiUtil(); - final Subject subject; - try { - subject = cdiUtil.findBean(Subject.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final Subject subject = cdiUtil.findBean(Subject.class); final UsernamePasswordToken token = new UsernamePasswordToken( - (String) m_loginName.getValue(state), - (String) m_password.getValue(state) + (String) m_loginName.getValue(state), + (String) m_password.getValue(state) ); - token.setRememberMe(getPersistentLoginValue(state, - false)); + token.setRememberMe(getPersistentLoginValue(state, false)); try { subject.login(token); - } catch(AuthenticationException ex) { + } catch (AuthenticationException ex) { onLoginFail(event, ex); } @@ -371,12 +362,8 @@ public class UserLoginForm extends Form implements LoginConstants, // // attempt to log in user // final CdiUtil cdiUtil = new CdiUtil(); // final LoginManager loginManager; -// try { + // loginManager = cdiUtil.findBean(LoginManager.class); -// } catch (CdiLookupException ex) { -// throw new UncheckedWrapperException( -// "Failed to lookup LoginManager", ex); -// } // loginManager.login(username, password); // onLoginSuccess(event); // } catch (FailedLoginException e) { @@ -395,7 +382,7 @@ public class UserLoginForm extends Form implements LoginConstants, * */ protected void onLoginSuccess(final FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { // do nothing } @@ -411,7 +398,6 @@ public class UserLoginForm extends Form implements LoginConstants, // throws FormProcessException { // onLoginFail(event, ex); // } - /** * Executed when login fails with a bad password or when autoLoginOn is set * to false and the user doesn't exist. Default implementation marks @@ -425,7 +411,7 @@ public class UserLoginForm extends Form implements LoginConstants, */ protected void onLoginFail(final FormSectionEvent event, final AuthenticationException ex) - throws FormProcessException { + throws FormProcessException { s_log.debug("Login fail"); event.getFormData().addError(ERROR_LOGIN_FAIL); } @@ -436,6 +422,7 @@ public class UserLoginForm extends Form implements LoginConstants, * * @param event * @param ex + * * @throws com.arsdigita.bebop.FormProcessException */ // protected void onLoginException(final FormSectionEvent event, @@ -445,7 +432,6 @@ public class UserLoginForm extends Form implements LoginConstants, // s_log.error("Login failed", ex); // throw new FormProcessException(ex); // } - /** * Determines whether a persistent cookie is requested in the given form. * FORM_PERSISTENT_LOGIN_P whose value is equal to "1". If there is no such @@ -453,6 +439,7 @@ public class UserLoginForm extends Form implements LoginConstants, * * @param state * @param defaultValue + * * @return true if the specified formdata has a field named * * diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLogoutListener.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLogoutListener.java index a607ecf42..ee020463e 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLogoutListener.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLogoutListener.java @@ -20,11 +20,9 @@ package com.arsdigita.ui.login; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.util.UncheckedWrapperException; import org.apache.log4j.Logger; import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; /** @@ -47,14 +45,8 @@ public class UserLogoutListener implements ActionListener { @Override public void actionPerformed(final ActionEvent event) { - final Subject subject; - try { - final CdiUtil cdiUtil = new CdiUtil(); - subject = cdiUtil.findBean(Subject.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final Subject subject = cdiUtil.findBean(Subject.class); subject.logout(); } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java index b1ddfcf0d..41843ce69 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java @@ -32,9 +32,9 @@ import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.URLParameter; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.ui.UI; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.URL; import com.arsdigita.web.ReturnSignal; + import java.util.concurrent.Callable; import static com.arsdigita.ui.login.LoginConstants.*; @@ -46,18 +46,16 @@ import org.apache.log4j.Logger; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.Shiro; import org.libreccm.security.User; import org.libreccm.security.UserManager; -import org.libreccm.security.UserRepository; /** * Creates a new user. Collects user's basic info, such as email, password, - first name, last name, etc; then tries to create the user in the database. If - returnURL is passed in to the form, then redirects to that URL_MSG; otherwise - redirects to the user workspace. + * first name, last name, etc; then tries to create the user in the database. If + * returnURL is passed in to the form, then redirects to that URL_MSG; otherwise + * redirects to the user workspace. * * * @author Michael Bryzek @@ -98,7 +96,7 @@ public class UserNewForm extends UserForm implements FormInitListener, // save return URL_MSG m_returnURL = new Hidden(new URLParameter( - LoginHelper.RETURN_URL_PARAM_NAME)); + LoginHelper.RETURN_URL_PARAM_NAME)); m_returnURL.setPassIn(true); add(m_returnURL); @@ -116,7 +114,7 @@ public class UserNewForm extends UserForm implements FormInitListener, @Override public void init(final FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { PageState state = event.getPageState(); // clear passwords from form data m_password.setValue(state, ""); @@ -133,11 +131,11 @@ public class UserNewForm extends UserForm implements FormInitListener, @Override public void process(final FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { PageState state = event.getPageState(); final InternetAddress address = (InternetAddress) m_email - .getValue(state); + .getValue(state); final String email = address.getAddress(); // TODO: set additional emails @@ -153,26 +151,17 @@ public class UserNewForm extends UserForm implements FormInitListener, final Exception[] formExceptions = new Exception[]{null}; - final Shiro shiro; - try { - final CdiUtil cdiUtil = new CdiUtil(); - shiro = cdiUtil.findBean(Shiro.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final CdiUtil cdiUtil = new CdiUtil(); + final Shiro shiro = cdiUtil.findBean(Shiro.class); shiro.getSystemUser().execute(new Callable() { + @Override public Void call() throws Exception { - final UserManager userManager; - try { - final CdiUtil cdiUtil = new CdiUtil(); - userManager = cdiUtil.findBean(UserManager.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final CdiUtil cdiUtil = new CdiUtil(); + final UserManager userManager = cdiUtil.findBean( + UserManager.class); userManager.createUser(firstName, lastName, screenName, @@ -181,6 +170,7 @@ public class UserNewForm extends UserForm implements FormInitListener, return null; } + }); try { @@ -191,7 +181,6 @@ public class UserNewForm extends UserForm implements FormInitListener, loginName = screenName; } - final CdiUtil cdiUtil = new CdiUtil(); final Subject subject = cdiUtil.findBean(Subject.class); if (subject.isAuthenticated()) { @@ -199,9 +188,9 @@ public class UserNewForm extends UserForm implements FormInitListener, } final UsernamePasswordToken token = new UsernamePasswordToken( - loginName, password); + loginName, password); subject.login(token); - } catch (CdiLookupException | AuthenticationException ex) { + } catch (AuthenticationException ex) { s_log.error("login failed for new user", ex); throw new FormProcessException(ex); } diff --git a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java index 67ce095be..8597c3a5e 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java @@ -18,9 +18,7 @@ */ package com.arsdigita.web; - import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.web.CcmApplication; import org.libreccm.web.ApplicationRepository; @@ -39,7 +37,7 @@ import javax.servlet.http.HttpServletResponse; * *

* Most CCM applications will extend this class by implementing - * {@link #doService(HttpServletRequest,HttpServletResponse,Application)} to + * {@link #doService(HttpServletRequest,HttpServletResponse,CcmApplication)} to * perform application-private dispatch to UI code.

* *

@@ -91,7 +89,7 @@ public abstract class BaseApplicationServlet extends BaseServlet { /** *

* Augments the context of the request and delegates to {@link - * #doService(HttpServletRequest,HttpServletResponse,Application)}.

+ * #doService(HttpServletRequest,HttpServletResponse,CcmApplication)}.

* * @throws javax.servlet.ServletException * @throws java.io.IOException @@ -119,7 +117,6 @@ public abstract class BaseApplicationServlet extends BaseServlet { // // final ServletException[] servletException = {null}; // final IOException[] ioException = {null}; - doService(request, response, app); } @@ -178,22 +175,17 @@ public abstract class BaseApplicationServlet extends BaseServlet { } final CdiUtil cdiUtil = new CdiUtil(); - try { - final ApplicationRepository appRepo = cdiUtil.findBean( - ApplicationRepository.class); - - return appRepo.findById(appId); - } catch (CdiLookupException ex) { - throw new IllegalStateException(String.format( - "Failed to retrieve application %d from the database.", appId)); - } + final ApplicationRepository appRepo = cdiUtil.findBean( + ApplicationRepository.class); + return appRepo.findById(appId); } - - /** - * + + /** + * * @param sreq * @param app * @param uc + * * @return */ // private RequestContext makeLegacyContext(HttpServletRequest sreq, @@ -212,6 +204,4 @@ public abstract class BaseApplicationServlet extends BaseServlet { // // return krc; // } - - } diff --git a/ccm-core/src/main/java/com/arsdigita/web/CCMDispatcherServlet.java b/ccm-core/src/main/java/com/arsdigita/web/CCMDispatcherServlet.java index b1885654b..e73a9df40 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/CCMDispatcherServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/web/CCMDispatcherServlet.java @@ -21,7 +21,6 @@ package com.arsdigita.web; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.ui.UI; import com.arsdigita.util.Assert; -import com.arsdigita.util.UncheckedWrapperException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -39,9 +38,8 @@ import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.apache.shiro.subject.Subject; -import org.libreccm.cdi.utils.CdiLookupException; -import org.libreccm.cdi.utils.CdiUtil; /** *

The CCM main dispatcher. This servlet serves as the main servlet / main diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java index 2ae21c258..3f3cfb1da 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java @@ -35,18 +35,26 @@ import static org.libreccm.core.CoreConstants.*; import java.util.Objects; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; /** - * Association class describing the association between a category and an - * object. Instances of these class should not created manually. - * The methods provided by the {@link CategoryManager} take care of that. - * + * Association class describing the association between a category and an + * object. Instances of these class should not created manually. The methods + * provided by the {@link CategoryManager} take care of that. + * * @author Jens Pelzetter - * + * * @apiviz.has org.libreccm.core.CcmObject */ @Entity @Table(name = "CATEGORIZATIONS", schema = DB_SCHEMA) +@NamedQueries({ + @NamedQuery(name = "Categorization.find", + query = "SELECT c FROM Categorization c " + + "WHERE c.category = :category " + + "AND c.categorizedObject = :object") +}) public class Categorization implements Serializable { private static final long serialVersionUID = 201504301320L; @@ -81,19 +89,25 @@ public class Categorization implements Serializable { private boolean index; /** - * Defines the order in which the categories assigned the the categorised + * Defines the order in which the categories assigned the the categorised * object are shown. */ @Column(name = "CATEGORY_ORDER") private long categoryOrder; /** - * Defines the order in which the objects assigned to the category are + * Defines the order in which the objects assigned to the category are * shown. */ @Column(name = "OBJECT_ORDER") private long objectOrder; + public Categorization() { + index = false; + categoryOrder = 0; + objectOrder = 0; + } + public long getCategorizationId() { return categorizationId; } @@ -146,7 +160,7 @@ public class Categorization implements Serializable { public int hashCode() { int hash = 7; hash - = 89 * hash + (int) (categorizationId ^ (categorizationId >>> 32)); + = 89 * hash + (int) (categorizationId ^ (categorizationId >>> 32)); hash = 89 * hash + Objects.hashCode(category); hash = 89 * hash + Objects.hashCode(categorizedObject); hash = 89 * hash + (index ? 1 : 0); @@ -156,7 +170,7 @@ public class Categorization implements Serializable { } @Override - //No chance to make this method less complex, therefore suppress warning + //No chance to make this method less complex, therefore suppress warning @SuppressWarnings("PMD.NPathComplexity") public boolean equals(final Object obj) { if (obj == null) { @@ -201,13 +215,13 @@ public class Categorization implements Serializable { public String toString(final String data) { return String.format("%s{ " - + "categorizationId = %d, " - + "category = %s, " - + "categorizedObject = %s, " - + "index = %b," - + "categoryOrder = %d, " - + "objectOrder = %d" - + "%s }", + + "categorizationId = %d, " + + "category = %s, " + + "categorizedObject = %s, " + + "index = %b," + + "categoryOrder = %d, " + + "objectOrder = %d" + + "%s }", super.toString(), categorizationId, Objects.toString(category), diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Category.java b/ccm-core/src/main/java/org/libreccm/categorization/Category.java index 2fb315d32..f7f394327 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Category.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Category.java @@ -64,7 +64,9 @@ import javax.validation.constraints.Pattern; @Table(name = "CATEGORIES", schema = DB_SCHEMA) @NamedQueries({ @NamedQuery(name = "Category.topLevelCategories", - query = "SELECT c FROM Category c WHERE c.parentCategory IS NULL") + query = "SELECT c FROM Category c WHERE c.parentCategory IS NULL"), + @NamedQuery(name = "Category.findByName", + query = "SELECT c FROM Category c WHERE c.name = :name") }) public class Category extends CcmObject implements Serializable { @@ -165,6 +167,10 @@ public class Category extends CcmObject implements Serializable { description = new LocalizedString(); objects = new ArrayList<>(); subCategories = new ArrayList<>(); + enabled = true; + visible= true; + abstractCategory = false; + categoryOrder = 0; } public String getUniqueId() { diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java b/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java index aa7fd91e7..c423fc3d4 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategoryManager.java @@ -18,10 +18,19 @@ */ package org.libreccm.categorization; +import java.util.List; + import org.libreccm.core.CcmObject; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.NoResultException; +import javax.persistence.TypedQuery; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.libreccm.core.CcmObjectRepository; /** * The {@code CategoryManager} provides several helper methods for managing @@ -32,33 +41,23 @@ import javax.inject.Inject; @RequestScoped public class CategoryManager { + private static final Logger LOGGER = LogManager.getLogger( + CategoryManager.class); + /** * A {@link CategoryRepository} instance used to interact with the database. */ @Inject private CategoryRepository categoryRepo; + @Inject + private CcmObjectRepository ccmObjectRepo; + + @Inject + private EntityManager entityManager; + /** - * Assigns an category to an object. The object is added at the position - * specified by the {@code order} parameter. If that position is already - * occupied the object currently assigned to that position and the objects - * after that object are moved one position down (the value of their - * {@code order} property is increased by one). - * - * If the position provided by the {@code order} parameter is larger than - * the value of the {@code order} property of the last object plus 1 the - * order property is set the the value of the {@code order} property of the - * last object plus one. - * - * If the order property is less than 0, the object is inserted at first - * position and the value of the {@code order} property is set to {@code 0}. - * The value of the {@code order} property of all other objects is increased - * by one. - * - * If the object is already assigned to the category and the value of the - * {@code order} property is different than the provided value the - * {@code order} property is set the provided value. No further action will - * executed. + * Assigns an category to an object. * * Please note: Because the association between {@link Category} and {@code * CcmObject} is a many-to-many association we use an association object to @@ -73,21 +72,38 @@ public class CategoryManager { * {@code null}. * @param category The category to which the object should be assigned. Can * never be {@code null}. - * @param order Order value specifying the sort order of the objects - * assigned to category. */ public void addObjectToCategory(final CcmObject object, - final Category category, - final long order) { - // TODO implement method - throw new UnsupportedOperationException(); + final Category category) { + if (object == null) { + throw new IllegalArgumentException( + "Null can't be added to a category."); + } + + if (category == null) { + throw new IllegalArgumentException( + "Can't add an object to category 'null'."); + } + + final Categorization categorization = new Categorization(); + categorization.setCategorizedObject(object); + categorization.setCategory(category); + categorization.setCategoryOrder(object.getCategories().size() + 1); + categorization.setObjectOrder(category.getObjects().size() + 1); + + object.addCategory(categorization); + category.addObject(categorization); + + entityManager.persist(categorization); + categoryRepo.save(category); + ccmObjectRepo.save(object); } /** * Removes a object from a category. Additionally to removing the object * from the category this method also upgrades the order of all objects * sorted in after the removed object so that the values are consistent - * without gaps (which may cause trouble). + * without gaps (which may cause trouble otherwise). * * If either the {@code object} or the {@code category} parameter are * {@code null} an {@link IllegalArgumentException} exception is thrown @@ -106,8 +122,52 @@ public class CategoryManager { public void removeObjectFromCategory(final CcmObject object, final Category category) throws ObjectNotAssignedToCategoryException { - // TODO implement method - throw new UnsupportedOperationException(); + + if (object == null) { + throw new IllegalArgumentException( + "Can't remove object 'null' from a category"); + } + + if (category == null) { + throw new IllegalArgumentException( + "Can't remove an object from category 'null'"); + } + + final TypedQuery query = entityManager.createNamedQuery( + "Categorization.find", Categorization.class); + query.setParameter("category", category); + query.setParameter("object", object); + + final Categorization categorization; + try { + categorization = query.getSingleResult(); + } catch (NoResultException ex) { + LOGGER.warn(String.format( + "No categorization for category %s and object %s found." + + "Ignoring. Orginal exception: ", + category.toString(), + object.toString()), + ex); + return; + } + + object.removeCategory(categorization); + category.removeObject(categorization); + entityManager.remove(categorization); + categoryRepo.save(category); + ccmObjectRepo.save(object); + + final List categories = object.getCategories(); + for (int i = 0; i < categories.size(); i++) { + categories.get(i).setCategoryOrder(i); + entityManager.merge(categories.get(i)); + } + + final List objects = category.getObjects(); + for (int i = 0; i < objects.size(); i++) { + objects.get(i).setObjectOrder(i); + entityManager.merge(objects.get(i)); + } } /** @@ -179,34 +239,25 @@ public class CategoryManager { * Adds a category as an subcategory to another category. If the category is * assigned to another category that association is removed. * - * The method will ensure that values of the {@code order} properties of all - * subcategories will remain consistent. If the provided position is already - * occupied a the values of the {@code order} properties of the object - * occupying the provided positions and of all following objects are - * increased by one. - * - * If the provided value is larger than the value of the {@code order} - * property of the last object the value of the {@code property} is set the - * value of the of the {@code order} property of the last object plus one. - * - * The provided value is less than {@code 0} the object will be the first - * one and the value of the {@code order} property will be set to {@code 0}. - * - * If the provided category is already assigned to the provided parent - * category only the value of the {@code order} property is updated. - * * @param subCategory The category to add as subcategory. Can't be * {@code null}. * @param parentCategory The category to which the category is added as * subcategory. Can't be {@code null}. - * @param order The value for the {@code order} property of the - * association. */ public void addSubCategoryToCategory(final Category subCategory, - final Category parentCategory, - final long order) { - // TODO implement method - throw new UnsupportedOperationException(); + final Category parentCategory) { + if (subCategory.getParentCategory() != null) { + final Category oldParent = subCategory.getParentCategory(); + removeSubCategoryFromCategory(subCategory, oldParent); + } + + final int order = parentCategory.getCategories().size() + 1; + parentCategory.addSubCategory(subCategory); + subCategory.setParentCategory(parentCategory); + subCategory.setCategoryOrder(order); + + categoryRepo.save(parentCategory); + categoryRepo.save(subCategory); } /** @@ -218,15 +269,32 @@ public class CategoryManager { * Can't be {@code null}. * @param parentCategory The parent category. Can't be {@code null}. * - * @throws NotASubCategoryException If the provided subcategory is not + * @throws IllegalArgumentException If the provided subcategory is not * assigned to the provided parent * category. */ public void removeSubCategoryFromCategory(final Category subCategory, - final Category parentCategory) - throws NotASubCategoryException { - // TODO implement method - throw new UnsupportedOperationException(); + final Category parentCategory) { + + if (subCategory.getParentCategory() == null + || !subCategory.getParentCategory().equals(parentCategory)) { + throw new IllegalArgumentException(String.format( + "Category %s is not a subcategory of category %s.", + subCategory.toString(), + parentCategory.toString())); + } + + parentCategory.removeSubCategory(subCategory); + subCategory.setParentCategory(null); + + final List subCategories = parentCategory.getSubCategories(); + for (int i = 0; i < subCategories.size(); i++) { + subCategories.get(i).setCategoryOrder(i); + categoryRepo.save(subCategories.get(i)); + } + + categoryRepo.save(parentCategory); + categoryRepo.save(subCategory); } /** @@ -240,13 +308,12 @@ public class CategoryManager { * @param parentCategory The parent category of the category. Can't be * {@code null}. * - * @throws NotASubCategoryException If the provided subcategory is not a + * @throws IllegalArgumentException If the provided subcategory is not a * subcategory of the provided parent * category. */ public void increaseCategoryOrder(final Category subCategory, - final Category parentCategory) - throws NotASubCategoryException { + final Category parentCategory) { // TODO implement method throw new UnsupportedOperationException(); } @@ -262,13 +329,12 @@ public class CategoryManager { * @param parentCategory The parent category of the category. Can't be * {@code null}. * - * @throws NotASubCategoryException If the provided subcategory is not a + * @throws IllegalArgumentException If the provided subcategory is not a * subcategory of the provided parent * category. */ public void decreaseCategoryOrder(final Category subCategory, - final Category parentCategory) - throws NotASubCategoryException { + final Category parentCategory) { // TODO implement method throw new UnsupportedOperationException(); } @@ -281,13 +347,13 @@ public class CategoryManager { * @param parentCategory The parent category of both subcategories. Can't be * {@code null}. * - * @throws NotASubCategoryException If one or both categories are not - * subcategories of the provided parent category.qq + * @throws IllegalArgumentException If one or both categories are not + * subcategories of the provided parent + * category.qq */ public void swapCategories(final Category subCategoryA, final Category subCategoryB, - final Category parentCategory) - throws NotASubCategoryException { + final Category parentCategory) { // TODO implement method throw new UnsupportedOperationException(); } diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java b/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java index 9534e6b06..ee0d790a2 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategoryRepository.java @@ -21,8 +21,11 @@ package org.libreccm.categorization; import org.libreccm.core.AbstractEntityRepository; import java.util.List; +import java.util.Optional; import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.NoResultException; import javax.persistence.TypedQuery; /** @@ -32,6 +35,9 @@ import javax.persistence.TypedQuery; @RequestScoped public class CategoryRepository extends AbstractEntityRepository { + @Inject + private DomainRepository domainRepo; + @Override public Class getEntityClass() { return Category.class; @@ -43,24 +49,93 @@ public class CategoryRepository extends AbstractEntityRepository } /** - * Retrieves a list of all top level categories (Categories without a - * parent category). - * + * Retrieves a list of all top level categories (Categories without a parent + * category). + * * @return A list of all top level categories. */ public List getTopLevelCategories() { final TypedQuery query = getEntityManager().createNamedQuery( "Category.topLevelCategories", Category.class); - + return query.getResultList(); } - + + public Category findByPath(final String path) { + if (path == null || path.isEmpty()) { + throw new IllegalArgumentException("Path can't be null or empty."); + } + + final String[] tokens = path.split(":"); + if (tokens.length > 2) { + throw new InvalidCategoryPathException( + "The provided path is invalid: More than one colon found. " + + "Valid path format: domainKey:path"); + } + + if (tokens.length < 2) { + throw new InvalidCategoryPathException( + "The provided path is invalid: No domain found in path. " + + "Valid path format: domainKey:path"); + } + + final Domain domain; + try { + domain = domainRepo.findByDomainKey(tokens[0]); + } catch (NoResultException ex) { + throw new InvalidCategoryPathException(String.format( + "No domain identified by the key '%s' found.", + tokens[0]), + ex); + } + + return findByPath(domain, tokens[1]); + } + + public Category findByPath(final Domain domain, final String path) { + if (domain == null) { + throw new IllegalArgumentException("Domain can't be null."); + } + + if (path == null || path.isEmpty()) { + throw new IllegalArgumentException("Path can't be null or empty."); + } + + String normalizedPath = path.replace('.', '/'); + if (normalizedPath.startsWith("/")) { + normalizedPath = normalizedPath.substring(1); + } + + if (normalizedPath.endsWith("/")) { + normalizedPath = normalizedPath.substring(0, + normalizedPath.length()); + } + + final String[] tokens = normalizedPath.split("/"); + Category current = domain.getRoot(); + for (String token : tokens) { + final Optional result = current.getSubCategories() + .stream() + .filter((c) -> { + return c.getName().equals(token); + }) + .findFirst(); + if (result.isPresent()) { + current = result.get(); + } else { + return null; + } + } + + return current; + } + /** * Retrieves all categories which are not assigned to another category as - * subcategory or the an {@link Domain} as root category. - * - * @return A list of all orphaned categories. Normally this list should be - * empty. + * subcategory or the an {@link Domain} as root category. + * + * @return A list of all orphaned categories. Normally this list should be + * empty. */ public List getOrphanedCategories() { // TODO implement method diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java index a16187794..c06ecb680 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Domain.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Domain.java @@ -47,6 +47,8 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; @@ -74,6 +76,12 @@ import javax.xml.bind.annotation.XmlRootElement; */ @Entity @Table(name = "CATEGORY_DOMAINS", schema = DB_SCHEMA) +@NamedQueries({ + @NamedQuery(name="Domain.findByKey", + query = "SELECT d FROM Domain d WHERE d.domainKey = :key"), + @NamedQuery(name="Domain.findByUri", + query = "SELECT d FROM Domain d WHERE d.uri = :uri") +}) @XmlRootElement(name = "domain", namespace = CAT_XML_NS) public class Domain extends CcmObject implements Serializable { @@ -102,9 +110,8 @@ public class Domain extends CcmObject implements Serializable { * http://example.org/domains/example-nav * */ - @Column(name = "URI", nullable = false, unique = true, length = 1024) + @Column(name = "URI", nullable = true, unique = true, length = 1024) @Convert(converter = UriConverter.class) - @NotBlank @URL @XmlElement(name = "uri", namespace = CAT_XML_NS) private URI uri; diff --git a/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java b/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java index 308566f46..619cdcc1b 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/DomainManager.java @@ -22,6 +22,8 @@ import org.libreccm.web.CcmApplication; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.persistence.EntityManager; +import org.libreccm.web.ApplicationRepository; /** * Provides several methods when managing the relations between {@link Domain}s @@ -32,8 +34,14 @@ import javax.inject.Inject; @RequestScoped public class DomainManager { + @Inject + private ApplicationRepository applicationRepo; + @Inject private DomainRepository domainRepo; + + @Inject + private EntityManager entityManager; /** * Adds a {@code CcmApplication} to the owners of a {@link Domain}. If the @@ -47,8 +55,18 @@ public class DomainManager { */ public void addDomainOwner(final CcmApplication application, final Domain domain) { - // TODO implement method - throw new UnsupportedOperationException(); + final DomainOwnership ownership = new DomainOwnership(); + ownership.setDomain(domain); + ownership.setOwner(application); + ownership.setOwnerOrder(domain.getOwners().size() + 1); + ownership.setDomainOrder(application.getDomains().size() + 1); + + application.addDomain(ownership); + domain.addOwner(ownership); + + entityManager.persist(ownership); + applicationRepo.save(application); + domainRepo.save(domain); } /** diff --git a/ccm-core/src/main/java/org/libreccm/categorization/DomainRepository.java b/ccm-core/src/main/java/org/libreccm/categorization/DomainRepository.java index b805dfbcd..e422cdca8 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/DomainRepository.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/DomainRepository.java @@ -25,6 +25,7 @@ import java.net.URI; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; /** * A repository for executing CRUD operations on {@link Domain} objects. @@ -36,7 +37,7 @@ public class DomainRepository extends AbstractEntityRepository { @Inject private EntityManager entityManager; - + @Override public Class getEntityClass() { return Domain.class; @@ -53,11 +54,14 @@ public class DomainRepository extends AbstractEntityRepository { * @param domainKey The domain key of the {@code Domain} to find. * * @return The {@code Domain} identified by {@code domainKey} or - * {@code null} if there is no such {@code Domain}. + * {@code null} if there is no such {@code Domain}. */ public Domain findByDomainKey(final String domainKey) { - // TODO implement method - throw new UnsupportedOperationException(); + final TypedQuery query = entityManager.createNamedQuery( + "Domain.findByKey", Domain.class); + query.setParameter("key", domainKey); + + return query.getSingleResult(); } /** @@ -66,11 +70,14 @@ public class DomainRepository extends AbstractEntityRepository { * @param uri The URI of the domain to find. * * @return The {@code Domain} identified by the provided URI or {@code null} - * if there is so such {@code Domain}. + * if there is so such {@code Domain}. */ public Domain findByUri(final URI uri) { - // TODO implement method - throw new UnsupportedOperationException(); + final TypedQuery query = entityManager.createNamedQuery( + "Domain.findByUri", Domain.class); + query.setParameter("uri", uri); + + return query.getSingleResult(); } } diff --git a/ccm-core/src/main/java/org/libreccm/categorization/InvalidCategoryPathException.java b/ccm-core/src/main/java/org/libreccm/categorization/InvalidCategoryPathException.java new file mode 100644 index 000000000..2eef30b0c --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/categorization/InvalidCategoryPathException.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 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.libreccm.categorization; + +/** + * + * @author Jens Pelzetter + */ +public class InvalidCategoryPathException extends RuntimeException { + + private static final long serialVersionUID = -428910047165112592L; + + /** + * Creates a new instance of InvalidCategoryPathException + * without detail message. + */ + public InvalidCategoryPathException() { + } + + /** + * Constructs an instance of InvalidCategoryPathException with + * the specified detail message. + * + * @param msg the detail message. + */ + public InvalidCategoryPathException(final String msg) { + super(msg); + } + + public InvalidCategoryPathException(final Throwable cause) { + super(cause); + } + + public InvalidCategoryPathException(final String msg, + final Throwable cause) { + super(msg, cause); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/categorization/NotASubCategoryException.java b/ccm-core/src/main/java/org/libreccm/categorization/NotASubCategoryException.java deleted file mode 100644 index 3e24b1f35..000000000 --- a/ccm-core/src/main/java/org/libreccm/categorization/NotASubCategoryException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2015 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.libreccm.categorization; - -/** - * Indicates that a category passed to a method is not a sub category of another - * category also passed to the method. - * - * @author Jens Pelzetter - */ -public class NotASubCategoryException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Creates a new instance of NotASubCategoryException without detail message. - */ - public NotASubCategoryException() { - super(); - } - - - /** - * Constructs an instance of NotASubCategoryException with the specified detail message. - * - * @param msg The detail message. - */ - public NotASubCategoryException(final String msg) { - super(msg); - } - - /** - * Constructs an instance of NotASubCategoryException which wraps the - * specified exception. - * - * @param exception The exception to wrap. - */ - public NotASubCategoryException(final Exception exception) { - super(exception); - } - - /** - * Constructs an instance of NotASubCategoryException with the specified message which also wraps the - * specified exception. - * - * @param msg The detail message. - * @param exception The exception to wrap. - */ - public NotASubCategoryException(final String msg, final Exception exception) { - super(msg, exception); - } -} diff --git a/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiLookupException.java b/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiLookupException.java deleted file mode 100644 index 6133d5844..000000000 --- a/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiLookupException.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2015 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.libreccm.cdi.utils; - -/** - * - * @author Jens Pelzetter - */ -public class CdiLookupException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Creates a new instance of CdiLookupException without detail message. - */ - public CdiLookupException() { - super(); - } - - - /** - * Constructs an instance of CdiLookupException with the specified detail message. - * - * @param msg The detail message. - */ - public CdiLookupException(final String msg) { - super(msg); - } - - /** - * Constructs an instance of CdiLookupException which wraps the - * specified exception. - * - * @param exception The exception to wrap. - */ - public CdiLookupException(final Exception exception) { - super(exception); - } - - /** - * Constructs an instance of CdiLookupException with the specified message which also wraps the - * specified exception. - * - * @param msg The detail message. - * @param exception The exception to wrap. - */ - public CdiLookupException(final String msg, final Exception exception) { - super(msg, exception); - } -} diff --git a/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiUtil.java b/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiUtil.java index 957a2cc1c..b8cc28630 100644 --- a/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiUtil.java +++ b/ccm-core/src/main/java/org/libreccm/cdi/utils/CdiUtil.java @@ -45,7 +45,7 @@ public class CdiUtil { } @SuppressWarnings("unchecked") - public T findBean(final Class beanType) throws CdiLookupException { + public T findBean(final Class beanType) { final Set> beans = beanManager.getBeans(beanType); final Iterator> iterator = beans.iterator(); if (iterator.hasNext()) { @@ -58,7 +58,7 @@ public class CdiUtil { } else { LOGGER.error(new ParameterizedMessage( "No CDI Bean for type {0} found.", beanType.getName())); - throw new CdiLookupException(String.format( + throw new IllegalStateException(String.format( "No CDI Bean for type \"%s\" found", beanType.getName())); } } diff --git a/ccm-core/src/main/java/org/libreccm/configuration/BigDecimalConfigurationEntry.java b/ccm-core/src/main/java/org/libreccm/configuration/BigDecimalConfigurationEntry.java index fb395730b..ae5bef427 100644 --- a/ccm-core/src/main/java/org/libreccm/configuration/BigDecimalConfigurationEntry.java +++ b/ccm-core/src/main/java/org/libreccm/configuration/BigDecimalConfigurationEntry.java @@ -18,6 +18,8 @@ */ package org.libreccm.configuration; +import static org.libreccm.core.CoreConstants.*; + import java.io.Serializable; import java.math.BigDecimal; import java.util.Objects; @@ -31,7 +33,7 @@ import javax.persistence.Table; * @author Jens Pelzetter */ @Entity -@Table(name = "CONF_ENTRIES_BIG_DECIMAL") +@Table(name = "CONF_ENTRIES_BIG_DECIMAL", schema = DB_SCHEMA) public class BigDecimalConfigurationEntry extends AbstractConfigurationEntry implements Serializable { diff --git a/ccm-core/src/main/java/org/libreccm/configuration/Configuration.java b/ccm-core/src/main/java/org/libreccm/configuration/Configuration.java new file mode 100644 index 000000000..80baf53d2 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/configuration/Configuration.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 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.libreccm.configuration; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.ResourceBundle; + +/** + * Marks a class as configuration class which is managed by the + * {@link ConfigurationManager}. + * + * @author Jens Pelzetter + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Configuration { + + /** + * The name of the configuration. If left blank the simple name of the class + * is used. + * + * @return Name of the configuration. + */ + String name() default ""; + + /** + * Points to the {@link ResourceBundle} containing the descriptions + * of the configuration and all entries of the configuration. + * + * @return Fully qualified name of the {@link ResourceBundle}. + */ + String descBundle() default ""; + + /** + * Key of the description of the configuration in the resource bundle + * provided by {@link #descBundle()}. + * + * @return Key of the description. + */ + String descKey() default ""; + +} diff --git a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationConstants.java b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationConstants.java new file mode 100644 index 000000000..a9082134a --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationConstants.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 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.libreccm.configuration; + +/** + * + * @author Jens Pelzetter + */ +public class ConfigurationConstants { + + public static final String REGISTRY_DOMAIN = "registry"; + + private ConfigurationConstants() { + //Nothing + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java new file mode 100644 index 000000000..6e1e99c59 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 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.libreccm.configuration; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import org.libreccm.categorization.CategoryManager; +import org.libreccm.categorization.Domain; +import org.libreccm.categorization.DomainManager; +import org.libreccm.categorization.DomainRepository; + +import static org.libreccm.configuration.ConfigurationConstants.*; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ConfigurationManager { + + @Inject + private CategoryManager categoryManager; + + @Inject + private DomainRepository domainRepository; + + @Inject + private DomainManager domainManager; + + @Inject + private EntityManager entityManager; + + + + public AbstractConfigurationEntry getEntry(final String name, + final Class clazz) { + final String[] tokens = name.split("."); + + final Domain registry = domainRepository.findByDomainKey(REGISTRY_DOMAIN); + + throw new UnsupportedOperationException(); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/configuration/EnumConfigurationEntry.java b/ccm-core/src/main/java/org/libreccm/configuration/EnumConfigurationEntry.java index 0f571e7eb..0c088f40e 100644 --- a/ccm-core/src/main/java/org/libreccm/configuration/EnumConfigurationEntry.java +++ b/ccm-core/src/main/java/org/libreccm/configuration/EnumConfigurationEntry.java @@ -22,11 +22,13 @@ import static org.libreccm.core.CoreConstants.*; import java.io.Serializable; import java.util.Collections; -import java.util.List; +import java.util.Set; import java.util.Objects; import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.Table; /** @@ -36,24 +38,27 @@ import javax.persistence.Table; @Entity @Table(name = "CONF_ENTRIES_ENUM", schema = DB_SCHEMA) public class EnumConfigurationEntry - extends AbstractConfigurationEntry> implements Serializable { + extends AbstractConfigurationEntry> implements Serializable { private static final long serialVersionUID = 8506016944203102813L; @ElementCollection - private List value; + @JoinTable(name = "ENUM_CONFIGURATION_ENTRIES_VALUES", + schema = DB_SCHEMA, + joinColumns = {@JoinColumn(name = "ENUM_ID")}) + private Set value; @Override - public List getValue() { + public Set getValue() { if (value == null) { return null; } else { - return Collections.unmodifiableList(value); + return Collections.unmodifiableSet(value); } } @Override - public void setValue(final List value) { + public void setValue(final Set value) { this.value = value; } diff --git a/ccm-core/src/main/java/org/libreccm/configuration/Setting.java b/ccm-core/src/main/java/org/libreccm/configuration/Setting.java new file mode 100644 index 000000000..f7c2a0edc --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/configuration/Setting.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 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.libreccm.configuration; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a field of a class annotated with {@link Configuration} as setting. + * + * @author Jens Pelzetter + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Setting { + + /** + * Name of the setting. If left blank the name of annotated field is + * used. + * + * @return The name of the setting. + */ + String name() default ""; + + /** + * Key of description of the setting. + * + * @return Key of description of the setting. + */ + String descKey() default ""; + +} diff --git a/ccm-core/src/main/java/org/libreccm/core/CcmObject.java b/ccm-core/src/main/java/org/libreccm/core/CcmObject.java index ed59b9db2..3583dc041 100644 --- a/ccm-core/src/main/java/org/libreccm/core/CcmObject.java +++ b/ccm-core/src/main/java/org/libreccm/core/CcmObject.java @@ -181,7 +181,7 @@ public class CcmObject implements Serializable { * * @param category The domain ownership to add. */ - protected void addCategory(final Categorization category) { + public void addCategory(final Categorization category) { categories.add(category); } @@ -192,7 +192,7 @@ public class CcmObject implements Serializable { * * @param category The assigned category to remove. */ - protected void removeCategory(final Categorization category) { + public void removeCategory(final Categorization category) { categories.remove(category); } diff --git a/ccm-core/src/main/java/org/libreccm/security/SecuredCollection.java b/ccm-core/src/main/java/org/libreccm/security/SecuredCollection.java index b5e837224..cccab8a9b 100644 --- a/ccm-core/src/main/java/org/libreccm/security/SecuredCollection.java +++ b/ccm-core/src/main/java/org/libreccm/security/SecuredCollection.java @@ -18,9 +18,6 @@ */ package org.libreccm.security; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.core.CcmObject; @@ -38,16 +35,16 @@ import java.util.Iterator; * check if the current subject is permitted to access the object. If the * current subject is permitted to access the object the object is returned. * Otherwise the object is replaced with a virtual object were the - * {@link CcmObject#displayName} property is set to {@code Access Denied}. - * Methods which return arrays or collections of objects from the decorated + * {@link CcmObject#displayName} property is set to {@code Access Denied}. + * Methods which return arrays or collections of objects from the decorated * collection check each object in the array or collection and replace the - * objects which the current subject is not permitted to access with a + * objects which the current subject is not permitted to access with a * Access denied object. * * @author Jens Pelzetter * - * @param Type of the objects in the collection. Must extend - * {@link CcmObject}. + * @param Type of the objects in the collection. Must extend + * {@link CcmObject}. */ @SuppressWarnings("PMD.TooManyMethods") public class SecuredCollection implements Collection { @@ -58,7 +55,7 @@ public class SecuredCollection implements Collection { private final Collection collection; /** - * The class of the objects in the collection. Required for creating the + * The class of the objects in the collection. Required for creating the * virtual Access denied object */ private final Class clazz; @@ -75,11 +72,11 @@ public class SecuredCollection implements Collection { /** * Create a new secured collection for the provided collection. - * - * @param collection The collection to secure. - * @param clazz The class of the objects in the collection. - * @param requiredPrivilege The privilege required to access the objects - * in the collection. + * + * @param collection The collection to secure. + * @param clazz The class of the objects in the collection. + * @param requiredPrivilege The privilege required to access the objects in + * the collection. */ public SecuredCollection(final Collection collection, final Class clazz, @@ -114,14 +111,9 @@ public class SecuredCollection implements Collection { @Override @SuppressWarnings("unchecked") public Object[] toArray() { - final PermissionChecker permissionChecker; final CdiUtil cdiUtil = new CdiUtil(); - try { - permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final PermissionChecker permissionChecker = cdiUtil.findBean( + PermissionChecker.class); final Object[] objects = collection.toArray(); for (int i = 0; i < objects.length; i++) { @@ -137,14 +129,9 @@ public class SecuredCollection implements Collection { @Override @SuppressWarnings({"unchecked", "PMD.UseVarargs"}) public T[] toArray(final T[] array) { - final PermissionChecker permissionChecker; final CdiUtil cdiUtil = new CdiUtil(); - try { - permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } + final PermissionChecker permissionChecker = cdiUtil.findBean( + PermissionChecker.class); final T[] objects = collection.toArray(array); for (int i = 0; i < objects.length; i++) { diff --git a/ccm-core/src/main/java/org/libreccm/security/SecuredEntrySet.java b/ccm-core/src/main/java/org/libreccm/security/SecuredEntrySet.java index 4fbc720c5..fb3265f0b 100644 --- a/ccm-core/src/main/java/org/libreccm/security/SecuredEntrySet.java +++ b/ccm-core/src/main/java/org/libreccm/security/SecuredEntrySet.java @@ -18,9 +18,6 @@ */ package org.libreccm.security; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.core.CcmObject; @@ -93,15 +90,10 @@ class SecuredEntrySet, K, V extends CcmObject> @Override @SuppressWarnings("unchecked") public Object[] toArray() { - final PermissionChecker permissionChecker; final CdiUtil cdiUtil = new CdiUtil(); - try { - permissionChecker = cdiUtil.findBean( + final PermissionChecker permissionChecker = cdiUtil.findBean( PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final Object[] entries = set.toArray(); for (int i = 0; i < entries.length; i++) { final E entry = (E) entries[i]; @@ -117,15 +109,10 @@ class SecuredEntrySet, K, V extends CcmObject> @Override @SuppressWarnings({"unchecked", "PMD.UseVarargs"}) public T[] toArray(final T[] array) { - final PermissionChecker permissionChecker; final CdiUtil cdiUtil = new CdiUtil(); - try { - permissionChecker = cdiUtil.findBean( + final PermissionChecker permissionChecker = cdiUtil.findBean( PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + final E[] entries = (E[]) set.toArray(array); for (int i = 0; i < entries.length; i++) { if (!permissionChecker.isPermitted(requiredPrivilege, diff --git a/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java b/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java index 9cebf420d..45bbbea99 100644 --- a/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java +++ b/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java @@ -18,13 +18,11 @@ */ package org.libreccm.security; -import com.arsdigita.util.UncheckedWrapperException; import static org.libreccm.core.CoreConstants.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiLookupException; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.core.CcmObject; @@ -69,14 +67,9 @@ class SecuredHelper { } final CdiUtil cdiUtil = new CdiUtil(); - final PermissionChecker permissionChecker; - try { - permissionChecker = cdiUtil.findBean( + final PermissionChecker permissionChecker = cdiUtil.findBean( PermissionChecker.class); - } catch (CdiLookupException ex) { - throw new UncheckedWrapperException(ex); - } - + if (permissionChecker.isPermitted(requiredPrivilege, object)) { return object; } else { diff --git a/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java b/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java index c1a25e32b..be3dca149 100644 --- a/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java +++ b/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java @@ -140,7 +140,7 @@ public class CcmApplication extends Resource implements Serializable { * * @param domain The domain ownership to add. */ - protected void addDomain(final DomainOwnership domain) { + public void addDomain(final DomainOwnership domain) { domains.add(domain); } @@ -151,7 +151,7 @@ public class CcmApplication extends Resource implements Serializable { * * @param domain The domain to remove. */ - protected void removeDomain(final DomainOwnership domain) { + public void removeDomain(final DomainOwnership domain) { domains.remove(domain); } diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_0__create_tables.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_0__create_tables.sql index b0896cac2..bcac00338 100644 --- a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_0__create_tables.sql +++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_0__create_tables.sql @@ -1,4 +1,3 @@ -create schema CCM_CORE; create table CCM_CORE.APPLICATIONS ( APPLICATION_TYPE varchar(1024) not null, @@ -49,7 +48,7 @@ create schema CCM_CORE; create table CCM_CORE.CATEGORY_DOMAINS ( DOMAIN_KEY varchar(255) not null, RELEASED timestamp, - URI varchar(1024) not null, + URI varchar(1024), VERSION varchar(255) not null, OBJECT_ID bigint not null, ROOT_CATEGORY_ID bigint, @@ -82,6 +81,59 @@ create schema CCM_CORE; primary key (ROLE_ID) ); + create table CCM_CORE.CONFIGURATION_ENTRIES ( + comment varchar(2048), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL ( + entry_value decimal(19,2), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BOOLEAN ( + entry_value boolean, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_DOUBLE ( + entry_value double, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_ENUM ( + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_INTEGER ( + entry_value bigint, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STRING ( + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES ( + ENTRY_ID bigint not null, + LOCALIZED_VALUE clob, + LOCALE varchar(255) not null, + primary key (ENTRY_ID, LOCALE) + ); + + create table CCM_CORE.CONF_ENTRIES_STRING ( + entry_value varchar(1024), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + create table CCM_CORE.DIGESTS ( FREQUENCY integer, HEADER varchar(4096) not null, @@ -118,6 +170,11 @@ create schema CCM_CORE; primary key (OBJECT_ID, LOCALE) ); + create table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES ( + ENUM_ID bigint not null, + value varchar(255) + ); + create table CCM_CORE.FORMBUILDER_COMPONENTS ( ACTIVE boolean, ADMIN_NAME varchar(255), @@ -621,6 +678,51 @@ create schema CCM_CORE; foreign key (OBJECT_ID) references CCM_CORE.CATEGORIES; + alter table CCM_CORE.CONFIGURATION_ENTRIES + add constraint FK_8u6h7p0gs4ybf0ju240mggb73 + foreign key (OBJECT_ID) + references CCM_CORE.CCM_OBJECTS; + + alter table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL + add constraint FK_3tnub4je6c2bwi0c3p9m2n6d1 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_BOOLEAN + add constraint FK_d79uxyam5uhhmw3ijw3c14gk2 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_DOUBLE + add constraint FK_l5qxx6wfngl2hvnqaq77oin1s + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_ENUM + add constraint FK_blwwj2ht4wbg82meuuxf0t7kk + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_INTEGER + add constraint FK_reo0efdw6evf11viwlse1w27 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STRING + add constraint FK_dbvyqoliuh0d7bl6ksng4abe + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES + add constraint FK_ftb5yqeoli1m932yp3p8ho74g + foreign key (ENTRY_ID) + references CCM_CORE.CONF_ENTRIES_L10N_STRING; + + alter table CCM_CORE.CONF_ENTRIES_STRING + add constraint FK_j31m640x2cn0xl5jcbik06708 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + alter table CCM_CORE.DIGESTS add constraint FK_3xrcpufumqnh4ke4somt89rvh foreign key (FROM_PARTY_ID) @@ -651,6 +753,11 @@ create schema CCM_CORE; foreign key (OBJECT_ID) references CCM_CORE.CATEGORY_DOMAINS; + alter table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES + add constraint FK_ao3evxajxd8y4gy5a6e8ua49j + foreign key (ENUM_ID) + references CCM_CORE.CONF_ENTRIES_ENUM; + alter table CCM_CORE.FORMBUILDER_COMPONENTS add constraint FK_72108sd6vsqt88g3fb4kl6o81 foreign key (parentComponent_OBJECT_ID) diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_0__create_tables.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_0__create_tables.sql index c338c9c35..8c95bc0f4 100644 --- a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_0__create_tables.sql +++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_0__create_tables.sql @@ -1,3 +1,4 @@ + create table CCM_CORE.APPLICATIONS ( APPLICATION_TYPE varchar(1024) not null, PRIMARY_URL varchar(1024) not null, @@ -47,7 +48,7 @@ create table CCM_CORE.CATEGORY_DOMAINS ( DOMAIN_KEY varchar(255) not null, RELEASED timestamp, - URI varchar(1024) not null, + URI varchar(1024), VERSION varchar(255) not null, OBJECT_ID int8 not null, ROOT_CATEGORY_ID int8, @@ -80,6 +81,59 @@ primary key (ROLE_ID) ); + create table CCM_CORE.CONFIGURATION_ENTRIES ( + comment varchar(2048), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL ( + entry_value numeric(19, 2), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BOOLEAN ( + entry_value boolean, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_DOUBLE ( + entry_value float8, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_ENUM ( + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_INTEGER ( + entry_value int8, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STRING ( + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES ( + ENTRY_ID int8 not null, + LOCALIZED_VALUE text, + LOCALE varchar(255) not null, + primary key (ENTRY_ID, LOCALE) + ); + + create table CCM_CORE.CONF_ENTRIES_STRING ( + entry_value varchar(1024), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + create table CCM_CORE.DIGESTS ( FREQUENCY int4, HEADER varchar(4096) not null, @@ -116,6 +170,11 @@ primary key (OBJECT_ID, LOCALE) ); + create table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES ( + ENUM_ID int8 not null, + value varchar(255) + ); + create table CCM_CORE.FORMBUILDER_COMPONENTS ( ACTIVE boolean, ADMIN_NAME varchar(255), @@ -619,6 +678,51 @@ foreign key (OBJECT_ID) references CCM_CORE.CATEGORIES; + alter table CCM_CORE.CONFIGURATION_ENTRIES + add constraint FK_8u6h7p0gs4ybf0ju240mggb73 + foreign key (OBJECT_ID) + references CCM_CORE.CCM_OBJECTS; + + alter table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL + add constraint FK_3tnub4je6c2bwi0c3p9m2n6d1 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_BOOLEAN + add constraint FK_d79uxyam5uhhmw3ijw3c14gk2 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_DOUBLE + add constraint FK_l5qxx6wfngl2hvnqaq77oin1s + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_ENUM + add constraint FK_blwwj2ht4wbg82meuuxf0t7kk + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_INTEGER + add constraint FK_reo0efdw6evf11viwlse1w27 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STRING + add constraint FK_dbvyqoliuh0d7bl6ksng4abe + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES + add constraint FK_ftb5yqeoli1m932yp3p8ho74g + foreign key (ENTRY_ID) + references CCM_CORE.CONF_ENTRIES_L10N_STRING; + + alter table CCM_CORE.CONF_ENTRIES_STRING + add constraint FK_j31m640x2cn0xl5jcbik06708 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + alter table CCM_CORE.DIGESTS add constraint FK_3xrcpufumqnh4ke4somt89rvh foreign key (FROM_PARTY_ID) @@ -649,6 +753,11 @@ foreign key (OBJECT_ID) references CCM_CORE.CATEGORY_DOMAINS; + alter table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES + add constraint FK_ao3evxajxd8y4gy5a6e8ua49j + foreign key (ENUM_ID) + references CCM_CORE.CONF_ENTRIES_ENUM; + alter table CCM_CORE.FORMBUILDER_COMPONENTS add constraint FK_72108sd6vsqt88g3fb4kl6o81 foreign key (parentComponent_OBJECT_ID) diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java new file mode 100644 index 000000000..88b5627b9 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2015 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.libreccm.categorization; + +import org.jboss.arquillian.container.test.api.Deployment; +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.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreccm.core.CcmObject; +import org.libreccm.core.CcmObjectRepository; +import org.libreccm.jpa.EntityManagerProducer; +import org.libreccm.jpa.utils.MimeTypeConverter; +import org.libreccm.l10n.LocalizedString; +import org.libreccm.security.Permission; +import org.libreccm.tests.categories.IntegrationTest; +import org.libreccm.testutils.EqualsVerifier; +import org.libreccm.web.CcmApplication; +import org.libreccm.workflow.Workflow; + +import java.io.File; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * + * @author Jens Pelzetter + */ +@org.junit.experimental.categories.Category(IntegrationTest.class) +@RunWith(Arquillian.class) +@PersistenceTest +@Transactional(TransactionMode.COMMIT) +@CreateSchema({"create_ccm_core_schema.sql"}) +public class CategoryManagerTest { + + @Inject + private CategoryRepository categoryRepo; + + @Inject + private CategoryManager categoryManager; + + @Inject + private CcmObjectRepository ccmObjectRepo; + + @Inject + private DomainRepository domainRepo; + + @PersistenceContext(name = "LibreCCM") + private EntityManager entityManager; + + public CategoryManagerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Deployment + public static WebArchive createDeployment() { + final PomEquippedResolveStage pom = Maven + .resolver() + .loadPomFromFile("pom.xml"); + final PomEquippedResolveStage dependencies = pom + .importCompileAndRuntimeDependencies(); + final File[] libs = dependencies.resolve().withTransitivity().asFile(); + + for (File lib : libs) { + System.err.printf("Adding file '%s' to test archive...%n", + lib.getName()); + } + + return ShrinkWrap + .create(WebArchive.class, + "LibreCCM-org.libreccm.categorization.CategoryManagerTest.war") + .addPackage(CcmObject.class.getPackage()) + .addPackage(Permission.class.getPackage()) + .addPackage(CcmApplication.class.getPackage()) + .addPackage(Categorization.class.getPackage()) + .addPackage(LocalizedString.class.getPackage()) + .addPackage(Workflow.class.getPackage()) + .addPackage(EntityManagerProducer.class.getPackage()) + .addPackage(MimeTypeConverter.class.getPackage()) + .addPackage(EqualsVerifier.class.getPackage()) + .addPackage(IntegrationTest.class.getPackage()) + .addAsLibraries(libs) + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + } + + @Test + @InSequence(1) + public void managerIsInjected() { + assertThat(categoryManager, is(not(nullValue()))); + } + + @Test + @InSequence(2) + public void entityManagerIsInjected() { + assertThat(entityManager, is(not((nullValue())))); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml") + @InSequence(3) + public void datasetOnly() { + System.out.println("Dataset loaded successfully."); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml") + @ShouldMatchDataSet(value + = "datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml", + excludeColumns = {"categorization_id"}) + @InSequence(1100) + public void addObjectToCategory() { + final CcmObject object2 = ccmObjectRepo.findById(-3200L); + final Category foo = categoryRepo.findById(-2100L); + + assertThat(object2, is(not(nullValue()))); + assertThat(foo, is(not(nullValue()))); + + categoryManager.addObjectToCategory(object2, foo); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml") + @ShouldMatchDataSet(value + = "datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-obj-from-category.yml", + excludeColumns = {"categorization_id"}) + @InSequence(1200) + public void removeObjectFromCategory() + throws ObjectNotAssignedToCategoryException { + + final CcmObject object1 = ccmObjectRepo.findById(-3100L); + final Category foo = categoryRepo.findById(-2100L); + + assertThat(object1, is(not(nullValue()))); + assertThat(foo, is(not(nullValue()))); + + categoryManager.removeObjectFromCategory(object1, foo); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml") + @ShouldMatchDataSet( + value = "datasets/org/libreccm/categorization/" + + "CategoryManagerTest/after-add-subcategory.yml", + excludeColumns = {"object_id"}) + @InSequence(2100) + public void addSubCategoryToCategory() { + final Category category = new Category(); + category.setName("category-new"); + category.setDisplayName("category-new"); + category.setUniqueId("catnew"); + categoryRepo.save(category); + + final TypedQuery query = entityManager.createQuery( + "SELECT c FROM Category c WHERE c.name = :name", + Category.class); + query.setParameter("name", "category-new"); + final Category sub = query.getSingleResult(); + + final Category foo = categoryRepo.findById(-2100L); +// final Category sub = categoryRepo.findById(-2200L); + + categoryManager.addSubCategoryToCategory(sub, foo); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml") + @ShouldMatchDataSet(value + = "datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-subcategory.yml", + excludeColumns = {"categorization_id", "object_id"}) + @InSequence(2200) + public void removeSubCategoryToCategory() { + final Category foo = categoryRepo.findById(-2100L); + final Category bar = categoryRepo.findById(-2200L); + + categoryManager.removeSubCategoryFromCategory(bar, foo); + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java new file mode 100644 index 000000000..d24111932 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2015 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.libreccm.categorization; + +import java.io.File; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +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.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreccm.core.CcmObject; +import org.libreccm.jpa.EntityManagerProducer; +import org.libreccm.jpa.utils.MimeTypeConverter; +import org.libreccm.l10n.LocalizedString; +import org.libreccm.security.Permission; +import org.libreccm.tests.categories.IntegrationTest; +import org.libreccm.testutils.EqualsVerifier; +import org.libreccm.web.CcmApplication; +import org.libreccm.workflow.Workflow; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * + * @author Jens Pelzetter + */ +@org.junit.experimental.categories.Category(IntegrationTest.class) +@RunWith(Arquillian.class) +@PersistenceTest +@Transactional(TransactionMode.COMMIT) +@CreateSchema({"create_ccm_core_schema.sql"}) +public class CategoryRepositoryTest { + + @Inject + private CategoryRepository categoryRepo; + + @Inject + private DomainRepository domainRepo; + + @PersistenceContext(name = "LibreCCM") + private EntityManager entityManager; + + public CategoryRepositoryTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Deployment + public static WebArchive createDeployment() { + final PomEquippedResolveStage pom = Maven + .resolver() + .loadPomFromFile("pom.xml"); + final PomEquippedResolveStage dependencies = pom + .importCompileAndRuntimeDependencies(); + final File[] libs = dependencies.resolve().withTransitivity().asFile(); + + for (File lib : libs) { + System.err.printf("Adding file '%s' to test archive...%n", + lib.getName()); + } + + return ShrinkWrap + .create(WebArchive.class, + "LibreCCM-org.libreccm.categorization.CategoryRepositoryTest.war") + .addPackage(CcmObject.class.getPackage()) + .addPackage(Permission.class.getPackage()) + .addPackage(CcmApplication.class.getPackage()) + .addPackage(Categorization.class.getPackage()) + .addPackage(LocalizedString.class.getPackage()) + .addPackage(Workflow.class.getPackage()) + .addPackage(EntityManagerProducer.class.getPackage()) + .addPackage(MimeTypeConverter.class.getPackage()) + .addPackage(EqualsVerifier.class.getPackage()) + .addPackage(IntegrationTest.class.getPackage()) + .addAsLibraries(libs) + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + } + + @Test + @InSequence(1) + public void repoIsInjected() { + assertThat(categoryRepo, is(not(nullValue()))); + } + + @Test + @InSequence(2) + public void entityManagerIsInjected() { + assertThat(entityManager, is(not((nullValue())))); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml") + @InSequence(3) + public void datasetOnly() { + System.out.println("Dataset loaded successfully."); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml") + @InSequence(1100) + public void findByPathString() { + final Category category1 = categoryRepo.findByPath("test:/foo/bar/"); + final Category category2 = categoryRepo.findByPath("test:/foo/bar"); + final Category category3 = categoryRepo.findByPath("test:/foo/"); + + final Category notFound = categoryRepo + .findByPath("test:/does/not/exist"); + + assertThat(category1, is(not(nullValue()))); + assertThat(category1.getName(), is(equalTo("bar"))); + + assertThat(category2, is(not(nullValue()))); + assertThat(category2.getName(), is(equalTo("bar"))); + + assertThat(category3, is(not(nullValue()))); + assertThat(category3.getName(), is(equalTo("foo"))); + + assertThat(notFound, is(nullValue())); + } + + @Test(expected = InvalidCategoryPathException.class) + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml") + @ShouldThrowException(InvalidCategoryPathException.class) + @InSequence(1200) + public void findByPathStringInvalidDomain() { + categoryRepo.findByPath("invalid:/foo/bar/"); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml") + @InSequence(2100) + public void findByPathDomainString() { + final Domain domain = domainRepo.findByDomainKey("test"); + + final Category category1 = categoryRepo.findByPath(domain, "/foo/bar/"); + final Category category2 = categoryRepo.findByPath(domain, "foo/bar/"); + final Category category3 = categoryRepo.findByPath(domain, "/foo/bar"); + final Category category4 = categoryRepo.findByPath(domain, "foo/bar"); + + final Category notFound = categoryRepo.findByPath(domain, + "/does/not/exist"); + + assertThat(category1, is(not(nullValue()))); + assertThat(category1.getName(), is(equalTo("bar"))); + + assertThat(category2, is(not(nullValue()))); + assertThat(category2.getName(), is(equalTo("bar"))); + + assertThat(category3, is(not(nullValue()))); + assertThat(category3.getName(), is(equalTo("bar"))); + + assertThat(category4, is(not(nullValue()))); + assertThat(category4.getName(), is(equalTo("bar"))); + + assertThat(notFound, is(nullValue())); + } + + @Test + @UsingDataSet( + "datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml") + @ShouldMatchDataSet( + value = "datasets/org/libreccm/categorization/CategoryRepositoryTest/" + + "after-save-new-category.yml", + excludeColumns = {"object_id"}) + @InSequence(3100) + public void saveNewCategory() { + final Category category = new Category(); + category.setDisplayName("new-category"); + category.setName("new-category"); + category.setUniqueId("new0001"); + + categoryRepo.save(category); + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/categorization/DatasetsTest.java b/ccm-core/src/test/java/org/libreccm/categorization/DatasetsTest.java new file mode 100644 index 000000000..1448a4602 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/categorization/DatasetsTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 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.libreccm.categorization; + +import java.util.Arrays; +import java.util.Collection; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.libreccm.tests.categories.UnitTest; +import org.libreccm.testutils.DatasetType; +import org.libreccm.testutils.DatasetsVerifier; + +import static org.libreccm.testutils.DatasetType.*; + + +/** + * + * @author Jens Pelzetter + */ +@RunWith(Parameterized.class) +@org.junit.experimental.categories.Category(UnitTest.class) +public class DatasetsTest extends DatasetsVerifier { + + @Parameterized.Parameters(name = "Dataset {0}") + public static Collection data() { + return Arrays.asList(new String[]{ + "/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml", + "/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-subcategory.yml", + "/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-obj-from-category.yml", + "/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-subcategory.yml", + "/datasets/org/libreccm/categorization/CategoryManagerTest/data.yml", + "/datasets/org/libreccm/categorization/CategoryManagerTest/data2.yml", + "/datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml", + "/datasets/org/libreccm/categorization/CategoryRepositoryTest/after-save-new-category.yml" + }); + } + + public DatasetsTest(final String datasetPath) { + super(datasetPath); + } + + @Override + public String[] getSchemas() { + return new String[]{"ccm_core"}; + } + + @Override + public DatasetType getDatasetType() { + return YAML; + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java b/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java index 9ed90cacc..9b6f7cc17 100644 --- a/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/AuthorizationInterceptorTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -40,7 +39,6 @@ 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.jboss.shrinkwrap.resolver.api.maven.Maven; import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; @@ -141,7 +139,6 @@ public class AuthorizationInterceptorTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/GroupManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/GroupManagerTest.java index cae6d468c..4e2dfa308 100644 --- a/ccm-core/src/test/java/org/libreccm/security/GroupManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/GroupManagerTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -136,7 +135,6 @@ public class GroupManagerTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java index dbef8b8d8..34ff460b6 100644 --- a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -150,7 +149,6 @@ public class PermissionCheckerTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java index 898356745..5134afe05 100644 --- a/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/PermissionManagerTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -64,7 +63,6 @@ import java.io.File; import javax.inject.Inject; import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -142,7 +140,6 @@ public class PermissionManagerTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java index acdf50712..053039c8d 100644 --- a/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/RoleManagerTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -136,7 +135,6 @@ public class RoleManagerTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java b/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java index 008593bbe..f46a9e354 100644 --- a/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/SecuredCollectionTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -167,7 +166,6 @@ public class SecuredCollectionTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java b/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java index 15124ed39..bf1398c35 100644 --- a/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/SecuredIteratorTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -167,7 +166,6 @@ public class SecuredIteratorTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java b/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java index 636e13354..0982c7d55 100644 --- a/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/ShiroTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -136,7 +135,6 @@ public class ShiroTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java b/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java index f29f4cea6..f53c96fee 100644 --- a/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/UserManagerTest.java @@ -21,7 +21,6 @@ package org.libreccm.security; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.parameter.AbstractParameterContext; import com.arsdigita.web.CCMApplicationContextListener; import com.arsdigita.xml.XML; @@ -137,7 +136,6 @@ public class UserManagerTest { .addPackage(SecurityConfig.class.getPackage()) .addPackage(AbstractConfig.class.getPackage()) .addPackage(AbstractParameterContext.class.getPackage()) - .addPackage(UncheckedWrapperException.class.getPackage()) .addPackage(CCMApplicationContextListener.class.getPackage()) .addPackage(XML.class.getPackage()) .addPackage(DateTimeFormatter.class.getPackage()) diff --git a/ccm-core/src/test/resources-wildfly8-remote-h2-mem/scripts/create_ccm_core_schema.sql b/ccm-core/src/test/resources-wildfly8-remote-h2-mem/scripts/create_ccm_core_schema.sql index 93470dec6..d2503fbbb 100644 --- a/ccm-core/src/test/resources-wildfly8-remote-h2-mem/scripts/create_ccm_core_schema.sql +++ b/ccm-core/src/test/resources-wildfly8-remote-h2-mem/scripts/create_ccm_core_schema.sql @@ -5,6 +5,7 @@ DROP SEQUENCE IF EXISTS hibernate_sequence; CREATE SCHEMA ccm_core; + create table CCM_CORE.APPLICATIONS ( APPLICATION_TYPE varchar(1024) not null, PRIMARY_URL varchar(1024) not null, @@ -54,7 +55,7 @@ CREATE SCHEMA ccm_core; create table CCM_CORE.CATEGORY_DOMAINS ( DOMAIN_KEY varchar(255) not null, RELEASED timestamp, - URI varchar(1024) not null, + URI varchar(1024), VERSION varchar(255) not null, OBJECT_ID bigint not null, ROOT_CATEGORY_ID bigint, @@ -83,10 +84,63 @@ CREATE SCHEMA ccm_core; create table CCM_CORE.CCM_ROLES ( ROLE_ID bigint not null, - name varchar(512) not null, + NAME varchar(512) not null, primary key (ROLE_ID) ); + create table CCM_CORE.CONFIGURATION_ENTRIES ( + comment varchar(2048), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL ( + entry_value decimal(19,2), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BOOLEAN ( + entry_value boolean, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_DOUBLE ( + entry_value double, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_ENUM ( + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_INTEGER ( + entry_value bigint, + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STRING ( + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES ( + ENTRY_ID bigint not null, + LOCALIZED_VALUE clob, + LOCALE varchar(255) not null, + primary key (ENTRY_ID, LOCALE) + ); + + create table CCM_CORE.CONF_ENTRIES_STRING ( + entry_value varchar(1024), + OBJECT_ID bigint not null, + primary key (OBJECT_ID) + ); + create table CCM_CORE.DIGESTS ( FREQUENCY integer, HEADER varchar(4096) not null, @@ -123,6 +177,11 @@ CREATE SCHEMA ccm_core; primary key (OBJECT_ID, LOCALE) ); + create table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES ( + ENUM_ID bigint not null, + value varchar(255) + ); + create table CCM_CORE.FORMBUILDER_COMPONENTS ( ACTIVE boolean, ADMIN_NAME varchar(255), @@ -466,6 +525,13 @@ CREATE SCHEMA ccm_core; primary key (MEMBERSHIP_ID) ); + create table CCM_CORE.TASK_ASSIGNMENTS ( + TASK_ASSIGNMENT_ID bigint not null, + ROLE_ID bigint, + TASK_ID bigint, + primary key (TASK_ASSIGNMENT_ID) + ); + create table CCM_CORE.THREADS ( OBJECT_ID bigint not null, ROOT_ID bigint, @@ -557,16 +623,6 @@ CREATE SCHEMA ccm_core; primary key (TASK_ID) ); - create table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS ( - USER_TASK_ID bigint not null, - ASSIGNED_GROUP_ID bigint not null - ); - - create table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS ( - USER_TASK_ID bigint not null, - ASSIGNED_USER_ID bigint not null - ); - alter table CCM_CORE.CATEGORY_DOMAINS add constraint UK_mb1riernf8a88u3mwl0bgfj8y unique (DOMAIN_KEY); @@ -579,12 +635,6 @@ CREATE SCHEMA ccm_core; alter table CCM_CORE.INSTALLED_MODULES add constraint UK_11imwgfojyi4hpr18uw9g3jvx unique (MODULE_CLASS_NAME); - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint UK_q9evs4qcfhr79fha7xgk057wo unique (ASSIGNED_GROUP_ID); - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint UK_bb9rm595xsbrpyx95lmwnlg76 unique (ASSIGNED_USER_ID); - alter table CCM_CORE.APPLICATIONS add constraint FK_sn1sqtx94nhxgv282ymoqiock foreign key (OBJECT_ID) @@ -635,6 +685,51 @@ CREATE SCHEMA ccm_core; foreign key (OBJECT_ID) references CCM_CORE.CATEGORIES; + alter table CCM_CORE.CONFIGURATION_ENTRIES + add constraint FK_8u6h7p0gs4ybf0ju240mggb73 + foreign key (OBJECT_ID) + references CCM_CORE.CCM_OBJECTS; + + alter table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL + add constraint FK_3tnub4je6c2bwi0c3p9m2n6d1 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_BOOLEAN + add constraint FK_d79uxyam5uhhmw3ijw3c14gk2 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_DOUBLE + add constraint FK_l5qxx6wfngl2hvnqaq77oin1s + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_ENUM + add constraint FK_blwwj2ht4wbg82meuuxf0t7kk + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_INTEGER + add constraint FK_reo0efdw6evf11viwlse1w27 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STRING + add constraint FK_dbvyqoliuh0d7bl6ksng4abe + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES + add constraint FK_ftb5yqeoli1m932yp3p8ho74g + foreign key (ENTRY_ID) + references CCM_CORE.CONF_ENTRIES_L10N_STRING; + + alter table CCM_CORE.CONF_ENTRIES_STRING + add constraint FK_j31m640x2cn0xl5jcbik06708 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + alter table CCM_CORE.DIGESTS add constraint FK_3xrcpufumqnh4ke4somt89rvh foreign key (FROM_PARTY_ID) @@ -665,6 +760,11 @@ CREATE SCHEMA ccm_core; foreign key (OBJECT_ID) references CCM_CORE.CATEGORY_DOMAINS; + alter table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES + add constraint FK_ao3evxajxd8y4gy5a6e8ua49j + foreign key (ENUM_ID) + references CCM_CORE.CONF_ENTRIES_ENUM; + alter table CCM_CORE.FORMBUILDER_COMPONENTS add constraint FK_72108sd6vsqt88g3fb4kl6o81 foreign key (parentComponent_OBJECT_ID) @@ -955,6 +1055,16 @@ CREATE SCHEMA ccm_core; foreign key (ROLE_ID) references CCM_CORE.CCM_ROLES; + alter table CCM_CORE.TASK_ASSIGNMENTS + add constraint FK_klh64or0yq26c63181j1tps2o + foreign key (ROLE_ID) + references CCM_CORE.CCM_ROLES; + + alter table CCM_CORE.TASK_ASSIGNMENTS + add constraint FK_fu6ukne6hj8ihlfxtmp17xpfj + foreign key (TASK_ID) + references CCM_CORE.WORKFLOW_USER_TASKS; + alter table CCM_CORE.THREADS add constraint FK_oopqroe5a8fg932teo0cyifcv foreign key (ROOT_ID) @@ -1005,24 +1115,4 @@ CREATE SCHEMA ccm_core; foreign key (WORKFLOW_ID) references CCM_CORE.WORKFLOWS; - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint FK_q9evs4qcfhr79fha7xgk057wo - foreign key (ASSIGNED_GROUP_ID) - references CCM_CORE.GROUPS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint FK_lqtfvnswn0k8kjghoi4jk3qfe - foreign key (USER_TASK_ID) - references CCM_CORE.WORKFLOW_USER_TASKS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint FK_bb9rm595xsbrpyx95lmwnlg76 - foreign key (ASSIGNED_USER_ID) - references CCM_CORE.USERS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint FK_7qgn3rbw4wgpd77hhqogfh53x - foreign key (USER_TASK_ID) - references CCM_CORE.WORKFLOW_USER_TASKS; - create sequence hibernate_sequence start with 1 increment by 1; \ No newline at end of file diff --git a/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql b/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql index 464364622..6af1e6b55 100644 --- a/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql +++ b/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql @@ -5,6 +5,7 @@ DROP SEQUENCE IF EXISTS hibernate_sequence; CREATE SCHEMA ccm_core; + create table CCM_CORE.APPLICATIONS ( APPLICATION_TYPE varchar(1024) not null, PRIMARY_URL varchar(1024) not null, @@ -54,7 +55,7 @@ CREATE SCHEMA ccm_core; create table CCM_CORE.CATEGORY_DOMAINS ( DOMAIN_KEY varchar(255) not null, RELEASED timestamp, - URI varchar(1024) not null, + URI varchar(1024), VERSION varchar(255) not null, OBJECT_ID int8 not null, ROOT_CATEGORY_ID int8, @@ -83,10 +84,63 @@ CREATE SCHEMA ccm_core; create table CCM_CORE.CCM_ROLES ( ROLE_ID int8 not null, - name varchar(512) not null, + NAME varchar(512) not null, primary key (ROLE_ID) ); + create table CCM_CORE.CONFIGURATION_ENTRIES ( + comment varchar(2048), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL ( + entry_value numeric(19, 2), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_BOOLEAN ( + entry_value boolean, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_DOUBLE ( + entry_value float8, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_ENUM ( + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_INTEGER ( + entry_value int8, + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STRING ( + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + + create table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES ( + ENTRY_ID int8 not null, + LOCALIZED_VALUE text, + LOCALE varchar(255) not null, + primary key (ENTRY_ID, LOCALE) + ); + + create table CCM_CORE.CONF_ENTRIES_STRING ( + entry_value varchar(1024), + OBJECT_ID int8 not null, + primary key (OBJECT_ID) + ); + create table CCM_CORE.DIGESTS ( FREQUENCY int4, HEADER varchar(4096) not null, @@ -123,6 +177,11 @@ CREATE SCHEMA ccm_core; primary key (OBJECT_ID, LOCALE) ); + create table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES ( + ENUM_ID int8 not null, + value varchar(255) + ); + create table CCM_CORE.FORMBUILDER_COMPONENTS ( ACTIVE boolean, ADMIN_NAME varchar(255), @@ -466,6 +525,13 @@ CREATE SCHEMA ccm_core; primary key (MEMBERSHIP_ID) ); + create table CCM_CORE.TASK_ASSIGNMENTS ( + TASK_ASSIGNMENT_ID int8 not null, + ROLE_ID int8, + TASK_ID int8, + primary key (TASK_ASSIGNMENT_ID) + ); + create table CCM_CORE.THREADS ( OBJECT_ID int8 not null, ROOT_ID int8, @@ -557,16 +623,6 @@ CREATE SCHEMA ccm_core; primary key (TASK_ID) ); - create table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS ( - USER_TASK_ID int8 not null, - ASSIGNED_GROUP_ID int8 not null - ); - - create table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS ( - USER_TASK_ID int8 not null, - ASSIGNED_USER_ID int8 not null - ); - alter table CCM_CORE.CATEGORY_DOMAINS add constraint UK_mb1riernf8a88u3mwl0bgfj8y unique (DOMAIN_KEY); @@ -579,12 +635,6 @@ CREATE SCHEMA ccm_core; alter table CCM_CORE.INSTALLED_MODULES add constraint UK_11imwgfojyi4hpr18uw9g3jvx unique (MODULE_CLASS_NAME); - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint UK_q9evs4qcfhr79fha7xgk057wo unique (ASSIGNED_GROUP_ID); - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint UK_bb9rm595xsbrpyx95lmwnlg76 unique (ASSIGNED_USER_ID); - alter table CCM_CORE.APPLICATIONS add constraint FK_sn1sqtx94nhxgv282ymoqiock foreign key (OBJECT_ID) @@ -635,6 +685,51 @@ CREATE SCHEMA ccm_core; foreign key (OBJECT_ID) references CCM_CORE.CATEGORIES; + alter table CCM_CORE.CONFIGURATION_ENTRIES + add constraint FK_8u6h7p0gs4ybf0ju240mggb73 + foreign key (OBJECT_ID) + references CCM_CORE.CCM_OBJECTS; + + alter table CCM_CORE.CONF_ENTRIES_BIG_DECIMAL + add constraint FK_3tnub4je6c2bwi0c3p9m2n6d1 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_BOOLEAN + add constraint FK_d79uxyam5uhhmw3ijw3c14gk2 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_DOUBLE + add constraint FK_l5qxx6wfngl2hvnqaq77oin1s + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_ENUM + add constraint FK_blwwj2ht4wbg82meuuxf0t7kk + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_INTEGER + add constraint FK_reo0efdw6evf11viwlse1w27 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STRING + add constraint FK_dbvyqoliuh0d7bl6ksng4abe + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + + alter table CCM_CORE.CONF_ENTRIES_L10N_STR_VALUES + add constraint FK_ftb5yqeoli1m932yp3p8ho74g + foreign key (ENTRY_ID) + references CCM_CORE.CONF_ENTRIES_L10N_STRING; + + alter table CCM_CORE.CONF_ENTRIES_STRING + add constraint FK_j31m640x2cn0xl5jcbik06708 + foreign key (OBJECT_ID) + references CCM_CORE.CONFIGURATION_ENTRIES; + alter table CCM_CORE.DIGESTS add constraint FK_3xrcpufumqnh4ke4somt89rvh foreign key (FROM_PARTY_ID) @@ -665,6 +760,11 @@ CREATE SCHEMA ccm_core; foreign key (OBJECT_ID) references CCM_CORE.CATEGORY_DOMAINS; + alter table CCM_CORE.ENUM_CONFIGURATION_ENTRIES_VALUES + add constraint FK_ao3evxajxd8y4gy5a6e8ua49j + foreign key (ENUM_ID) + references CCM_CORE.CONF_ENTRIES_ENUM; + alter table CCM_CORE.FORMBUILDER_COMPONENTS add constraint FK_72108sd6vsqt88g3fb4kl6o81 foreign key (parentComponent_OBJECT_ID) @@ -955,6 +1055,16 @@ CREATE SCHEMA ccm_core; foreign key (ROLE_ID) references CCM_CORE.CCM_ROLES; + alter table CCM_CORE.TASK_ASSIGNMENTS + add constraint FK_klh64or0yq26c63181j1tps2o + foreign key (ROLE_ID) + references CCM_CORE.CCM_ROLES; + + alter table CCM_CORE.TASK_ASSIGNMENTS + add constraint FK_fu6ukne6hj8ihlfxtmp17xpfj + foreign key (TASK_ID) + references CCM_CORE.WORKFLOW_USER_TASKS; + alter table CCM_CORE.THREADS add constraint FK_oopqroe5a8fg932teo0cyifcv foreign key (ROOT_ID) @@ -1005,24 +1115,4 @@ CREATE SCHEMA ccm_core; foreign key (WORKFLOW_ID) references CCM_CORE.WORKFLOWS; - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint FK_q9evs4qcfhr79fha7xgk057wo - foreign key (ASSIGNED_GROUP_ID) - references CCM_CORE.GROUPS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_GROUPS - add constraint FK_lqtfvnswn0k8kjghoi4jk3qfe - foreign key (USER_TASK_ID) - references CCM_CORE.WORKFLOW_USER_TASKS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint FK_bb9rm595xsbrpyx95lmwnlg76 - foreign key (ASSIGNED_USER_ID) - references CCM_CORE.USERS; - - alter table CCM_CORE.WORKFLOW_USER_TASK_ASSIGNED_USERS - add constraint FK_7qgn3rbw4wgpd77hhqogfh53x - foreign key (USER_TASK_ID) - references CCM_CORE.WORKFLOW_USER_TASKS; - create sequence hibernate_sequence start 1 increment 1; \ No newline at end of file diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml new file mode 100644 index 000000000..0f1b30f33 --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml @@ -0,0 +1,67 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10000 + category_id: -2100 + object_id: -3100 + object_order: 1 + category_order: 1 + category_index: false + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false + - categorization_id: -10200 + object_id: -3200 + category_id: -2100 + category_order: 1 + object_order: 2 + category_index: false \ No newline at end of file diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-subcategory.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-subcategory.yml new file mode 100644 index 000000000..ab90c4bcf --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-add-subcategory.yml @@ -0,0 +1,71 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + - object_id: -2300 + display_name: category-new + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2300 + unique_id: catnew + name: category-new + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 1 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10000 + category_id: -2100 + object_id: -3100 + object_order: 1 + category_order: 1 + category_index: false + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false \ No newline at end of file diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-obj-from-category.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-obj-from-category.yml new file mode 100644 index 000000000..662c98cef --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-obj-from-category.yml @@ -0,0 +1,55 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-subcategory.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-subcategory.yml new file mode 100644 index 000000000..3402359ae --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/after-remove-subcategory.yml @@ -0,0 +1,60 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10000 + category_id: -2100 + object_id: -3100 + object_order: 1 + category_order: 1 + category_index: false + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data.yml new file mode 100644 index 000000000..80a4ba1cd --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data.yml @@ -0,0 +1,61 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10000 + category_id: -2100 + object_id: -3100 + object_order: 1 + category_order: 1 + category_index: false + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false \ No newline at end of file diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data2.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data2.yml new file mode 100644 index 000000000..52fc228cd --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryManagerTest/data2.yml @@ -0,0 +1,71 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -3100 + display_name: object1 + - object_id: -3200 + display_name: object2 + - object_id: -3300 + display_name: object3 + - object_id: -2300 + display_name: category-new + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2300 + unique_id: catnew + name: category-new + enabled: true + visible: true + abstract_category: false + category_order: 1 + + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + +ccm_core.categorizations: + - categorization_id: -10000 + category_id: -2100 + object_id: -3100 + object_order: 1 + category_order: 1 + category_index: false + - categorization_id: -10100 + category_id: -2200 + object_id: -3300 + category_order: 1 + object_order: 1 + category_index: false diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/after-save-new-category.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/after-save-new-category.yml new file mode 100644 index 000000000..14750c723 --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/after-save-new-category.yml @@ -0,0 +1,52 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + - object_id: -2300 + display_name: new-category + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2300 + unique_id: new0001 + name: new-category + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + + diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml new file mode 100644 index 000000000..30c247ee8 --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/CategoryRepositoryTest/data.yml @@ -0,0 +1,42 @@ +ccm_core.ccm_objects: + - object_id: -1000 + display_name: test + - object_id: -2000 + display_name: test_root + - object_id: -2100 + display_name: foo + - object_id: -2200 + display_name: bar + +ccm_core.categories: + - object_id: -2000 + unique_id: test0001 + name: test-root + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2100 + unique_id: test0002 + name: foo + parent_category_id: -2000 + enabled: true + visible: true + abstract_category: false + category_order: 0 + - object_id: -2200 + unique_id: test0003 + name: bar + parent_category_id: -2100 + enabled: true + visible: true + abstract_category: false + category_order: 0 + +ccm_core.category_domains: + - object_id: -1000 + domain_key: test + root_category_id: -2000 + uri: http://libreccm.org/test + version: 1.0 + diff --git a/ccm-core/src/test/resources/scripts/h2-cleanup.sql b/ccm-core/src/test/resources/scripts/h2-cleanup.sql index e5c3503e2..127e9cae4 100644 --- a/ccm-core/src/test/resources/scripts/h2-cleanup.sql +++ b/ccm-core/src/test/resources/scripts/h2-cleanup.sql @@ -1,3 +1,9 @@ +DELETE FROM ccm_core.categorizations; + +DELETE FROM ccm_core.category_domains; + +DELETE FROM ccm_core.categories; + DELETE FROM ccm_core.permissions; DELETE FROM ccm_core.ccm_objects; diff --git a/ccm-core/src/test/resources/scripts/pgsql-cleanup.sql b/ccm-core/src/test/resources/scripts/pgsql-cleanup.sql index 66da066ef..c3898d65e 100644 --- a/ccm-core/src/test/resources/scripts/pgsql-cleanup.sql +++ b/ccm-core/src/test/resources/scripts/pgsql-cleanup.sql @@ -1,9 +1,23 @@ -DELETE FROM ccm_core.permissions; - -DELETE FROM ccm_core.ccm_privileges; - -DELETE FROM ccm_core.ccm_objects; - -DELETE FROM ccm_core.user_email_addresses; - -DELETE FROM ccm_core.parties; \ No newline at end of file +-- DELETE FROM ccm_core.categorizations; +-- +-- DELETE FROM ccm_core.category_domains; +-- +-- DELETE FROM ccm_core.categories; +-- +-- DELETE FROM ccm_core.permissions; +-- +-- DELETE FROM ccm_core.ccm_objects; +-- +-- DELETE FROM ccm_core.role_memberships; +-- +-- DELETE FROM ccm_core.group_memberships; +-- +-- DELETE FROM ccm_core.groups; +-- +-- DELETE FROM ccm_core.users; +-- +-- DELETE FROM ccm_core.user_email_addresses; +-- +-- DELETE FROM ccm_core.parties; +-- +-- DELETE FROM ccm_core.ccm_roles; \ No newline at end of file