Skip to content

Commit 9298bf9

Browse files
authored
Merge pull request #3946 from Johaney-s/ls_username
feat(core): extend lifescience username module
2 parents 4336cca + 339ea36 commit 9298bf9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_login_namespace_lifescienceid_username.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,33 @@
1414

1515
public class urn_perun_user_attribute_def_def_login_namespace_lifescienceid_username extends urn_perun_user_attribute_def_def_login_namespace{
1616
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";
1718

1819
@Override
1920
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;
2130
try {
22-
elixirPersistentShadow = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, elixirUsername);
31+
newAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attributeName);
2332
} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
2433
return;
2534
}
26-
elixirPersistentShadow.setValue(attribute.getValue());
35+
36+
if (newAttribute.getValue() != null && !newAttribute.valueAsString().isBlank()) {
37+
return;
38+
}
39+
40+
newAttribute.setValue(lsAttribute.getValue());
41+
2742
try {
28-
sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, elixirPersistentShadow);
43+
sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, newAttribute);
2944
} catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException e) {
3045
throw new InternalErrorException(e);
3146
}

0 commit comments

Comments
 (0)