urn_perun_user_attribute_def_virt_tcsMails_mu extends UserVirtualAttributesModuleAbstract implements UserVirtualAttributesModuleImplApi { @Override public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) { Attribute attribute = new Attribute(attributeDefinition); SortedSet<String> tcsMailsValue = new TreeSet<>(); Set<String> compareSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); List<String> namesOfAttributes = Arrays.asList(A_U_D_preferredMail, A_U_D_ISMail, A_U_D_o365EmailAddressesMU, A_U_D_publicAliasMails, A_U_D_privateAliasMails); List<Attribute> sourceAttributes = sess.getPerunBl().getAttributesManagerBl().getAttributes(sess, user, namesOfAttributes); Map<String,Attribute> attributesMap = sourceAttributes.stream().collect(Collectors.toMap(Attribute::getName, Function.identity())); for (String attrName : namesOfAttributes) { Attribute sourceAttribute = attributesMap.get(attrName); if (sourceAttribute != null) { if (sourceAttribute.getType().equals(String.class.getName())) { if (sourceAttribute.getValue() != null) { if (!compareSet.contains(sourceAttribute.valueAsString().trim())) { compareSet.add(sourceAttribute.valueAsString().trim()); tcsMailsValue.add(sourceAttribute.valueAsString().trim()); } } } else if (sourceAttribute.getType().equals(ArrayList.class.getName())) { if (sourceAttribute.getValue() != null) { sourceAttribute.valueAsList().stream().map(String::trim).collect(Collectors.toList()).forEach(s -> { if (!compareSet.contains(s)) { compareSet.add(s); tcsMailsValue.add(s); } }); } } else { log.error("Unexpected type of attribute (should be String or ArrayList) {}. It will be skipped.", sourceAttribute); } } else { log.warn("When counting value of attribute {} we are missing source attribute {}. It will be skipped.", this.getAttributeDefinition(), attrName); } } attribute.setValue(new ArrayList<>(tcsMailsValue)); return attribute; }  @Override Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition); @Override List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message); @Override List<String> getStrongDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void getAttributeValue() { ArrayList<String> attributeValue = classInstance.getAttributeValue(sess, user, tcsMailsAttrDef).valueAsList(); assertNotNull(attributeValue); assertEquals(email1, attributeValue.get(0)); assertEquals(email2.trim(), attributeValue.get(1)); assertEquals(email3, attributeValue.get(2)); assertEquals(email4, attributeValue.get(3)); assertEquals(email5, attributeValue.get(4)); assertEquals(email6.trim().toLowerCase(), attributeValue.get(4)); assertEquals(5, attributeValue.size()); }