/** * Creates Attribute instance from an AttributeDefinition and a value. */ public Attribute(AttributeDefinition attributeDefinition, Object value) { this(attributeDefinition); this.setValue(value); }
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); } }
a.setValue(safeMail);
} else { a.setValue(newValue); attributes.add(a);
attr.setValue(map); perun.getAttributesManager().setAttribute(cabinetSession, u, attr); } else {
/** * 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; }
@Override public Application approveApplication(PerunSession sess, Application application) throws PerunException { if (application.getType() == Application.AppType.INITIAL) { List<ApplicationFormItemData> applicationData = registrar.getApplicationDataById(sess, application.getId()); String nickName = null; for (ApplicationFormItemData appItem : applicationData) { if (APPLICATION_NICKNAME_ITEM.equals(appItem.getShortname())) { nickName = appItem.getValue(); } } if (nickName != null && !nickName.trim().isEmpty()) { User user = application.getUser(); Attribute loginAttribute; try { loginAttribute = sess.getPerun().getAttributesManager().getAttribute(sess, user, A_U_D_EDUTEAMS_NICKNAME); } catch (AttributeNotExistsException e) { // do not set the login if the attribute does not exist return application; } loginAttribute.setValue(nickName); sess.getPerun().getAttributesManager().setAttribute(sess, user, loginAttribute); } } return application; }
identities.add(((String)loginMu.getValue())+"@eduroam.muni.cz"); eduroamIdentities.setValue(identities);
@Override public Application approveApplication(PerunSession session, Application app) throws PerunException { PerunBl perun = (PerunBl) session.getPerun(); Member member = perun.getMembersManagerBl().getMemberByUser(session, app.getVo(), app.getUser()); if (app.getGroup() == null && Objects.equals(app.getType(), Application.AppType.INITIAL)) { // IF VO INITIAL override VO rules to set unlimited (only to those with LoA = 2). Attribute loaAttr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_VIRT + ":loa"); int loa = Integer.valueOf((String) loaAttr.getValue()); if (loa == 2) { Attribute attr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_DEF + ":membershipExpiration"); attr.setValue("9999-01-01"); // set distant future as never expires perun.getAttributesManagerBl().setAttribute(session, member, attr); } } if ((app.getGroup() != null && Objects.equals(app.getType(), Application.AppType.INITIAL)) || (app.getGroup() == null && Objects.equals(app.getType(), Application.AppType.EXTENSION))) { // GROUP INITIAL OR VO EXTENSION -> set back standard expiration date based on VO rules Attribute attr = perun.getAttributesManagerBl().getAttribute(session, member, AttributesManager.NS_MEMBER_ATTR_DEF + ":membershipExpiration"); perun.getAttributesManagerBl().removeAttribute(session, member, attr); perun.getMembersManagerBl().extendMembership(session, member); } return app; }