All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.internet2.middleware.grouper.grouperUi.beans.api.GuiPermissionLimitBeanContainer Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright 2012 Internet2
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package edu.internet2.middleware.grouper.grouperUi.beans.api;

import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.lang.StringUtils;

import edu.internet2.middleware.grouper.attr.assign.AttributeAssign;
import edu.internet2.middleware.grouper.attr.assign.AttributeAssignType;
import edu.internet2.middleware.grouper.permissions.limits.PermissionLimitBean;
import edu.internet2.middleware.grouper.permissions.role.Role;
import edu.internet2.middleware.grouper.ui.tags.TagUtils;
import edu.internet2.middleware.grouper.ui.util.GrouperUiUtils;
import edu.internet2.middleware.grouper.util.GrouperUtil;

/**
 * for displaying a permission entry limit bean row on the screen (could be multiple actions)
 * @author mchyzer
 *
 */
@SuppressWarnings("serial")
public class GuiPermissionLimitBeanContainer implements Serializable, Comparable {
  
  /** permission limit and values */
  private PermissionLimitBean permissionLimitBean;

  /**
   * get actions comma separated
   * @return actions comma separated
   */
  public String getActionsCommaSeparated() {
    return StringUtils.join(GrouperUtil.nonNull(this.actions).iterator(), ", ");
  }
  
  /**
   * 
   * @return if has multiple actions
   */
  public boolean isHasMultipleActions() {
    return GrouperUtil.nonNull(this.actions).size() > 1;
  }
  
  /**
   * if it has values
   * @return if has values
   */
  public boolean isHasValues() {
    return GrouperUtil.nonNull(this.permissionLimitBean.getLimitAssignValues()).size() > 0;
  }
  
  /**
   * permission limit and values
   * @return permission limit and values
   */
  public PermissionLimitBean getPermissionLimitBean() {
    return this.permissionLimitBean;
  }

  /**
   * permission limit and values
   * @param permissionLimitBean1
   */
  public void setPermissionLimitBean(PermissionLimitBean permissionLimitBean1) {
    this.permissionLimitBean = permissionLimitBean1;
    this.limitDisplayExtension = permissionLimitBean1.getLimitAssign().getAttributeDefName().getDisplayExtension();
  }
  
  /** one limit can apply to multiple actions... keep them sorted */
  private Set actions = new TreeSet();

  /**
   * one limit can apply to multiple actions... keep them sorted
   * @return the set, never null
   */
  public Set getActions() {
    return this.actions;
  }
  
  /** if immediate for any applicable action, i.e. can be deleted */
  private boolean immediate = false;

  /** limit display extension for sorting */
  private String limitDisplayExtension;
  
  /**
   * if immediate for any applicable action, i.e. can be deleted
   * @return if immediate
   */
  public boolean isImmediate() {
    return this.immediate;
  }

  /**
   * if immediate for any applicable action, i.e. can be deleted
   * @param immediate1
   */
  public void setImmediate(boolean immediate1) {
    this.immediate = immediate1;
  }

  /**
   * get the tooltip for where assigned
   * @return the tooltip
   */
  public String getAssignedToTooltip() {
    StringBuilder result = new StringBuilder();
    
    //everything has a role
    AttributeAssign limitAssign = this.getPermissionLimitBean().getLimitAssign();
    
    AttributeAssignType attributeAssignType = limitAssign.getAttributeAssignType();
    if (AttributeAssignType.group == attributeAssignType) {
      result.append(StringUtils.replace(TagUtils.navResourceString("simplePermissionUpdate.limitRoleTypeLabel"), "\"", """)).append("
"); } else if (AttributeAssignType.any_mem == attributeAssignType) { result.append(StringUtils.replace(TagUtils.navResourceString("simplePermissionUpdate.limitMembershipTypeLabel"), "\"", """)).append("
"); } else if (AttributeAssignType.any_mem_asgn == attributeAssignType || AttributeAssignType.group_asgn == attributeAssignType) { result.append(StringUtils.replace(TagUtils.navResourceString("simplePermissionUpdate.limitPermisssionTypeLabel"), "\"", """)).append("
"); } else { throw new RuntimeException("Not expecting limit assign type: " + attributeAssignType); } AttributeAssign ownerAttributeAssign = limitAssign.getAttributeAssignType().isAssignmentOnAssignment() ? limitAssign.getOwnerAttributeAssign() : null; Role role = limitAssign.getAttributeAssignType().isAssignmentOnAssignment() ? ownerAttributeAssign.getOwnerGroup() : limitAssign.getOwnerGroup(); result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitAssignedToRoleLabel"), true)); result.append(" ").append(role.getDisplayName()).append("
"); if (AttributeAssignType.any_mem == attributeAssignType) { GuiSubject guiSubject = new GuiSubject(limitAssign.getOwnerMember().getSubject()); result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitAssignedToEntityLabel"), true)); result.append(" ").append(guiSubject.getScreenLabel()).append("
"); } if (AttributeAssignType.any_mem_asgn == attributeAssignType) { GuiSubject guiSubject = new GuiSubject(ownerAttributeAssign.getOwnerMember().getSubject()); result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitAssignedToEntityLabel"), true)); result.append(" ").append(guiSubject.getScreenLabel()).append("
"); } if (limitAssign.getAttributeAssignType().isAssignmentOnAssignment()) { result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitAssignedToPermissionActionLabel"), true)); result.append(" ").append(ownerAttributeAssign.getAttributeAssignAction().getName()).append("
"); result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitAssignedToPermissionNameLabel"), true)); result.append(" ").append(ownerAttributeAssign.getAttributeDefName().getDisplayName()).append("
"); } result.append(GrouperUiUtils.escapeHtml(TagUtils.navResourceString("simplePermissionUpdate.limitIdLabel"), true)); result.append(" ").append(limitAssign.getId()); return result.toString(); } /** * @see Comparable#compareTo(Object) */ @Override public int compareTo(GuiPermissionLimitBeanContainer other) { //keep the limit display extension cached return this.limitDisplayExtension.compareTo(other.limitDisplayExtension); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy