====== Get manager of users ======
This script can be used as a transformation script to the system - in the provisioning mapping. The script will return the direct manager of the prime contract of a user.
===== Script =====
import eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto;
import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;
import eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter;
org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger("customGetManager");
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(entity.getId());
if (primeContract == null) {
LOG.warn("User {} doesn't have any contract.", entity.getUsername());
return null;
}
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setManagersFor(entity.getId());
filter.setManagersByContract(primeContract.getId());
List managers = identityService.find(filter, null).getContent();
if (managers == null || managers.isEmpty()) {
LOG.info("Cannot find manager for contract {} of the user {}", primeContract.getId(), entity.getUsername());
return null;
} else if (managers.size()> 1) {
// TODO process multiple managers differently, if needed
LOG.warn("Multiple managers found for contract {} of the user {}, using the first manager {}",
primeContract.getId(), entity.getUsername(), managers.get(0).getUsername());
}
IdmIdentityDto managerForContract = managers.get(0);
String managerUsername = managerForContract.getUsername();
return managerUsername;
===== Script authorities =====
Service
identityContractService
identityService
Class
eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter
eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto
eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto
org.springframework.data.domain.PageImpl