private static String getParameterValue(
     TargetParameter parameter, WhatIfEngineInstance ei, SpagoBICellWrapper cell) {
   if (parameter.isAbsolute()) {
     return parameter.getValue();
   }
   String value = null;
   String dimensionName = parameter.getDimension();
   String hierarchyName = parameter.getHierarchy();
   String levelName = parameter.getLevel();
   String propertyName = parameter.getProperty();
   logger.debug(
       "Looking for dimension "
           + dimensionName
           + ", hierarchy "
           + hierarchyName
           + ", level "
           + levelName
           + ", property "
           + propertyName
           + " ...");
   Hierarchy hierarchy =
       getHierarchy(ei.getSpagoBIPivotModel().getCube(), ei.getModelConfig(), dimensionName);
   Member member = cell.getContextMember(hierarchy);
   logger.debug("Considering context member " + member.getUniqueName());
   logger.debug("Member hierarchy is " + hierarchy.getUniqueName());
   if (hierarchy.getUniqueName().equals(hierarchyName)) {
     if (propertyName == null || propertyName.trim().equals("")) {
       value = getLevelValue(member, levelName);
     } else {
       value = getMemberPropertyValue(member, propertyName);
     }
   }
   return value;
 }
示例#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;
  }
示例#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>();
  }
示例#4
0
 public boolean removeLevel(
     String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) {
   IQuery query = getIQuery(queryName);
   removeAllChildren(queryName, dimensionName);
   QueryDimension dimension = query.getDimension(dimensionName);
   try {
     for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) {
       if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) {
         for (Level level : hierarchy.getLevels()) {
           if (level.getUniqueName().equals(uniqueLevelName)) {
             Selection inclusion = dimension.createSelection(level);
             dimension.getInclusions().remove(inclusion);
             ArrayList<Selection> removals = new ArrayList<Selection>();
             for (Selection sel : dimension.getInclusions()) {
               if ((sel.getRootElement() instanceof Member)) {
                 if (((Member) sel.getRootElement()).getLevel().equals(level)) {
                   if (dimension.getInclusions().contains(sel)) {
                     removals.add(sel);
                   }
                 }
               }
             }
             dimension.getInclusions().removeAll(removals);
           }
         }
       }
     }
   } catch (Exception e) {
     throw new SaikuServiceException(
         "Cannot remove level" + uniqueLevelName + "from dimension " + dimensionName, e);
   }
   return true;
 }
示例#5
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);
  }
示例#6
0
  public List<SaikuMember> getResultMetadataMembers(
      String queryName,
      boolean preferResult,
      String dimensionName,
      String hierarchyName,
      String levelName) {
    IQuery query = getIQuery(queryName);
    CellSet cs = query.getCellset();
    List<SaikuMember> members = new ArrayList<SaikuMember>();
    Set<Level> levels = new HashSet<Level>();

    if (cs != null && preferResult) {
      for (CellSetAxis axis : cs.getAxes()) {
        int posIndex = 0;
        for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) {
          if (h.getUniqueName().equals(hierarchyName)) {
            log.debug("Found hierarchy in the result: " + hierarchyName);
            if (h.getLevels().size() == 1) {
              break;
            }
            Set<Member> mset = new HashSet<Member>();
            for (Position pos : axis.getPositions()) {
              Member m = pos.getMembers().get(posIndex);
              if (!m.getLevel().getLevelType().equals(Type.ALL)) {
                levels.add(m.getLevel());
              }
              if (m.getLevel().getUniqueName().equals(levelName)) {
                mset.add(m);
              }
            }

            members = ObjectUtil.convertMembers(mset);
            Collections.sort(members, new SaikuUniqueNameComparator());

            break;
          }
          posIndex++;
        }
      }
      log.debug("Found members in the result: " + members.size());
    }
    if (cs == null || !preferResult || members.size() == 0 || levels.size() == 1) {
      members =
          olapDiscoverService.getLevelMembers(
              query.getSaikuCube(), dimensionName, hierarchyName, levelName);
    }

    return members;
  }
示例#7
0
 public boolean includeLevel(
     String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) {
   IQuery query = getIQuery(queryName);
   removeAllChildren(queryName, dimensionName);
   QueryDimension dimension = query.getDimension(dimensionName);
   for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) {
     if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) {
       for (Level level : hierarchy.getLevels()) {
         if (level.getUniqueName().equals(uniqueLevelName)) {
           Selection sel = dimension.createSelection(level);
           if (!dimension.getInclusions().contains(sel)) {
             dimension.include(level);
           }
           return true;
         }
       }
     }
   }
   return false;
 }
示例#8
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>();
  }
示例#9
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;
  }