Ejemplo n.º 1
0
  /**
   * Persists a new person and make them follow themselves.
   *
   * @param inActionContext the action context
   * @param inFields the fields.
   * @param inPerson the person to persist.
   * @throws Exception On error.
   */
  @Override
  public void persist(
      final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
      final Map<String, Serializable> inFields,
      final Person inPerson)
      throws Exception {
    personMapper.insert(inPerson);

    // sets the destination entity id for the person's stream scope
    inPerson.getStreamScope().setDestinationEntityId(inPerson.getId());

    // this has to be the last thing we do, since it updates the person behind the back of the
    // object model
    personMapper.addFollower(inPerson.getId(), inPerson.getId());
  }
  @Override
  public Serializable execute(final PrincipalActionContext inActionContext)
      throws ExecutionException {
    SetTabOrderRequest currentRequest = (SetTabOrderRequest) inActionContext.getParams();

    Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId());

    List<Tab> tabs = person.getTabs(currentRequest.getTabType());

    // Find the tab to be moved
    int oldIndex = findTabIndex(tabs, currentRequest.getTabId());

    Tab movingTab = tabs.get(oldIndex);

    // move the tab
    tabs.remove(oldIndex);
    tabs.add(currentRequest.getNewIndex(), movingTab);

    personMapper.flush();

    return Boolean.TRUE;
  }
  /**
   * Perform security check on this action to verify user can execute. Throw appropriate
   * AuthorizationException in needed.
   *
   * @param inActionContext {@link PrincipalActionContext}.
   * @throws AuthorizationException thrown if the user does not have proper access
   */
  @Override
  public void authorize(final PrincipalActionContext inActionContext)
      throws AuthorizationException {
    AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams();
    Long tabId = request.getTabId();

    // get the Tab we're inserting the Gadget into
    if (tabId == null) {
      // if client passes null for id, find the first tab
      Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId());
      tabId = person.getStartTabGroup().getTabs().get(0).getId();
    }

    // This will throw AuthorizationException if user doesn't have permissions.
    if (!tabPermission.canModifyGadgets(
        inActionContext.getPrincipal().getAccountId(), tabId, true)) {
      throw new AuthorizationException("Failed to authorize adding of the supplied gadget.");
    }
  }