class urn_perun_group_attribute_def_virt_adDisplayName_o365mu extends GroupVirtualAttributesModuleAbstract implements GroupVirtualAttributesModuleImplApi {

	@Override
	public Attribute getAttributeValue(PerunSessionImpl sess, Group group, AttributeDefinition attributeDefinition) {
		Attribute attribute = new Attribute(attributeDefinition);

		String defaultAdDisplayName = getStringValueOfGroupAttribute(sess, group, A_G_D_AD_DISPLAY_NAME_O365MU);
		if(defaultAdDisplayName != null) {
			//there is a default value and we can take it
			attribute.setValue(defaultAdDisplayName);
			return attribute;
		}

		//If there is no way to take default value, count a new one from other attributes (if possible)
		//if any of these values are null, return empty attribute instead
		String cispr = getStringValueOfGroupAttribute(sess, group, A_G_D_INET_CISPR);
		if (cispr == null) return attribute;
		String typeOfWorkplaces = getStringValueOfGroupAttribute(sess, group, A_G_D_INET_WORKPLACES_TYPE_CS);
		if (typeOfWorkplaces == null) return attribute;

		String finalName = null;
		Matcher partOfUniversityMatcher = partOfUniversityPattern.matcher(cispr);
		Matcher otherWorkplacesMatcher = otherWorkplacesPattern.matcher(cispr);

		//Now there is a hardcoded logic defined by the prefix of number in CISPR
		if (cispr.equals(TOP_LEVEL_GROUP_CISPR)) {
			//if this is top level group, use predefined name + type of workplaces (defined by specific tree where group exists)
			finalName = TOP_LEVEL_PREFIX + ", " + typeOfWorkplaces;
		} else if (partOfUniversityMatcher.matches()) {
			//if this workplace is part of university with cispr [1-9][1-9]0000, use name of group + type of workplaces
			String groupNameCS = getStringValueOfGroupAttribute(sess, group, A_G_D_INET_GROUP_NAME_CS);
			//we need not-null name of group to count this value correctly
			if(groupNameCS == null) return attribute;
			finalName = groupNameCS + ", " + typeOfWorkplaces;
		} else if (otherWorkplacesMatcher.matches()) {
			//other parts of university with expression as [1-9][0-9]{5}
			//for these groups we need to find parent group with part of university cispr and use also abbreviation for it in the final name
			String groupNameCS = getStringValueOfGroupAttribute(sess, group, A_G_D_INET_GROUP_NAME_CS);
			if (groupNameCS != null) {
				String abbreviation = getParentGroupAbbreviation(sess, group);
				//we can use abbreviation only if exists
				if (abbreviation != null) {
					finalName = groupNameCS + ", " + abbreviation + ", " + typeOfWorkplaces;
				} else {
					finalName = groupNameCS + ", " + typeOfWorkplaces;
				}
			}
		}

		//for other type of groups as ^[0][0-9]{5}$ (except 000000) we don't want to generate any displayName

		attribute.setValue(finalName);
		return attribute;
	}

}