class urn_perun_user_attribute_def_virt_userOrganizations extends UserVirtualAttributesModuleAbstract implements UserVirtualAttributesModuleImplApi {

	@Override
	public Attribute getAttributeValue(PerunSessionImpl perunSession, User user, AttributeDefinition attributeDefinition) {
		Map<String, String> userOrganizations = new LinkedHashMap<>();
		List<Vo> vos = perunSession.getPerunBl().getUsersManagerBl().getVosWhereUserIsMember(perunSession, user);

		for (Vo vo : vos) {
			try {
				Member member = perunSession.getPerunBl().getMembersManagerBl().getMemberByUser(perunSession, vo, user);
				String value = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, member, A_M_organization).valueAsString();
				if (value != null) userOrganizations.put(vo.getShortName(), value);
			} catch (MemberNotExistsException e) {
				throw new ConsistencyErrorException(e);
			} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
				throw new InternalErrorException(e);
			}
		}

		Attribute attribute = new Attribute(attributeDefinition);
		attribute.setValue(userOrganizations);
		return attribute;
	}

}