urn_perun_user_attribute_def_virt_eduPersonScopedAffiliations extends UserVirtualAttributeCollectedFromUserExtSource { @Override public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message) throws WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException { List<AuditEvent> resolvingMessages = super.resolveVirtualAttributeValueChange(perunSession, message); if (message instanceof AttributeSetForUser && ((AttributeSetForUser) message).getAttribute().getFriendlyName().equals(getSecondarySourceAttributeFriendlyName())) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeSetForUser) message).getUser())); } else if (message instanceof AttributeRemovedForUser && ((AttributeRemovedForUser) message).getAttribute().getFriendlyName().equals(getSecondarySourceAttributeFriendlyName())) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeRemovedForUser) message).getUser())); } else if (message instanceof AllAttributesRemovedForUser) { boolean skip = false; try { AttributeDefinition sourceExists = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getSecondarySourceAttributeName()); User user = perunSession.getPerunBl().getUsersManagerBl().getUserById(perunSession, ((AllAttributesRemovedForUser) message).getUser().getId()); } catch (AttributeNotExistsException | UserNotExistsException ex) { skip = true; } if (!skip) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AllAttributesRemovedForUser) message).getUser())); } } if (message instanceof AttributeSetForGroup && !VosManager.MEMBERS_GROUP.equals(((AttributeSetForGroup) message).getGroup().getName()) && ((AttributeSetForGroup) message).getAttribute().getName().equals(getTertiarySourceAttributeName())) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AttributeSetForGroup) message).getGroup()); for (User user : users) { resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user)); } } else if (message instanceof AttributeRemovedForGroup && !VosManager.MEMBERS_GROUP.equals(((AttributeRemovedForGroup) message).getGroup().getName()) && ((AttributeRemovedForGroup) message).getAttribute().getName().equals(getTertiarySourceAttributeName())) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AttributeRemovedForGroup) message).getGroup()); for (User user : users) { resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user)); } } else if (message instanceof AllAttributesRemovedForGroup && !VosManager.MEMBERS_GROUP.equals(((AllAttributesRemovedForGroup) message).getGroup().getName())) { boolean skip = false; try { AttributeDefinition sourceExists = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getTertiarySourceAttributeName()); Group group = perunSession.getPerunBl().getGroupsManagerBl().getGroupById(perunSession, ((AllAttributesRemovedForGroup) message).getGroup().getId()); } catch (AttributeNotExistsException | GroupNotExistsException ex) { skip = true; } if (!skip) { AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName()); List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AllAttributesRemovedForGroup) message).getGroup()); for (User user : users) { resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user)); } } } return resolvingMessages; }  @Override String getSourceAttributeFriendlyName(); String getSecondarySourceAttributeFriendlyName(); String getSecondarySourceAttributeName(); String getTertiarySourceAttributeFriendlyName(); String getTertiarySourceAttributeName(); @Override String getDestinationAttributeFriendlyName(); @Override Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition destinationAttributeDefinition); @Override List<AttributeHandleIdentifier> getHandleIdentifiers(); @Override List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message);  }
@Test public void resolveAttributeValueChangeTest() throws Exception { when(session.getPerunBl().getUsersManagerBl().getUserById(session, 1)).thenReturn(user); AuditEvent event = new AllAttributesRemovedForUserExtSource(ues1); List<AuditEvent> auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event); assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class); event = new AllAttributesRemovedForUser(user); auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event); assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class); Attribute attribute = new Attribute(); attribute.setFriendlyName("eduPersonScopedAffiliationsManuallyAssigned"); event = new AttributeSetForUser(attribute, user); auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event); assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class); when(session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_VIRT + ":" + "eduPersonScopedAffiliations")).thenReturn(attribute); auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event); assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class); }