use of eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_ in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method compileAtributeForStrategy.
/**
* Compile given attribute for strategy
*
* @param strategy
* @param defaultAttribute
* @param overloadingAttributes
*
* @return
*/
protected List<AttributeMapping> compileAtributeForStrategy(AttributeMappingStrategyType strategy, AttributeMapping defaultAttribute, List<SysRoleSystemAttributeDto> overloadingAttributes) {
List<AttributeMapping> finalAttributes = new ArrayList<>();
List<SysRoleSystemAttributeDto> attributesOrdered = overloadingAttributes.stream().filter(roleSystemAttribute -> {
// Search attribute override same schema attribute
SysSystemAttributeMappingDto attributeMapping = DtoUtils.getEmbedded(roleSystemAttribute, SysRoleSystemAttribute_.systemAttributeMapping.getName(), SysSystemAttributeMappingDto.class);
return attributeMapping.equals(defaultAttribute);
}).sorted((att1, att2) -> {
// Sort attributes by role priority
IdmRoleDto role1 = this.getRole(att1);
IdmRoleDto role2 = this.getRole(att2);
return Integer.compare(role2.getPriority(), role1.getPriority());
}).collect(Collectors.toList());
// We have some overloaded attributes
if (!attributesOrdered.isEmpty()) {
List<SysRoleSystemAttributeDto> attributesOrderedGivenStrategy = attributesOrdered.stream().filter(attribute -> {
return strategy == attribute.getStrategyType();
}).collect(Collectors.toList());
// We do not have overloaded attributes for given strategy
if (attributesOrderedGivenStrategy.isEmpty()) {
return finalAttributes;
}
// First element have role with max priority
IdmRoleDto roleForSetMaxPriority = this.getRole((AttributeMapping) attributesOrderedGivenStrategy.get(0));
int maxPriority = roleForSetMaxPriority.getPriority();
// We will search for attribute with highest priority (and role
// name)
Optional<SysRoleSystemAttributeDto> highestPriorityAttributeOptional = attributesOrderedGivenStrategy.stream().filter(attribute -> {
IdmRoleDto roleDto = this.getRole(attribute);
// Filter attributes by max priority
return maxPriority == roleDto.getPriority();
}).sorted((att1, att2) -> {
// Second filtering, if we have same priority, then
// we will sort by role name
IdmRoleDto roleDto1 = this.getRole(att1);
IdmRoleDto roleDto2 = this.getRole(att2);
//
return roleDto2.getCode().compareTo(roleDto1.getCode());
}).findFirst();
if (highestPriorityAttributeOptional.isPresent()) {
SysRoleSystemAttributeDto highestPriorityAttribute = highestPriorityAttributeOptional.get();
// overloaded attributes
if (strategy == AttributeMappingStrategyType.AUTHORITATIVE_MERGE || strategy == AttributeMappingStrategyType.MERGE) {
attributesOrderedGivenStrategy.forEach(attribute -> {
// Disabled attribute will be skipped
if (!attribute.isDisabledDefaultAttribute()) {
// Default values (values from schema attribute
// handling)
attribute.setSchemaAttribute(defaultAttribute.getSchemaAttribute());
attribute.setTransformFromResourceScript(defaultAttribute.getTransformFromResourceScript());
// Common properties (for MERGE strategy) will be
// set from MERGE attribute with highest priority
attribute.setSendAlways(highestPriorityAttribute.isSendAlways());
attribute.setSendOnlyIfNotNull(highestPriorityAttribute.isSendOnlyIfNotNull());
// Add modified attribute to final list
finalAttributes.add(attribute);
}
});
return finalAttributes;
}
// We will search for disabled overloaded attribute
Optional<SysRoleSystemAttributeDto> disabledOverloadedAttOptional = attributesOrderedGivenStrategy.stream().filter(attribute -> {
// Filter attributes by max priority
IdmRoleDto roleDto = this.getRole(attribute);
return maxPriority == roleDto.getPriority();
}).filter(attribute -> {
// overloaded attribute
return attribute.isDisabledDefaultAttribute();
}).findFirst();
if (disabledOverloadedAttOptional.isPresent()) {
// priority
return finalAttributes;
}
// Disabled attribute will be skipped
if (!highestPriorityAttribute.isDisabledDefaultAttribute()) {
// Default values (values from schema attribute handling)
highestPriorityAttribute.setSchemaAttribute(defaultAttribute.getSchemaAttribute());
highestPriorityAttribute.setCached(defaultAttribute.isCached());
highestPriorityAttribute.setTransformFromResourceScript(defaultAttribute.getTransformFromResourceScript());
// Add modified attribute to final list
finalAttributes.add(highestPriorityAttribute);
return finalAttributes;
}
}
}
if (!defaultAttribute.isDisabledAttribute() && strategy == defaultAttribute.getStrategyType()) {
finalAttributes.add(defaultAttribute);
}
return finalAttributes;
}
Aggregations