/** * 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; }
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; }
/** * 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); }
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); } }
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; } }
Attribute attr = new Attribute(attrDef);
} catch (AttributeNotExistsException | WrongAttributeAssignmentException ex) { entityIDAttr = new Attribute(); log.error("EntityId attribute is missing or it's assignment is wrong is missing. Attribute was skipped.", ex); } catch (AttributeNotExistsException | WrongAttributeAssignmentException ex) { clientIDAttr = new Attribute(); log.error("clientIDAttr attribute is missing or it's assignment is wrong is missing. Attribute was skipped.", ex);
private void createAttributeDefinitions(String extSourceType, List<String> attrNames) { List<AttributeDefinition> attrs = new ArrayList<>(); for (String attrName : attrNames) { AttributeDefinition attr = new Attribute(); attr.setType(String.class.getName()); attr.setNamespace("urn:perun:ues:attribute-def:def");