class urn_perun_user_facility_attribute_def_def_accountExpirationTime extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi {

	@Override
	public Attribute fillAttribute(PerunSessionImpl perunSession, User user, Facility facility, AttributeDefinition attribute) throws WrongAttributeAssignmentException {
		Attribute ret = new Attribute(attribute);
		List<Integer> resourcesExpTimes = new ArrayList<>();
		Integer resourceExpTime;
		for (Resource r : perunSession.getPerunBl().getUsersManagerBl().getAllowedResources(perunSession, facility, user)) {
			try { //getting all resources at which user has access
				resourceExpTime = (Integer) perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, r, attribute.getName()).getValue();
				if (resourceExpTime != null) {
					resourcesExpTimes.add(resourceExpTime);
				}
			} catch (AttributeNotExistsException ex) {
				throw new InternalErrorException(ex);
			}
		}
		Integer facilityAccExpTime;
		try {
			facilityAccExpTime = (Integer) perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, attribute.getName()).getValue();
		} catch (AttributeNotExistsException ex) {
			throw new InternalErrorException(ex);
		}
		if (facilityAccExpTime != null) {
			resourcesExpTimes.add(facilityAccExpTime);
		}
		ret.setValue(Collections.min(resourcesExpTimes));
		return ret;
	}

}