public int compareTo(PerunBean perunBean) { if (perunBean == null) throw new NullPointerException("PerunBean to compare with is null."); if (perunBean instanceof AttributeDefinition) { AttributeDefinition attrDef = (AttributeDefinition) perunBean; if (this.getFriendlyName() == null && attrDef.getFriendlyName() != null) return -1; if (attrDef.getFriendlyName() == null && this.getFriendlyName() != null) return 1; if (this.getFriendlyName() == null && attrDef.getFriendlyName() == null) return 0; return this.getFriendlyName().compareToIgnoreCase(attrDef.getFriendlyName()); } else { return (this.getId() - perunBean.getId()); } }
public AttributeHolders(AttributeDefinition attribute, SavedBy savedBy) { super(attribute); this.nameForSearch = attribute.getNamespace() + ":" + attribute.getFriendlyName(); this.namespaceForSearch = attribute.getNamespace(); this.friendlyNameForSearch = attribute.getFriendlyName(); this.typeForSearch = attribute.getType(); this.idForSearch = attribute.getId(); this.valueForSearch = null; this.savedBy = savedBy; }
/** * Returns abbreviation in format [Entity]:[V/D/C]:[friendlyName] * [Entity] is something like 'U' for user, 'G-R' for group-resource etc. * * @param ad attribute definition * @return abbreviation in format [Entity]:[V/D/C]:[friendlyName] */ public static String getAttributeDefinitionAbbreviation(AttributeDefinition ad) { String entity = parseEntityAbbreviation(ad); String type; if (ad.getNamespace().endsWith("virt")) { type = "V"; } else if (ad.getNamespace().endsWith("def")) { type = "D"; } else { type = "C"; } String formattedFriendlyName; String[] splitFriendlyName = ad.getFriendlyName().split(":"); formattedFriendlyName = splitFriendlyName[0]; if (splitFriendlyName.length > 1) { formattedFriendlyName += ":*"; } return entity + ":" + type + ":" + formattedFriendlyName; }
@Override public String serializeToString() { return this.getClass().getSimpleName() + ":[" + "id=<" + getId() + ">" + ", friendlyName=<" + (getFriendlyName() == null ? "\\0" : BeansUtils.createEscaping(getFriendlyName())) + ">" + ", namespace=<" + (getNamespace() == null ? "\\0" : BeansUtils.createEscaping(getNamespace())) + ">" + ", type=<" + (getType() == null ? "\\0" : BeansUtils.createEscaping(getType())) + ">" + ", unique=<" + unique + ">" + ']'; }
/** * Compares this instance to other instance, throws exception if they are different. * Used to check that Attribute has correct AttributeDefinition fields. * * @param a other instance to be checked for equality * @throws ConsistencyErrorException thrown if any of class attributes differ */ public void checkEquality(AttributeDefinition a) throws ConsistencyErrorException { if (!this.getFriendlyName().equals(a.getFriendlyName())) throw new ConsistencyErrorException("attribute friendlyName is altered"); if (!this.getNamespace().equals(a.getNamespace())) throw new ConsistencyErrorException("attribute namespace is altered"); if (!this.getType().equals(a.getType())) throw new ConsistencyErrorException("attribute type is altered"); if (this.isUnique() != a.isUnique()) throw new ConsistencyErrorException("attribute unique flag is altered"); }
/** * Copy constructor. New attribute will be exactly the same as attribute from parameter. * * @param attributeDefinition attribute to copy */ public AttributeDefinition(AttributeDefinition attributeDefinition) { super(attributeDefinition.getId(), attributeDefinition.getCreatedAt(), attributeDefinition.getCreatedBy(), attributeDefinition.getModifiedAt(), attributeDefinition.getModifiedBy(), attributeDefinition.getCreatedByUid(), attributeDefinition.getModifiedByUid()); this.friendlyName = attributeDefinition.getFriendlyName(); this.namespace = attributeDefinition.getNamespace(); this.description = attributeDefinition.getDescription(); this.type = attributeDefinition.getType(); this.displayName = attributeDefinition.getDisplayName(); this.writable = attributeDefinition.getWritable(); this.unique = attributeDefinition.isUnique(); }