Пример #1
0
/** @author Frank Febbraro ([email protected]) */
public class CategoryAction extends ModelAction {
  private static final Logger logger = Logger.getLogger(CategoryAction.class.getName());

  private static final long serialVersionUID = 1L;

  public static final String MAIN = "main";

  private CategoryController controller = CategoryController.getController();
  private ContentCategoryController contentCategoryController =
      ContentCategoryController.getController();
  private boolean forceDelete = false;

  protected Persistent createModel() {
    return new CategoryVO();
  }

  public CategoryVO getCategory() {
    return (CategoryVO) getModel();
  }

  public Integer getCategoryId() {
    return getCategory().getCategoryId();
  }

  public void setCategoryId(Integer i) {
    getCategory().setCategoryId(i);
  }

  public List getReferences() throws Exception {
    return contentCategoryController.findByCategory(getCategoryId());
  }

  public String doList() throws SystemException {
    setModels(controller.findRootCategories());
    return SUCCESS;
  }

  public String doNew() throws SystemException {
    return SUCCESS;
  }

  public String doEdit() throws SystemException {
    setModel(controller.findWithChildren(getCategoryId()));
    return SUCCESS;
  }

  public String doDisplayTreeForMove() throws SystemException {
    return SUCCESS;
  }

  public String doMove() throws SystemException {
    setModel(controller.moveCategory(getCategoryId(), getCategory().getParentId()));
    return SUCCESS;
  }

  public String doSave() throws SystemException, ConstraintException {
    validateModel();
    setModel(controller.save(getCategory()));
    return (getCategory().isRoot()) ? MAIN : SUCCESS;
  }

  public String doDelete() throws Exception {
    List references = new ArrayList();
    try {
      references = getReferences();
    } catch (Exception e) {
      logger.error("Error getting references:" + e.getMessage());
    }

    if (references.size() > 0 && !forceDelete)
      throw new ConstraintException("Category.name", "3608");

    // So we have the parent and know which page to go to
    setModel(controller.findById(getCategoryId()));
    controller.delete(getCategoryId());

    return (getCategory().getParentId() == null) ? MAIN : SUCCESS;
  }

  // Needed as part of WebworklAbstractAction
  public String doExecute() throws Exception {
    return SUCCESS;
  }

  public void setForceDelete(boolean forceDelete) {
    this.forceDelete = forceDelete;
  }
}
Пример #2
0
/** @author Frank Febbraro ([email protected]) */
public class CategoryNodeSupplier extends BaseNodeSupplier {
  private static final Logger logger = Logger.getLogger(CategoryNodeSupplier.class.getName());

  public static final Integer ROOT = new Integer(-1);

  private CategoryController controller = CategoryController.getController();

  private ArrayList cacheLeafs;

  public CategoryNodeSupplier() {
    BaseNode rootNode = new ContentNodeImpl();
    rootNode.setChildren(true);
    rootNode.setId(ROOT); // There is no BASE category so make it up
    rootNode.setTitle("Categories");
    rootNode.setContainer(true);
    setRootNode(rootNode);
  }

  public boolean hasChildren() {
    return true;
  }

  public Collection getChildContainerNodes(Integer parentNode) {
    ArrayList ret = new ArrayList();
    cacheLeafs = new ArrayList();

    List children = null;
    try {
      children =
          (ROOT.equals(parentNode))
              ? controller.findRootCategories()
              : controller.findActiveByParent(parentNode);
    } catch (SystemException e) {
      logger.warn("Error getting Category Children", e);
    }

    for (Iterator i = children.iterator(); i.hasNext(); ) {
      CategoryVO vo = (CategoryVO) i.next();

      List grandkids = getGrandKids(vo.getId());

      BaseNode node = new CategoryNodeImpl();
      node.setId(vo.getId());
      node.setTitle(vo.getName());
      node.setContainer(true);
      node.setChildren(!grandkids.isEmpty());
      ret.add(node);
    }

    return ret;
  }

  private List getGrandKids(Integer childId) {
    try {
      return controller.findActiveByParent(childId);
    } catch (SystemException e) {
      return Collections.EMPTY_LIST;
    }
  }

  /** @see com.frovi.ss.Tree.INodeSupplier#getChildLeafNodes(Integer) */
  public Collection getChildLeafNodes(Integer parentNode) {
    return Collections.EMPTY_LIST;
  }
}