Ejemplo n.º 1
0
  public SaikuFilter getFilter(
      String queryName,
      String filtername,
      String dimensionName,
      String hierarchyName,
      String levelName) {
    IQuery query = getIQuery(queryName);
    CellSet cs = query.getCellset();
    List<SimpleCubeElement> members = new ArrayList<SimpleCubeElement>();
    SimpleCubeElement dimension = null;
    SimpleCubeElement hierarchy = null;
    Set<MetadataElement> mset = new HashSet<MetadataElement>();

    if (cs != null) {
      List<CellSetAxis> axes = new ArrayList<CellSetAxis>();
      axes.addAll(cs.getAxes());
      axes.add(cs.getFilterAxis());
      for (CellSetAxis axis : axes) {
        int posIndex = 0;
        for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) {
          if (h.getName().equals(hierarchyName)) {
            if (hierarchy == null) {
              hierarchy = new SimpleCubeElement(h.getName(), h.getUniqueName(), h.getCaption());
              Dimension d = h.getDimension();
              dimension = new SimpleCubeElement(d.getName(), d.getUniqueName(), d.getCaption());
            }
            if (h.getLevels().size() == 1) {
              break;
            }

            for (Position pos : axis.getPositions()) {
              Member m = pos.getMembers().get(posIndex);
              if (m.getLevel().getName().equals(levelName)) {
                mset.add(m);
              }
            }
            break;
          }
          posIndex++;
        }
      }
      if (mset.size() == 0) {
        QueryDimension qd = query.getDimension(dimensionName);
        if (qd != null && qd.getAxis().getLocation() != null) {
          for (Selection sel : qd.getInclusions()) {
            if ((sel.getRootElement() instanceof Member)) {
              Member m = ((Member) sel.getRootElement());
              if (m.getLevel().getName().equals(levelName)) {
                mset.add(m);
              }
            }
          }
        }
      }
      members = ObjectUtil.convert2Simple(mset);
      Collections.sort(members, new SaikuUniqueNameComparator());
      log.debug("Create Filters: Found members in the result or query: " + members.size());
    }
    return new SaikuFilter(filtername, null, dimension, hierarchy, members);
  }
Ejemplo n.º 2
0
  /**
   * @param hierarchy
   * @return
   */
  protected UIComponent createFilterItem(Hierarchy hierarchy) {
    String id = "filter-item-" + hierarchy.getUniqueName().hashCode();

    HtmlPanelGroup panel = new HtmlPanelGroup();
    panel.setId(id);
    panel.setLayout("block");
    panel.setStyleClass("ui-widget-header filter-item");

    CommandLink link = new CommandLink();
    link.setId(id + "-link");
    link.setValue(hierarchy.getCaption());
    link.setTitle(hierarchy.getUniqueName());

    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory factory = context.getApplication().getExpressionFactory();

    link.setActionExpression(
        factory.createMethodExpression(
            context.getELContext(), "#{filterHandler.show}", Void.class, new Class<?>[0]));
    link.setUpdate(":filter-form");
    link.setOncomplete("PF('filterDialog').show();");

    UIParameter parameter = new UIParameter();
    parameter.setName("hierarchy");
    parameter.setValue(hierarchy.getName());

    link.getChildren().add(parameter);

    panel.getChildren().add(link);

    CommandButton closeButton = new CommandButton();
    closeButton.setId(id + "-button");
    closeButton.setIcon("ui-icon-close");
    closeButton.setActionExpression(
        factory.createMethodExpression(
            context.getELContext(),
            "#{filterHandler.removeHierarchy}",
            Void.class,
            new Class<?>[0]));
    closeButton.setUpdate(
        ":filter-items-form,:source-tree-form,:grid-form,:editor-form:mdx-editor,:editor-form:editor-toolbar");
    closeButton.setOncomplete("onViewChanged()");

    UIParameter parameter2 = new UIParameter();
    parameter2.setName("hierarchy");
    parameter2.setValue(hierarchy.getName());

    closeButton.getChildren().add(parameter2);

    panel.getChildren().add(closeButton);

    return panel;
  }
