|
14 | 14 |
|
15 | 15 | public class urn_perun_user_attribute_def_def_login_namespace_lifescienceid_username extends urn_perun_user_attribute_def_def_login_namespace{ |
16 | 16 | private final static String elixirUsername = "urn:perun:user:attribute-def:def:login-namespace:elixir"; |
| 17 | + private final static String bbmriUsername = "urn:perun:user:attribute-def:def:login-namespace:bbmri"; |
17 | 18 |
|
18 | 19 | @Override |
19 | 20 | public void changedAttributeHook(PerunSessionImpl sess, User user, Attribute attribute) { |
20 | | - Attribute elixirPersistentShadow; |
| 21 | + trySetAttribute(sess, user, attribute, elixirUsername); |
| 22 | + trySetAttribute(sess, user, attribute, bbmriUsername); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Set attribute if it is not filled yet |
| 27 | + */ |
| 28 | + private void trySetAttribute(PerunSessionImpl sess, User user, Attribute lsAttribute, String attributeName) { |
| 29 | + Attribute newAttribute; |
21 | 30 | try { |
22 | | - elixirPersistentShadow = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, elixirUsername); |
| 31 | + newAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attributeName); |
23 | 32 | } catch (WrongAttributeAssignmentException | AttributeNotExistsException e) { |
24 | 33 | return; |
25 | 34 | } |
26 | | - elixirPersistentShadow.setValue(attribute.getValue()); |
| 35 | + |
| 36 | + if (newAttribute.getValue() != null && !newAttribute.valueAsString().isBlank()) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + newAttribute.setValue(lsAttribute.getValue()); |
| 41 | + |
27 | 42 | try { |
28 | | - sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, elixirPersistentShadow); |
| 43 | + sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, newAttribute); |
29 | 44 | } catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException e) { |
30 | 45 | throw new InternalErrorException(e); |
31 | 46 | } |
|
0 commit comments