CCM NG: Item Category Step basically works now
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5000 8810af33-2d31-482b-a856-94f89814c4df
parent
cbd68a8fdf
commit
582b180d94
|
|
@ -124,56 +124,55 @@ public class ItemCategoryStep extends SimpleContainer implements Resettable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void register(Page p
|
||||
) {
|
||||
super.register(p);
|
||||
public void register(final Page page) {
|
||||
super.register(page);
|
||||
|
||||
p.setVisibleDefault(addComponent, false);
|
||||
// for (int i=0;i<extensionsCount;i++) {
|
||||
// p.setVisibleDefault(extensionForms[i], false);
|
||||
// }
|
||||
p.addGlobalStateParam(rootParameter);
|
||||
p.addGlobalStateParam(modeParameter);
|
||||
page.setVisibleDefault(addComponent, false);
|
||||
for (int i = 0; i < extensionsCount; i++) {
|
||||
page.setVisibleDefault(extensionForms[i], false);
|
||||
}
|
||||
page.addGlobalStateParam(rootParameter);
|
||||
page.addGlobalStateParam(modeParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(PageState state
|
||||
) {
|
||||
public void reset(final PageState state) {
|
||||
state.setValue(rootParameter, null);
|
||||
state.setValue(modeParameter, null);
|
||||
|
||||
itemCategorySummary.setVisible(state, true);
|
||||
addComponent.setVisible(state, false);
|
||||
// for (int i=0;i<extensionsCount;i++) {
|
||||
// extensionSummaries[i].setVisible(state, true);
|
||||
// extensionForms[i].setVisible(state, false);
|
||||
// }
|
||||
for (int i = 0; i < extensionsCount; i++) {
|
||||
extensionSummaries[i].setVisible(state, true);
|
||||
extensionForms[i].setVisible(state, false);
|
||||
}
|
||||
}
|
||||
|
||||
private class AddActionListener implements ActionListener {
|
||||
|
||||
private String m_mode;
|
||||
private final String mode;
|
||||
|
||||
public AddActionListener(String mode) {
|
||||
m_mode = mode;
|
||||
public AddActionListener(final String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState state = e.getPageState();
|
||||
public void actionPerformed(final ActionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
state.setValue(rootParameter,
|
||||
new BigDecimal(state.getControlEventValue()));
|
||||
|
||||
state.setValue(ItemCategoryStep.this.modeParameter,
|
||||
m_mode);
|
||||
mode);
|
||||
|
||||
itemCategorySummary.setVisible(state, false);
|
||||
addComponent.setVisible(state, true);
|
||||
// for (int i=0;i<extensionsCount;i++) {
|
||||
// extensionSummaries[i].setVisible(state, false);
|
||||
// extensionForms[i].setVisible(state, false);
|
||||
// }
|
||||
for (int i=0;i<extensionsCount;i++) {
|
||||
extensionSummaries[i].setVisible(state, false);
|
||||
extensionForms[i].setVisible(state, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -182,7 +181,7 @@ public class ItemCategoryStep extends SimpleContainer implements Resettable {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState state = e.getPageState();
|
||||
final PageState state = e.getPageState();
|
||||
reset(state);
|
||||
throw new RedirectSignal(state.toURL(), true);
|
||||
}
|
||||
|
|
@ -191,21 +190,22 @@ public class ItemCategoryStep extends SimpleContainer implements Resettable {
|
|||
|
||||
private class ExtensionListener implements ActionListener {
|
||||
|
||||
int extensionIndex;
|
||||
private final int extensionIndex;
|
||||
|
||||
public ExtensionListener(int i) {
|
||||
extensionIndex = i;
|
||||
public ExtensionListener(int extensionIndex) {
|
||||
this.extensionIndex = extensionIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState state = e.getPageState();
|
||||
public void actionPerformed(final ActionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
itemCategorySummary.setVisible(state, false);
|
||||
addComponent.setVisible(state, false);
|
||||
// for (int i=0;i<extensionsCount;i++) {
|
||||
// extensionSummaries[i].setVisible(state, false);
|
||||
// }
|
||||
// extensionForms[extensionIndex].setVisible(state, true);
|
||||
for (int i=0;i<extensionsCount;i++) {
|
||||
extensionSummaries[i].setVisible(state, false);
|
||||
}
|
||||
extensionForms[extensionIndex].setVisible(state, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import org.libreccm.categorization.DomainRepository;
|
|||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.CcmObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
|
@ -157,23 +158,26 @@ public abstract class ACSObjectCategoryPicker extends SimpleContainer {
|
|||
// }
|
||||
// }
|
||||
protected Domain getDomain(final PageState state) {
|
||||
|
||||
LOGGER.debug("Getting domain for {}", state.getValue(rootParam));
|
||||
|
||||
final Long domainId = (Long) state.getValue(rootParam);
|
||||
final Object value = state.getValue(rootParam);
|
||||
final Long domainId;
|
||||
if (value instanceof Long) {
|
||||
domainId = (Long) value;
|
||||
} else if (value instanceof BigDecimal) {
|
||||
domainId = ((Number) value).longValue();
|
||||
} else if (value instanceof String) {
|
||||
domainId = Long.parseLong((String) value);
|
||||
} else {
|
||||
domainId = Long.parseLong(value.toString());
|
||||
}
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final DomainRepository domainRepo = cdiUtil
|
||||
.findBean(DomainRepository.class);
|
||||
final CategoryPickerController controller = cdiUtil
|
||||
.findBean(CategoryPickerController.class);
|
||||
|
||||
final Optional<Domain> domain = domainRepo
|
||||
.findById(domainId);
|
||||
|
||||
if (domain.isPresent()) {
|
||||
return domain.get();
|
||||
} else {
|
||||
LOGGER.warn("No Domain for ID {} found.", domainId);
|
||||
return null;
|
||||
}
|
||||
return controller.findDomainByRootCategory(domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,9 +20,6 @@ package com.arsdigita.london.terms.ui;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Categorization;
|
||||
import org.libreccm.categorization.CategorizationConstants;
|
||||
import org.libreccm.categorization.CategorizationMarshaller;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
|
|
@ -40,6 +37,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -67,6 +69,25 @@ class CategoryPickerController {
|
|||
@Inject
|
||||
private DomainManager domainManager;
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Domain findDomainByRootCategory(final long rootCategoryId) {
|
||||
|
||||
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Domain> query = builder.createQuery(Domain.class);
|
||||
|
||||
final Root<Domain> from = query.from(Domain.class);
|
||||
final Join<Domain, Category> rootCatJoin = from.join("root");
|
||||
|
||||
query.where(builder.equal(rootCatJoin.get("objectId"), rootCategoryId));
|
||||
|
||||
return entityManager
|
||||
.createQuery(query)
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<Category> getCurrentCategories(final Domain domain,
|
||||
final CcmObject object) {
|
||||
|
|
@ -183,7 +204,10 @@ class CategoryPickerController {
|
|||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<Category> getRootCategories(final Domain domain) {
|
||||
|
||||
return getDomainModelCategory(domain).getSubCategories();
|
||||
return getDomainModelCategory(domain)
|
||||
.getSubCategories()
|
||||
.stream()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -37,8 +36,6 @@ import org.libreccm.categorization.Category;
|
|||
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.libreccm.categorization.Domain;
|
||||
|
||||
import com.arsdigita.xml.Element;
|
||||
|
|
@ -98,6 +95,7 @@ public class TermWidget extends Widget {
|
|||
|
||||
@Override
|
||||
protected void generateWidget(final PageState state, final Element parent) {
|
||||
|
||||
final Domain domain = picker.getDomain(state);
|
||||
|
||||
final Element widget = parent.newChildElement("cms:categoryWidget",
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package org.arsdigita.cms;
|
|||
|
||||
import com.arsdigita.bebop.form.DHTMLEditor;
|
||||
import com.arsdigita.cms.ui.authoring.ItemCategoryExtension;
|
||||
import com.arsdigita.cms.ui.authoring.ItemCategoryForm;
|
||||
import com.arsdigita.london.terms.ui.ItemCategoryPicker;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.Configuration;
|
||||
|
|
@ -372,7 +372,7 @@ public class CMSConfig {
|
|||
private int xmlCacheAge = 60 * 60 * 24;
|
||||
|
||||
@Setting
|
||||
private String categoryAuthoringAddForm = ItemCategoryForm.class.getName();
|
||||
private String categoryAuthoringAddForm = ItemCategoryPicker.class.getName();
|
||||
|
||||
@Setting
|
||||
private String categoryAuthoringExtension = ItemCategoryExtension.class
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
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;
|
||||
|
||||
|
|
@ -30,13 +33,18 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class ACSObjectCategoryController {
|
||||
class ACSObjectCategoryController {
|
||||
|
||||
@Inject
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
@Inject
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
@Inject
|
||||
private CcmObjectRepository ccmObjectRepo;
|
||||
|
|
@ -47,8 +55,8 @@ import javax.transaction.Transactional;
|
|||
Objects.requireNonNull(object);
|
||||
|
||||
final CcmObject ccmObject = ccmObjectRepo
|
||||
.findById(object.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.findById(object.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No CcmObject with ID %d in the database",
|
||||
object.getObjectId())));
|
||||
|
||||
|
|
@ -59,4 +67,49 @@ import javax.transaction.Transactional;
|
|||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ 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;
|
||||
|
|
@ -82,10 +83,10 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
categoryWidget.addValidationListener(new NotNullValidationListener());
|
||||
saveCancelSection = new SaveCancelSection();
|
||||
|
||||
add(categoryWidget);
|
||||
add(saveCancelSection);
|
||||
super.add(categoryWidget);
|
||||
super.add(saveCancelSection);
|
||||
|
||||
addInitListener(new FormInitListener() {
|
||||
super.addInitListener(new FormInitListener() {
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event)
|
||||
|
|
@ -96,11 +97,11 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
|
||||
final List<Long> selectedCats = new ArrayList<>();
|
||||
final Set<Long> ancestorCats = new HashSet<>();
|
||||
final List<Category> categories = object
|
||||
.getCategories()
|
||||
.stream()
|
||||
.map(categorization -> categorization.getCategory())
|
||||
.collect(Collectors.toList());
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ACSObjectCategoryController controller = cdiUtil
|
||||
.findBean(ACSObjectCategoryController.class);
|
||||
final List<Category> categories = controller
|
||||
.getCategoriesForObject(object);
|
||||
for (final Category category : categories) {
|
||||
selectedCats.add(category.getObjectId());
|
||||
addAncestorCats(ancestorCats, category);
|
||||
|
|
@ -117,7 +118,7 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
|
||||
});
|
||||
|
||||
addProcessListener(new FormProcessListener() {
|
||||
super.addProcessListener(new FormProcessListener() {
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
|
|
@ -127,19 +128,27 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
|
||||
final CcmObject object = getObject(state);
|
||||
|
||||
final Set<Long> curSelectedCat = object
|
||||
.getCategories()
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ACSObjectCategoryController controller = cdiUtil
|
||||
.findBean(ACSObjectCategoryController.class);
|
||||
|
||||
final Set<Long> curSelectedCat = controller
|
||||
.getCategoriesForObject(object)
|
||||
.stream()
|
||||
.map(categorization -> categorization.getCategory())
|
||||
.map(category -> category.getObjectId())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
final CategoryManager categoryManager = cdiUtil
|
||||
.findBean(CategoryManager.class);
|
||||
final Long[] ids = (Long[]) categoryWidget.getValue(state);
|
||||
final List<Long> 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)
|
||||
|
|
@ -148,11 +157,10 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
+ "Where did that ID come from?",
|
||||
id)));
|
||||
if (!curSelectedCat.contains(id)) {
|
||||
categoryManager.addObjectToCategory(object, cat);
|
||||
controller.addObjectToCategory(object, cat);
|
||||
} else {
|
||||
try {
|
||||
categoryManager
|
||||
.removeObjectFromCategory(object, cat);
|
||||
controller.removeObjectFromCategory(object, cat);
|
||||
} catch (ObjectNotAssignedToCategoryException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
|
@ -163,7 +171,7 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
}
|
||||
|
||||
});
|
||||
addSubmissionListener(new FormSubmissionListener() {
|
||||
super.addSubmissionListener(new FormSubmissionListener() {
|
||||
|
||||
@Override
|
||||
public void submitted(final FormSectionEvent event)
|
||||
|
|
@ -185,7 +193,9 @@ public abstract class ACSObjectCategoryForm extends Form {
|
|||
private void addAncestorCats(final Set<Long> ancestorCats,
|
||||
final Category category) {
|
||||
|
||||
ancestorCats.add(category.getParentCategory().getObjectId());
|
||||
if (category.getParentCategory() != null) {
|
||||
ancestorCats.add(category.getParentCategory().getObjectId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public abstract class ACSObjectCategorySummary extends SimpleComponent {
|
|||
ACTION_ADD_JS,
|
||||
Long.toString(rootCategory.getObjectId()));
|
||||
try {
|
||||
root.addAttribute("addJsAction",
|
||||
root.addAttribute("addJSAction",
|
||||
XML.format(state.stateAsURL()));
|
||||
} catch (IOException ex) {
|
||||
throw new UnexpectedErrorException("cannot generate URL",
|
||||
|
|
|
|||
Loading…
Reference in New Issue