From af6bee2cdc594fa5b0adf36e8979e23b4d71c512 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Mon, 21 Mar 2022 19:47:21 +0100 Subject: [PATCH] Removed depcrecated package com.arsdigita.categorization from ccm-cms --- .../ui/ACSObjectCategoryController.java | 128 -------- .../ui/ACSObjectCategoryForm.java | 206 ------------- .../ui/ACSObjectCategorySummary.java | 274 ------------------ 3 files changed, 608 deletions(-) delete mode 100644 ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryController.java delete mode 100755 ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryForm.java delete mode 100755 ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategorySummary.java diff --git a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryController.java b/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryController.java deleted file mode 100644 index 93de15253..000000000 --- a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryController.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2017 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 com.arsdigita.categorization.ui; - -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.categorization.ObjectNotAssignedToCategoryException; -import org.libreccm.core.CcmObject; -import org.libreccm.core.CcmObjectRepository; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class ACSObjectCategoryController { - - @Inject - private CategoryRepository categoryRepo; - - @Inject - private CategoryManager categoryManager; - - @Inject - private CcmObjectRepository ccmObjectRepo; - - @Transactional(Transactional.TxType.REQUIRED) - protected List getCategoriesForObject(final CcmObject object) { - - Objects.requireNonNull(object); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database", - object.getObjectId()))); - - return ccmObject - .getCategories() - .stream() - .map(categorization -> categorization.getCategory()) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void addObjectToCategory(final CcmObject object, - final Category category) { - - Objects.requireNonNull(object); - Objects.requireNonNull(category); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database", - object.getObjectId()))); - - final Category cat = categoryRepo - .findById(category.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - category.getObjectId()))); - - categoryManager.addObjectToCategory(ccmObject, cat); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void removeObjectFromCategory(final CcmObject object, - final Category category) - throws ObjectNotAssignedToCategoryException { - - Objects.requireNonNull(object); - Objects.requireNonNull(category); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database", - object.getObjectId()))); - - final Category cat = categoryRepo - .findById(category.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - category.getObjectId()))); - - categoryManager.removeObjectFromCategory(ccmObject, cat); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected long getParentCategoryId(final Category forCategory) { - - final Category category = categoryRepo - .findById(forCategory.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - forCategory.getObjectId()))); - - return category.getParentCategory().getObjectId(); - } - -} diff --git a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryForm.java b/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryForm.java deleted file mode 100755 index 3827f3dd6..000000000 --- a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategoryForm.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2004 Chris Gilbert - * - * 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.categorization.ui; - -import java.util.ArrayList; -import java.util.List; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.form.Widget; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.util.GlobalizationUtil; - -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.categorization.ObjectNotAssignedToCategoryException; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.CcmObject; -import org.libreccm.core.UnexpectedErrorException; - -import java.math.BigDecimal; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Abstract form for assigning categories to acs_objects. The assigned - * categories are those specified by the category widget, which is retrieved by - * the concrete subclass' implementation of getCategoryWidget. - * - * The category widget may be an implementation of CategoryWidget, which - * generates a javascript tree of categories. Implementations need only specify - * an XML prefix and namespace. - * - * The object that is to be assigned to the categories is specified by the - * concrete subclass' implentation of getObject - * - * @author chris.gilbert@westsussex.gov.uk - * - * - */ -// this class has been abstracted out from the original cms specific -// category form in ccm-cms -public abstract class ACSObjectCategoryForm extends Form { - - private final Widget categoryWidget; - private final SaveCancelSection saveCancelSection; - - protected abstract CcmObject getObject(PageState state); - - public ACSObjectCategoryForm(final LongParameter root, - final StringParameter mode, - final Widget categoryWidget) { - super("category", new BoxPanel(BoxPanel.VERTICAL)); - - this.categoryWidget = categoryWidget; - categoryWidget.addValidationListener(new NotNullValidationListener()); - saveCancelSection = new SaveCancelSection(); - - super.add(categoryWidget); - super.add(saveCancelSection); - - super.addInitListener(new FormInitListener() { - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final CcmObject object = getObject(state); - - final List selectedCats = new ArrayList<>(); - final Set ancestorCats = new HashSet<>(); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ACSObjectCategoryController controller = cdiUtil - .findBean(ACSObjectCategoryController.class); - final List categories = controller - .getCategoriesForObject(object); - for (final Category category : categories) { - selectedCats.add(category.getObjectId()); - addAncestorCats(ancestorCats, category); - } - - final Long[][] paramArray = new Long[2][]; - paramArray[0] = selectedCats - .toArray(new Long[selectedCats.size()]); - paramArray[1] = ancestorCats - .toArray(new Long[ancestorCats.size()]); - - categoryWidget.setValue(state, paramArray); - } - - }); - - super.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final CcmObject object = getObject(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ACSObjectCategoryController controller = cdiUtil - .findBean(ACSObjectCategoryController.class); - - final Set curSelectedCat = controller - .getCategoriesForObject(object) - .stream() - .map(category -> category.getObjectId()) - .collect(Collectors.toSet()); - - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - final CategoryManager categoryManager = cdiUtil - .findBean(CategoryManager.class); - final List ids = new ArrayList<>(); - for (final BigDecimal value : (BigDecimal[]) categoryWidget - .getValue(state)) { - - ids.add(value.longValue()); - - } - for (final Long id : ids) { - final Category cat = categoryRepo - .findById(id) - .orElseThrow(() -> new IllegalArgumentException( - String.format("No Category with ID %d in the database. " - + "Where did that ID come from?", - id))); - if (!curSelectedCat.contains(id)) { - controller.addObjectToCategory(object, cat); - } else { - try { - controller.removeObjectFromCategory(object, cat); - } catch (ObjectNotAssignedToCategoryException ex) { - throw new UnexpectedErrorException(ex); - } - } - } - - fireCompletionEvent(state); - } - - }); - super.addSubmissionListener(new FormSubmissionListener() { - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getCancelButton().isSelected(state)) { - fireCompletionEvent(state); - throw new FormProcessException("Submission cancelled", - GlobalizationUtil.globalize( - "categorization.cancel.msg")); - } - } - - }); - } - - private void addAncestorCats(final Set ancestorCats, - final Category category) { - - if (category.getParentCategory() != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ACSObjectCategoryController controller = cdiUtil - .findBean(ACSObjectCategoryController.class); - ancestorCats - .add(controller.getParentCategoryId(category)); - } - - } - -} diff --git a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategorySummary.java b/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategorySummary.java deleted file mode 100755 index c6f4ed84c..000000000 --- a/ccm-core/src/main/java/com/arsdigita/categorization/ui/ACSObjectCategorySummary.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2007 Chris Gilbert - * - * 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.categorization.ui; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.ServletException; - -import org.apache.logging.log4j.Logger; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleComponent; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.core.CcmObject; -import org.libreccm.categorization.Category; - -import com.arsdigita.util.Assert; -import com.arsdigita.web.RedirectSignal; -import com.arsdigita.xml.Element; -import com.arsdigita.xml.XML; - -import org.apache.logging.log4j.LogManager; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.categorization.ObjectNotAssignedToCategoryException; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; - -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * abstract class for displaying the categories assigned to an object under one - * or more root nodes. Subclasses should retrieve the object to be assigned and - * supply the logic to retrieve root categories. - * - * * abstracted from ItemCategorySummary in ccm-cms - * - * @author chris.gilbert@westsussex.gov.uk - * @author Jens Pelzetter - * - * - * - */ -public abstract class ACSObjectCategorySummary extends SimpleComponent { - - private static final Logger LOGGER = LogManager - .getLogger(ACSObjectCategorySummary.class); - - public static final String ACTION_DELETE = "delete"; - public static final String ACTION_ADD = "add"; - public static final String ACTION_ADD_JS = "addJS"; - - private final Map listenersLap = new HashMap<>(); - - public ACSObjectCategorySummary() { - registerAction(ACTION_DELETE, - new DeleteActionListener()); - } - - public void registerAction(final String name, - final ActionListener listener) { - listenersLap.put(name, listener); - } - - @Override - public void respond(final PageState state) throws ServletException { - - super.respond(state); - - Assert.isTrue(canEdit(state), "User can edit object"); - - final String name = state.getControlEventName(); - final ActionListener listener = listenersLap.get(name); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Got event {} listener {}", - name, - listener); - } - - if (listener != null) { - listener.actionPerformed(new ActionEvent(this, state)); - } - } - - /** - * default behaviour is to check for edit access on the current resource. as - * defined by getCategorizedObject. This can be overridden by subclasses, if - * for instance a specific privilege should be checked - * - * @param state - * - * @return - */ - protected abstract boolean canEdit(final PageState state); - - protected abstract CcmObject getObject(PageState state); - - protected abstract String getXMLPrefix(); - - protected abstract String getXMLNameSpace(); - - protected abstract List getRootCategories(PageState state); - - @Override - public void generateXML(final PageState state, final Element parent) { - - final boolean canEdit = canEdit(state); - - final Element content = parent - .newChildElement(String.format("%s:categoryStepSummary", - getXMLPrefix()), - getXMLNameSpace()); - exportAttributes(content); - - final Element rootCats = content - .newChildElement(String.format("%s:categoryRoots", - getXMLPrefix()), - getXMLNameSpace()); - - final List roots = getRootCategories(state); - for (final Category rootCategory : roots) { - - final Element root = rootCats - .newChildElement(String.format("%s:categoryRoot", - getXMLPrefix()), - getXMLNameSpace()); - root.addAttribute("name", rootCategory.getName()); - root.addAttribute("description", - rootCategory - .getDescription() - .getValue(KernelConfig - .getConfig() - .getDefaultLocale())); - - if (canEdit) { - state.setControlEvent(this, - ACTION_ADD, - Long.toString(rootCategory.getObjectId())); - try { - root.addAttribute("addAction", - XML.format(state.stateAsURL())); - } catch (IOException ex) { - throw new UnexpectedErrorException("cannot generate URL", - ex); - } - state.clearControlEvent(); - state.setControlEvent(this, - ACTION_ADD_JS, - Long.toString(rootCategory.getObjectId())); - try { - root.addAttribute("addJSAction", - XML.format(state.stateAsURL())); - } catch (IOException ex) { - throw new UnexpectedErrorException("cannot generate URL", - ex); - } - state.clearControlEvent(); - } - } - - final Element itemCats = content - .newChildElement(String.format("%s:itemCategories", - getXMLPrefix()), - getXMLNameSpace()); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ACSObjectCategoryController controller = cdiUtil - .findBean(ACSObjectCategoryController.class); - final List categories = controller - .getCategoriesForObject(getObject(state)); - - final CategoryManager categoryManager = cdiUtil - .findBean(CategoryManager.class); - - for (final Category category : categories) { - - final String path = categoryManager.getCategoryPath(category); - - final Element categoryElem = itemCats - .newChildElement(String.format("%s:itemCategory", - getXMLPrefix()), - getXMLNameSpace()); - categoryElem.addAttribute("name", category.getName()); - categoryElem.addAttribute("description", - category - .getDescription() - .getValue(KernelConfig - .getConfig() - .getDefaultLocale())); - categoryElem.addAttribute("path", XML.format(path)); - - if (canEdit) { - state.setControlEvent(this, - ACTION_DELETE, - Long.toString(category.getObjectId())); - try { - categoryElem.addAttribute("deleteAction", - XML.format(state.stateAsURL())); - } catch (IOException ex) { - throw new UnexpectedErrorException("cannot generate URL", - ex); - } - state.clearControlEvent(); - } - } - - } - - private class DeleteActionListener implements ActionListener { - - @Override - public void actionPerformed(final ActionEvent event) { - - final PageState state = event.getPageState(); - final String value = state.getControlEventValue(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - final Category category = categoryRepo - .findById(Long.parseLong(value)) - .orElseThrow(() -> new IllegalArgumentException( - String.format( - "No Category with ID %s in the database. " - + "Where did that ID come from?", - value))); - - final CcmObject object = getObject(state); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Removing category {} from {}", - Objects.toString(category), - Objects.toString(object)); - } - - final CategoryManager categoryManager = cdiUtil - .findBean(CategoryManager.class); - try { - categoryManager.removeObjectFromCategory(object, category); - } catch (ObjectNotAssignedToCategoryException ex) { - throw new UnexpectedErrorException(ex); - } - - state.clearControlEvent(); - throw new RedirectSignal(state.toURL(), true); - } - - } - -}