private static AttributeDefinition createAttributeDefinition(Map<String, String> beanAttr) { if(beanAttr==null) return null; AttributeDefinition attributeDefinition = new AttributeDefinition(); attributeDefinition.setId(Integer.valueOf(beanAttr.get("id"))); attributeDefinition.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attributeDefinition.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attributeDefinition.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); attributeDefinition.setUnique(Boolean.valueOf(beanAttr.get("unique"))); return attributeDefinition; }
/** * 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(); }
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; }
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()); } }
AttributeDefinition attributeDefinition = new AttributeDefinition(); attributeDefinition.setDisplayName(ATTR_COEF_DISPLAY_NAME); attributeDefinition.setDescription(ATTR_COEF_DESCRIPTION); attributeDefinition.setFriendlyName(ATTR_COEF_FRIENDLY_NAME); attributeDefinition.setNamespace(ATTR_COEF_NAMESPACE); attributeDefinition.setType(ATTR_COEF_TYPE); try { rights.add(new AttributeRights(attrDef.getId(), Role.SELF, Arrays.asList(ActionType.READ))); perun.getAttributesManager().setAttributeRights(cabinetSession, rights); } catch (PerunException pe) { AttributeDefinition attributeDefinition = new AttributeDefinition(); attributeDefinition.setDisplayName(ATTR_PUBS_DISPLAY_NAME); attributeDefinition.setDescription(ATTR_PUBS_DESCRIPTION); attributeDefinition.setFriendlyName(ATTR_PUBS_FRIENDLY_NAME); attributeDefinition.setNamespace(ATTR_PUBS_NAMESPACE); attributeDefinition.setType(ATTR_PUBS_TYPE); try { attrDef2 = perun.getAttributesManager().createAttribute(cabinetSession, attributeDefinition); rights.add(new AttributeRights(attrDef2.getId(), Role.SELF, Arrays.asList(ActionType.READ))); perun.getAttributesManager().setAttributeRights(cabinetSession, rights); } catch (PerunException pe) {
for (String attrName : attrNames) { AttributeDefinition attr = new Attribute(); attr.setType(String.class.getName()); attr.setNamespace("urn:perun:ues:attribute-def:def"); attr.setFriendlyName(attrName); switch (attrName) { case "mail": attr.setDisplayName("mail"); attr.setDescription("email address"); break; case "cn": attr.setDisplayName("common name"); attr.setDescription("full name of person"); break; case "sn": attr.setDisplayName("surname"); attr.setDescription("family name, usually last name (first in Hungary)"); break; case "givenName": attr.setDisplayName("given name"); attr.setDescription("usually first name (last in Hungary)"); break; case "eppn": attr.setDisplayName("eduPersonPrincipalName"); attr.setDescription("person identifier in academic federations"); break; case "epuid": attr.setDisplayName("eduPersonUniqueId"); attr.setDescription("non re-assignable person identifier in academic federations");
/** * Get list of AttributeDefinitions from list of AttributeHolders * Used in CacheManager to transform result of query (list of AttributeHolders) to list of AttributeDefinitions. * * @param attrHolders list of AttributeHolders * @return list of AttributeDefinitions */ public static List<AttributeDefinition> getAttributeDefinitionsFromAttributeHolders(List<AttributeHolders> attrHolders) { List<AttributeDefinition> attrDefs = new ArrayList<>(); for (AttributeHolders attrHolder: attrHolders) { attrDefs.add(new AttributeDefinition(attrHolder)); } return attrDefs; }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof AttributeDefinition)) return false; final AttributeDefinition other = (AttributeDefinition) obj; return this.getId() == other.getId() && (this.friendlyName == null ? other.friendlyName == null : this.friendlyName.equals(other.friendlyName)) && (this.namespace == null ? other.namespace == null : this.namespace.equals(other.namespace)); }
Matcher uidMatcher = userUidNamespacePattern.matcher(this.attributeDef.getName()); Matcher loginMatcher = userLoginNamespacePattern.matcher(this.attributeDef.getName()); if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrPreferredMail)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrPreferredMail)) { updateUserAttribute(ldapAttrPreferredMail, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrOrganization)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrOrganization)) { updateUserAttribute(ldapAttrOrganization, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrPhone)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrTelephoneNumber)) { updateUserAttribute(ldapAttrTelephoneNumber, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_VIRT + ":" + perunAttrUserCertDNs)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrUserCertDNs)) { updateUserAttribute(ldapAttrUserCertDNs, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_VIRT + ":" + perunAttrEduPersonScopedAffiliations)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrEduPersonScopedAffiliations)) { updateUserAttribute(ldapAttrEduPersonScopedAffiliations, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_VIRT + ":" + perunAttrGroupNames)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrGroupNames)) { updateUserAttribute(ldapAttrGroupNames, null, LdapOperation.REMOVE_ATTRIBUTE, this.user); } else if(this.attributeDef.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_VIRT + ":" + perunAttrInstitutionsCountries)) { if(ldapConnector.userAttributeExist(this.user, ldapAttrInstitutionsCountries)) { updateUserAttribute(ldapAttrInstitutionsCountries, null, LdapOperation.REMOVE_ATTRIBUTE, this.user);
String loginNamespace = loginAttribute.getFriendlyNameParameter();
AttributeDefinition attrDef = new AttributeDefinition(); attrDef.setDisplayName(DISPLAY_NAME_VO_FROM_EMAIL); attrDef.setFriendlyName(FRIENDLY_NAME_VO_FROM_EMAIL); attrDef.setNamespace(NAMESPACE_VO_FROM_EMAIL); attrDef.setDescription("Email address used as \"from\" in mail notifications."); attrDef.setType(String.class.getName()); attrDef = attrManager.createAttribute(registrarSession, attrDef); rights.add(new AttributeRights(attrDef.getId(), Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE))); perun.getAttributesManager().setAttributeRights(registrarSession, rights); AttributeDefinition attrDef = new AttributeDefinition(); attrDef.setDisplayName(DISPLAY_NAME_VO_TO_EMAIL); attrDef.setFriendlyName(FRIENDLY_NAME_VO_TO_EMAIL); attrDef.setNamespace(NAMESPACE_VO_TO_EMAIL); attrDef.setDescription("Email addresses (of VO administrators) used as \"to\" in mail notifications."); attrDef.setType("java.util.ArrayList"); attrDef = attrManager.createAttribute(registrarSession, attrDef); rights.add(new AttributeRights(attrDef.getId(), Role.VOADMIN, Arrays.asList(ActionType.READ, ActionType.WRITE))); perun.getAttributesManager().setAttributeRights(registrarSession, rights); AttributeDefinition attrDef = new AttributeDefinition(); attrDef.setDisplayName(DISPLAY_NAME_GROUP_TO_EMAIL); attrDef.setFriendlyName(FRIENDLY_NAME_GROUP_TO_EMAIL); attrDef.setNamespace(NAMESPACE_GROUP_TO_EMAIL); attrDef.setDescription("Email addresses (of Group administrators) used as \"to\" in mail notifications."); attrDef.setType("java.util.ArrayList"); attrDef = attrManager.createAttribute(registrarSession, attrDef);
@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 + ">" + ']'; }
@Override public String toString() { return this.getClass().getSimpleName() + ":[" + "id='" + getId() + "'" + ", friendlyName='" + friendlyName + "'" + ", namespace='" + namespace + "'" + ", type='" + type + "'" + ", unique='" + unique + "'" + ']'; } }
@Override public int hashCode() { int hash = 7; hash = 53 * hash + getId(); hash = 53 * hash + (friendlyName == null ? 0 : friendlyName.hashCode()); hash = 53 * hash + (namespace == null ? 0 : namespace.hashCode()); return hash; }