class urn_perun_user_attribute_def_virt_userCertificatesLimited extends UserVirtualAttributesModuleAbstract implements UserVirtualAttributesModuleImplApi {

	@Override
	public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) {
		Attribute resultAttribute = new Attribute(attributeDefinition);
		List<String> result = new ArrayList<>();

		Attribute userCertsAttribute = getUserCertsAttribute(sess, user);
		Map<String,String> certs = userCertsAttribute.valueAsMap();
		if (certs != null) {
			Map<String, String> certsExpiration = ModulesUtilsBlImpl.retrieveCertificatesExpiration(certs);

			DateFormat dateFormatInstance = DateFormat.getDateInstance();

			Map<String, Long> certsExpirationInMilliSeconds = new HashMap<>();
			certsExpiration.forEach((key, value) -> {
				try {
					certsExpirationInMilliSeconds.put(key, dateFormatInstance.parse(value).getTime());
				} catch (ParseException ex) {
					throw new ConsistencyErrorException(ex);
				}
			});

			certsExpirationInMilliSeconds.entrySet().stream()
				.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
				.limit(10)
				.forEachOrdered(entry -> result.add(certs.get(entry.getKey())));

			Utils.copyAttributeToViAttributeWithoutValue(userCertsAttribute, resultAttribute);
		}

		resultAttribute.setValue(result);

		return resultAttribute;
	}

}