Adds AddUseContextForm
A lot is still commented and needs confirmation git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4401 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
c0af067da9
commit
4aff7be1c7
|
|
@ -29,15 +29,20 @@ import com.arsdigita.bebop.parameters.ParameterData;
|
|||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.BaseForm;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
|
||||
/**
|
||||
* TODO Needs a description.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author Scott Seago
|
||||
* @version $Id: AddUseContextForm.java 2090 2010-04-17 08:04:14Z pboy $
|
||||
*/
|
||||
|
|
@ -95,12 +100,15 @@ class AddUseContextForm extends BaseForm {
|
|||
final PageState state = e.getPageState();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
|
||||
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
|
||||
|
||||
final String useContext = (String) m_useContext.getValue(state);
|
||||
|
||||
final String rootName = (String) m_rootName.getValue(state);
|
||||
final LocalizedString rootDescription = new LocalizedString();
|
||||
rootDescription.addValue(null, (String) m_rootDescription.getValue(state));
|
||||
rootDescription.addValue(config.getDefaultLocale(), (String) m_rootDescription.getValue(state));
|
||||
|
||||
Category root = new Category();
|
||||
root.setName(rootName);
|
||||
root.setDescription(rootDescription);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.category;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.dispatcher.AccessDeniedException;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.util.Assert;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
/**
|
||||
* TODO Needs a description.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @version $Id: CategoryAddForm.java 2090 2010-04-17 08:04:14Z pboy $
|
||||
*/
|
||||
final class CategoryAddForm extends BaseCategoryForm {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger
|
||||
(CategoryAddForm.class);
|
||||
|
||||
private final SingleSelectionModel m_model;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CategoryAddForm(final CategoryRequestLocal parent,
|
||||
final SingleSelectionModel model) {
|
||||
super("AddSubcategories", gz("cms.ui.category.add"), parent);
|
||||
|
||||
m_model = model;
|
||||
|
||||
//m_name.addValidationListener(new NameUniqueListener(null, m_name, NameUniqueListener.NAME_FIELD));
|
||||
//m_url.addValidationListener(new NameUniqueListener(null, m_url, NameUniqueListener.URL_FIELD));
|
||||
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
private final class ProcessListener implements FormProcessListener {
|
||||
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
s_log.debug("Adding a category");
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
||||
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
|
||||
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
|
||||
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
final Category parent = m_parent.getCategory(state);
|
||||
final String name = (String) m_name.getValue(state);
|
||||
final String description = (String) m_description.getValue(state);
|
||||
final String url = (String) m_url.getValue(state);
|
||||
final String isAbstract = (String) m_isAbstract.getValue(state);
|
||||
|
||||
Assert.exists(parent, "Category parent");
|
||||
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Using parent category " + parent + " to " +
|
||||
"create new category");
|
||||
}
|
||||
|
||||
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) {
|
||||
final Category category = new Category();
|
||||
category.setName(name);
|
||||
final LocalizedString localizedDescription = new LocalizedString();
|
||||
localizedDescription.addValue(config.getDefaultLocale(), description);
|
||||
category.setDescription(localizedDescription);
|
||||
// this seems anti-intuitive but the question is "can you place
|
||||
// items in this category. If the user says "yes" then the
|
||||
// category is not abstract
|
||||
if ("yes".equals(isAbstract)) {
|
||||
category.setAbstractCategory(false);
|
||||
} else if ("no".equals(isAbstract)) {
|
||||
category.setAbstractCategory(true);
|
||||
}
|
||||
|
||||
//category.save(); // XXX this is necessary?
|
||||
categoryRepository.save(category);
|
||||
|
||||
//parent.addChild(category);
|
||||
//parent.save();
|
||||
categoryManager.addSubCategoryToCategory(category, parent);
|
||||
|
||||
//category.setDefaultParentCategory(parent);
|
||||
//category.save(k);
|
||||
|
||||
|
||||
m_model.setSelectedKey(state, category.getUniqueId());
|
||||
} else {
|
||||
// XXX user a better exception here.
|
||||
// PermissionException doesn't work for this case.
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue