|
| 1 | +package cz.metacentrum.perun.core.impl.modules.attributes; |
| 2 | + |
| 3 | +import cz.metacentrum.perun.core.api.Attribute; |
| 4 | +import cz.metacentrum.perun.core.api.AttributeDefinition; |
| 5 | +import cz.metacentrum.perun.core.api.AttributesManager; |
| 6 | +import cz.metacentrum.perun.core.api.User; |
| 7 | +import cz.metacentrum.perun.core.api.exceptions.*; |
| 8 | +import cz.metacentrum.perun.core.impl.PerunSessionImpl; |
| 9 | +import cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleAbstract; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class for access def:bbmri-test-persistent-shadow attribute. It generates value if you call it for the first time. |
| 13 | + * |
| 14 | + * @author Peter Jancus <p.jancus1996@gmail.com> |
| 15 | + * |
| 16 | + * @date 21.06.2018 |
| 17 | + */ |
| 18 | +public class urn_perun_user_attribute_def_virt_login_namespace_bbmri_test_persistent extends UserVirtualAttributesModuleAbstract { |
| 19 | + |
| 20 | + public static final String SHADOW = "urn:perun:user:attribute-def:def:login-namespace:bbmri-test-persistent-shadow"; |
| 21 | + |
| 22 | + @Override |
| 23 | + public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException { |
| 24 | + Attribute bbmriPersistent = new Attribute(attributeDefinition); |
| 25 | + |
| 26 | + try { |
| 27 | + Attribute bbmriPersistentShadow = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, SHADOW); |
| 28 | + |
| 29 | + if (bbmriPersistentShadow.getValue() == null) { |
| 30 | + |
| 31 | + bbmriPersistentShadow = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, user, bbmriPersistentShadow); |
| 32 | + |
| 33 | + if (bbmriPersistentShadow.getValue() == null) { |
| 34 | + throw new InternalErrorException("BBMRI TEST id couldn't be set automatically"); |
| 35 | + } |
| 36 | + sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, bbmriPersistentShadow); |
| 37 | + } |
| 38 | + |
| 39 | + bbmriPersistent.setValue(bbmriPersistentShadow.getValue()); |
| 40 | + return bbmriPersistent; |
| 41 | + |
| 42 | + } catch (WrongAttributeAssignmentException e) { |
| 43 | + throw new InternalErrorException(e); |
| 44 | + } catch (AttributeNotExistsException e) { |
| 45 | + throw new InternalErrorException(e); |
| 46 | + } catch (WrongReferenceAttributeValueException e) { |
| 47 | + throw new InternalErrorException(e); |
| 48 | + } catch (WrongAttributeValueException e) { |
| 49 | + throw new InternalErrorException(e); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public AttributeDefinition getAttributeDefinition() { |
| 54 | + AttributeDefinition attr = new AttributeDefinition(); |
| 55 | + attr.setNamespace(AttributesManager.NS_USER_ATTR_VIRT); |
| 56 | + attr.setFriendlyName("login-namespace:bbmri-test-persistent"); |
| 57 | + attr.setDisplayName("BBMRI TEST login"); |
| 58 | + attr.setType(String.class.getName()); |
| 59 | + attr.setDescription("Login to BBMRI TEST. It is set automatically with first call."); |
| 60 | + return attr; |
| 61 | + } |
| 62 | +} |
0 commit comments