Ejemplo n.º 3
0
  public List<SaikuMember> getAllMembers(
      SaikuCube cube, String dimension, String hierarchy, String level) throws SaikuOlapException {
    try {
      Cube nativeCube = getNativeCube(cube);
      Dimension dim = nativeCube.getDimensions().get(dimension);
      if (dim != null) {
        Hierarchy h = dim.getHierarchies().get(hierarchy);
        if (h == null) {
          for (Hierarchy hlist : dim.getHierarchies()) {
            if (hlist.getUniqueName().equals(hierarchy) || hlist.getName().equals(hierarchy)) {
              h = hlist;
            }
          }
        }

        if (h != null) {
          Level l = h.getLevels().get(level);
          if (l == null) {
            for (Level lvl : h.getLevels()) {
              if (lvl.getUniqueName().equals(level) || lvl.getName().equals(level)) {
                return (ObjectUtil.convertMembers(lvl.getMembers()));
              }
            }
          } else {
            return (ObjectUtil.convertMembers(l.getMembers()));
          }
        }
      }
    } catch (OlapException e) {
      throw new SaikuOlapException("Cannot get all members", e);
    }

    return new ArrayList<SaikuMember>();
  }
Ejemplo n.º 4
0
  /** @param e */
  public void onDrop(DragDropEvent e) {
    List<Integer> sourcePath = getNodePath(e.getDragId());

    Hierarchy hierarchy = null;

    if (isSourceNode(e.getDragId())) {
      TreeNode sourceNode = findNodeFromPath(navigator.getCubeNode(), sourcePath);

      if (sourceNode instanceof HierarchyNode) {
        HierarchyNode node = (HierarchyNode) sourceNode;
        hierarchy = node.getObject();
      } else if (sourceNode instanceof LevelNode) {
        LevelNode node = (LevelNode) sourceNode;
        Level level = node.getObject();

        hierarchy = level.getHierarchy();
      }

      if (hierarchy == null) {
        return;
      }

      if (navigator.isSelected(hierarchy)) {
        FacesContext context = FacesContext.getCurrentInstance();

        ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");

        String title = bundle.getString("error.filter.title");
        String message = bundle.getString("error.filter.message");

        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, title, message));
        return;
      }

      UIComponent panel = createFilterItem(hierarchy);
      filterPanel.getChildren().add(panel);

      show(hierarchy.getName());

      RequestContext.getCurrentInstance().execute("PF('filterDialog').show();");
    }
  }
Ejemplo n.º 5
0
  public List<SaikuLevel> getAllLevels(SaikuCube cube, String dimension, String hierarchy)
      throws SaikuOlapException {
    Cube nativeCube = getNativeCube(cube);
    Dimension dim = nativeCube.getDimensions().get(dimension);
    if (dim != null) {
      Hierarchy h = dim.getHierarchies().get(hierarchy);
      if (h == null) {
        for (Hierarchy hlist : dim.getHierarchies()) {
          if (hlist.getUniqueName().equals(hierarchy) || hlist.getName().equals(hierarchy)) {
            h = hlist;
          }
        }
      }

      if (h != null) {
        List<SaikuLevel> levels = (ObjectUtil.convertLevels(h.getLevels()));
        return levels;
      }
    }
    return new ArrayList<SaikuLevel>();
  }
Ejemplo n.º 6
0
  public List<SaikuMember> getHierarchyRootMembers(SaikuCube cube, String hierarchyName)
      throws SaikuOlapException {
    Cube nativeCube = getNativeCube(cube);
    List<SaikuMember> members = new ArrayList<SaikuMember>();
    Hierarchy h = nativeCube.getHierarchies().get(hierarchyName);

    if (h == null) {
      for (Hierarchy hlist : nativeCube.getHierarchies()) {
        if (hlist.getUniqueName().equals(hierarchyName) || hlist.getName().equals(hierarchyName)) {
          h = hlist;
        }
      }
    }
    if (h != null) {
      try {
        members = (ObjectUtil.convertMembers(h.getRootMembers()));
      } catch (OlapException e) {
        throw new SaikuOlapException(
            "Cannot retrieve root members of hierarchy: " + hierarchyName, e);
      }
    }

    return members;
  }