Exemple #1
0
  @MethodFilter
  public ViewComponent addComponent(String componentName) {
    ViewComponent viewComponent = ViewComponent.newInstance(componentName);

    User user = Common.getUser();
    View view = user.getView();
    view.addViewComponent(viewComponent);
    viewComponent.validateDataPoint(user, false);

    return viewComponent;
  }
Exemple #2
0
  public String setViewPointAnon(int viewId, String viewComponentId, String valueStr) {
    View view = Common.getAnonymousView(viewId);
    if (view == null) throw new PermissionException("View is not in session", null);

    if (view.getAnonymousAccess() != ShareUser.ACCESS_SET)
      throw new PermissionException("Point is not anonymously settable", null);

    // Allow the set.
    setPointImpl(view.findDataPoint(viewComponentId), valueStr, new AnonymousUser());

    return viewComponentId;
  }
Exemple #3
0
  @MethodFilter
  public List<ShareUser> removeSharedUser(int userId) {
    View view = Common.getUser().getView();

    for (ShareUser su : view.getViewUsers()) {
      if (su.getUserId() == userId) {
        view.getViewUsers().remove(su);
        break;
      }
    }

    return view.getViewUsers();
  }
Exemple #4
0
  /**
   * Allows the setting of a given data point. Overrides BaseDwr to resolve the point view id.
   *
   * @param pointId
   * @param valueStr
   * @return
   */
  @MethodFilter
  public String setViewPoint(String viewComponentId, String valueStr) {
    User user = Common.getUser();
    View view = user.getView();
    DataPointVO point = view.findDataPoint(viewComponentId);

    if (point != null) {
      // Check that setting is allowed.
      int access = view.getUserAccess(user);
      if (!(access == ShareUser.ACCESS_OWNER || access == ShareUser.ACCESS_SET))
        throw new PermissionException("Not allowed to set this point", user);

      // Try setting the point.
      setPointImpl(point, valueStr, user);
    }

    return viewComponentId;
  }
Exemple #5
0
  private List<ViewComponentState> getViewPointData(User user, View view, boolean edit) {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    List<ViewComponentState> states = new ArrayList<ViewComponentState>();
    Map<String, Object> model = new HashMap<String, Object>();
    RuntimeManager rtm = Common.ctx.getRuntimeManager();

    for (ViewComponent viewComponent : view.getViewComponents()) {
      if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) {
        CompoundComponent compoundComponent = (CompoundComponent) viewComponent;

        boolean imageChart = compoundComponent instanceof ImageChartComponent;

        // Add states for each of the children
        for (CompoundChild child : compoundComponent.getChildComponents())
          addPointComponentState(
              child.getViewComponent(), rtm, model, request, view, user, states, edit, !imageChart);

        // Add a state for the compound component.
        ViewComponentState state = new ViewComponentState();
        state.setId(compoundComponent.getId());

        model.clear();
        model.put("compoundComponent", compoundComponent);

        List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>();
        for (CompoundChild child : compoundComponent.getChildComponents()) {
          if (child.getViewComponent().isPointComponent()) {
            DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint();
            if (point != null) {
              Map<String, Object> map = new HashMap<String, Object>();
              if (imageChart) map.put("name", point.getName());
              else map.put("name", getMessage(child.getDescription()));
              map.put("point", point);
              map.put("pointValue", point.lastValue());
              childData.add(map);
            }
          }
        }
        model.put("childData", childData);

        if (compoundComponent.hasInfo())
          state.setInfo(generateContent(request, "compoundInfoContent.jsp", model));

        if (imageChart)
          state.setContent(
              ((ImageChartComponent) compoundComponent).getImageChartData(getResourceBundle()));
        else if (!edit) state.setChart(compoundComponent.getImageChartData(getResourceBundle()));

        states.add(state);
      } else
        addPointComponentState(viewComponent, rtm, model, request, view, user, states, edit, true);
    }

    return states;
  }
Exemple #6
0
  //
  // View users
  //
  @MethodFilter
  public List<ShareUser> addUpdateSharedUser(int userId, int accessType) {
    View view = Common.getUser().getView();
    boolean found = false;
    for (ShareUser su : view.getViewUsers()) {
      if (su.getUserId() == userId) {
        found = true;
        su.setAccessType(accessType);
        break;
      }
    }

    if (!found) {
      ShareUser su = new ShareUser();
      su.setUserId(userId);
      su.setAccessType(accessType);
      view.getViewUsers().add(su);
    }

    return view.getViewUsers();
  }
Exemple #7
0
  private void addPointComponentState(
      ViewComponent viewComponent,
      RuntimeManager rtm,
      Map<String, Object> model,
      HttpServletRequest request,
      View view,
      User user,
      List<ViewComponentState> states,
      boolean edit,
      boolean add) {
    if (viewComponent.isPointComponent() && (edit || viewComponent.isVisible())) {
      PointComponent pointComponent = (PointComponent) viewComponent;

      DataPointRT dataPointRT = null;
      if (pointComponent.tgetDataPoint() != null)
        dataPointRT = rtm.getDataPoint(pointComponent.tgetDataPoint().getId());

      ViewComponentState state =
          preparePointComponentState(pointComponent, user, dataPointRT, model, request);

      if (!edit) {
        if (pointComponent.isSettable()) {
          int access = view.getUserAccess(user);
          if (access == ShareUser.ACCESS_OWNER || access == ShareUser.ACCESS_SET)
            setChange(pointComponent.tgetDataPoint(), state, dataPointRT, request, model);
        }

        if (pointComponent.tgetDataPoint() != null)
          setChart(pointComponent.tgetDataPoint(), state, request, model);
      }

      if (add) states.add(state);

      model.clear();
    }
  }
Exemple #8
0
 private ViewComponent getViewComponent(View view, String viewComponentId) {
   for (ViewComponent viewComponent : view.getViewComponents()) {
     if (viewComponent.getId().equals(viewComponentId)) return viewComponent;
   }
   return null;
 }
Exemple #9
0
 @MethodFilter
 public void deleteViewComponent(String viewComponentId) {
   View view = Common.getUser().getView();
   view.removeViewComponent(getViewComponent(view, viewComponentId));
 }