if (a != null && a.getValue() != null && !((String)a.getValue()).isEmpty()) { result = (String)a.getValue(); if (a2 != null && a2.getValue() != null && !((String)a2.getValue()).isEmpty()) { result = (String)a2.getValue(); if (a2 != null && a2.getValue() != null && !((String)a2.getValue()).isEmpty()) { result = (String)a2.getValue();
private static Attribute createAttribute(Map<String, String> beanAttr) throws InternalErrorException { if(beanAttr==null) return null; Attribute attribute = new Attribute(); attribute.setId(Integer.valueOf(beanAttr.get("id"))); attribute.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attribute.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attribute.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); attribute.setValue(BeansUtils.stringToAttributeValue(BeansUtils.eraseEscaping(beanAttr.get("value")), attribute.getType())); attribute.setUnique(Boolean.valueOf(beanAttr.get("unique"))); return attribute; }
public Attribute(Attribute attribute, boolean copyValue) { super(attribute); if(copyValue) { this.value = attribute.getValue(); this.valueCreatedAt = attribute.getValueCreatedAt(); this.valueCreatedBy = attribute.getValueCreatedBy(); this.valueModifiedAt = attribute.getValueModifiedAt(); this.valueModifiedBy = attribute.getValueModifiedBy(); } }
@Override public String toString() { return this.getClass().getSimpleName() + ":[" + "id='" + getId() + '\'' + ", friendlyName='" + getFriendlyName() + '\'' + ", namespace='" + getNamespace() + '\'' + ", type='" + getType() + '\'' + ", unique='" + isUnique() + '\'' + ", value='" + getValue() + '\'' + ']'; } }
/** * Converts attribute value to string (serialize object to string). * This is a wrapper for passing value and type only for specific use. * @see #attributeValueToString(Attribute) * * @param attributeValue value of the attribute * @param type type of resulting attribute * @return string representation of the value * * @throws InternalErrorException */ @SuppressWarnings("unchecked") public static String attributeValueToString(Object attributeValue, String type) throws InternalErrorException { Attribute a = new Attribute(); a.setType(type); a.setValue(attributeValue); return attributeValueToString(a); }
Attribute loginMu = perun.getAttributesManager().getAttribute(session, user, "urn:perun:user:attribute-def:def:login-namespace:mu"); if (eduroamIdentities.getValue() == null) { if (loginMu.getValue() != null) { identities.add(((String)loginMu.getValue())+"@eduroam.muni.cz"); eduroamIdentities.setValue(identities); if (loginMu.getValue() != null) { for (String value : (List<String>)eduroamIdentities.getValue()) { if (Objects.equals(value, ((String)loginMu.getValue())+"@eduroam.muni.cz")) { found = true; break; ((List<String>) eduroamIdentities.getValue()).add(((String)loginMu.getValue())+"@eduroam.muni.cz");
boolean found = false; for (Attribute a : loginAttrs) { if (pair.getLeft().equals(a.getFriendlyNameParameter())) { , pair.getRight(), pair.getLeft(), a.getValue()); found = true; break;
private EmailSCIM getEmail(User perunUser) { Attribute preferredEmailAttribute = new Attribute(); EmailSCIM email = new EmailSCIM(); try { preferredEmailAttribute = perunBl.getAttributesManagerBl().getAttribute(session, perunUser, AttributesManager.NS_USER_ATTR_DEF + ":preferredMail"); if (preferredEmailAttribute.getValue() != null) { email.setValue(preferredEmailAttribute.getValue().toString()); email.setPrimary(true); email.setType("preferred email"); return email; } } catch (InternalErrorException | WrongAttributeAssignmentException ex) { log.error("Internal exception occured while getting preferred email of user " + perunUser.getId(), ex); } catch (AttributeNotExistsException ex) { log.error("Attribute preferredMail doesn't exist for user " + perunUser.getId(), ex); } return null; } }
if (a != null && "login-namespace".equals(a.getBaseFriendlyName())) { continue; if (a.getType().equalsIgnoreCase("java.util.LinkedHashMap")) { } else if (a.getType().equalsIgnoreCase("java.util.ArrayList") || a.getType().equalsIgnoreCase(BeansUtils.largeArrayListClassName)) { ArrayList<String> value = ((ArrayList<String>)a.getValue()); a.setValue(value); attributes.add(a); continue; } else { a.setValue(newValue); attributes.add(a);
/** * Add new bonaFideStatus to the user attribute. */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { User user = app.getUser(); Group group = app.getGroup(); AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); String newValue = attestation.valueAsString(); Attribute bonaFideStatus = am.getAttribute(session, user, A_U_D_userBonaFideStatus); List<String> value = new ArrayList<>(); if (bonaFideStatus.getValue() != null && bonaFideStatus.valueAsList() != null) { value = bonaFideStatus.valueAsList(); } value.add(newValue); bonaFideStatus.setValue(value); am.setAttribute(session, user, bonaFideStatus); return app; }
/** * Check if the attribute value contains value. In case of list, it uses method contains. In case of array it searches in both keys and values. * * @param value value * @return true if the attribute value contains value. */ @SuppressWarnings("unchecked") public boolean valueContains(String value) { if (this.getType().equals(String.class.getName()) || this.getType().equals(BeansUtils.largeStringClassName)) { return value == null ? this.getValue() == null : value.equals(this.getValue()); } else if (this.getType().equals(ArrayList.class.getName()) || this.getType().equals(BeansUtils.largeArrayListClassName)) { return this.getValue() == null ? value == null : ((ArrayList<String>) this.getValue()).contains(value); } else if (this.getType().equals(LinkedHashMap.class.getName())) { return this.getValue() == null ? value == null : (((LinkedHashMap<String, String>) this.getValue()).containsKey(value) || ((LinkedHashMap<String, String>) this.getValue()).containsValue(value)); } else return false; }
if (MailManagerImpl.URN_USER_PREFERRED_MAIL.equals(a.getName())) { if (a.getValue() != null && !((String)a.getValue()).isEmpty()) { String safeMail = ((String) a.getValue()).split("@")[0]; safeMail += "@"+((String) a.getValue()).split("@")[1]; } else if ("urn:perun:user:attribute-def:def:organization".equals(a.getName())) { if (a.getValue() != null) { identity.setOrganization((String)a.getValue()); if (uesAttr.getValue() != null && !((String) uesAttr.getValue()).isEmpty()) { ues.getExtSource().setName((String) uesAttr.getValue());
Matcher uidMatcher = userUidNamespacePattern.matcher(this.attribute.getName()); Matcher loginMatcher = userLoginNamespacePattern.matcher(this.attribute.getName()); if(this.attribute.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrPreferredMail)) { if(this.attribute.getValue() != null) { updateUserAttribute(ldapAttrPreferredMail, (String) this.attribute.getValue(), LdapOperation.REPLACE_ATTRIBUTE, user); updateUserAttribute(ldapAttrMail, (String) this.attribute.getValue(), LdapOperation.REPLACE_ATTRIBUTE, user); } else { if(ldapConnector.userAttributeExist(this.user, ldapAttrPreferredMail)) { } else if(this.attribute.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrOrganization)) { if(this.attribute.getValue() != null) { updateUserAttribute(ldapAttrOrganization, (String) attribute.getValue(), LdapOperation.REPLACE_ATTRIBUTE, this.user); } else { if(ldapConnector.userAttributeExist(this.user, ldapAttrOrganization)) { } else if(this.attribute.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_DEF + ":" + perunAttrPhone)) { if(this.attribute.getValue() != null) { updateUserAttribute(ldapAttrTelephoneNumber, (String) attribute.getValue(), LdapOperation.REPLACE_ATTRIBUTE, this.user); } else { if(ldapConnector.userAttributeExist(this.user, ldapAttrTelephoneNumber)) { } else if(this.attribute.getName().equals(cz.metacentrum.perun.core.api.AttributesManager.NS_USER_ATTR_VIRT + ":" + perunAttrUserCertDNs)) { Map<String, String> certDNsMap = (this.attribute.getValue() != null) ? (Map) this.attribute.getValue() : null; Set<String> certSubjectsWithPrefixes = ((Map) this.attribute.getValue()).keySet(); Set<String> certSubjectsWithoutPrefixes = new HashSet<>();
User user = perun.getUsersManagerBl().getUserById(session, id); Attribute emailAttribute = perun.getAttributesManagerBl().getAttribute(session, user, "urn:perun:user:attribute-def:def:preferredMail"); if (emailAttribute != null && StringUtils.hasText(emailAttribute.toString())) { emailDto.setReceiver((String) emailAttribute.getValue());
public void updatePriorityCoefficient(PerunSession sess, Integer userId, Double rank) throws CabinetException { try { // get definition AttributeDefinition attrDef = perun.getAttributesManager().getAttributeDefinition(cabinetSession, ATTR_COEF_NAMESPACE+":"+ATTR_COEF_FRIENDLY_NAME); // Set attribute value Attribute attr = new Attribute(attrDef); DecimalFormat twoDForm = new DecimalFormat("#.##"); attr.setValue(String.valueOf(twoDForm.format(rank))); // get user User user = perun.getUsersManager().getUserById(cabinetSession, userId); // assign or update user's attribute perun.getAttributesManager().setAttribute(cabinetSession, user, attr); } catch (PerunException e) { throw new CabinetException("Failed to update priority coefficient in Perun.",ErrorCodes.PERUN_EXCEPTION, e); } }
if (affiliations.getValue() != null) { List<String> val = affiliations.valueAsList(); for (String affiliation: val) { if (affiliation.startsWith("faculty@")) { if (rems.getValue() != null) { return;
/** * Get list of Attributes from list of AttributeHolders * Used in CacheManager to transform result of query (list of AttributeHolders) to list of Attributes. * * @param attrHolders list of AttributeHolders * @return list of Attributes */ public static List<Attribute> getAttributesFromAttributeHolders(List<AttributeHolders> attrHolders) { List<Attribute> attrs = new ArrayList<>(); for (AttributeHolders attrHolder: attrHolders) { attrs.add(new Attribute(attrHolder, true)); } return attrs; }
public AttributeHolders(Attribute attribute, Holder primaryHolder, Holder secondaryHolder, SavedBy savedBy) throws InternalErrorException { super(attribute, true); if (primaryHolder != null && secondaryHolder != null) { if (secondaryHolder.getType().equals(Holder.HolderType.GROUP) && (!primaryHolder.getType().equals(Holder.HolderType.MEMBER)) || (secondaryHolder.getType().equals(Holder.HolderType.MEMBER)) || (secondaryHolder.getType().equals(Holder.HolderType.USER))) { this.primaryHolder = secondaryHolder; this.secondaryHolder = primaryHolder; } else { this.primaryHolder = primaryHolder; this.secondaryHolder = secondaryHolder; } } else { this.primaryHolder = primaryHolder; this.secondaryHolder = secondaryHolder; } this.nameForSearch = attribute.getNamespace() + ":" + attribute.getFriendlyName(); this.namespaceForSearch = attribute.getNamespace(); this.friendlyNameForSearch = attribute.getFriendlyName(); this.typeForSearch = attribute.getType(); this.idForSearch = attribute.getId(); this.valueForSearch = BeansUtils.attributeValueToString(attribute); this.savedBy = savedBy; }
/** * Creates Attribute instance from an AttributeDefinition and a value. */ public Attribute(AttributeDefinition attributeDefinition, Object value) { this(attributeDefinition); this.setValue(value); }