We pull a lot of our data from an authoritative source into various attributes in our environment.
One of those attributes we have is "jobTitle" - as the name suggests, it's an identity's respective job title at the organization.
One of my primary jobs is to create Assignment Rules for Roles at the organization and I've run into an issue that I believe can be done more efficiently, but am missing the java knowledge
So here's the problem:
We use the following Java line to "get" any specific jobTitle in our org that has Nurse in it: identity.getAttribute("jobTitle").contains("Nurse");
My question for you Java experts - is there a way I utilize wildcards where I can pull all job titles that contain %Nursing%Specialist% or %Nursing%Coordinator% ..
So if I wanted to provision the role to all users who have a jobTitle of "Nursing Professional Development Specialist" or "Nursing Resource Coordinator" for example where the words Coordinator and Specialist could possibly be separated by other strings.
Is there an efficient way in Java to overcome this challenge?
For example-
Currently are returning true if the following match:
return "Nursing Care Coordinator".equalsIgnoreCase(identity.getAttribute("jobTitle")) || "Nursing Resource Coordinator".equalsIgnoreCase(identity.getAttribute("jobTitle")) || "Nursing Practice Specialist".equalsIgnoreCase(identity.getAttribute("jobTitle")) || "Nursing Professional Development Specialist".equalsIgnoreCase(identity.getAttribute("jobTitle"));
%Nursing%Specialist% - those % could be other strings such as Professional Nursing Development Specialist , so just trying to make sure all necessary job titles get the correct roles. Would like to not have to be able to type out every specific job title!!
You can do it efficiently for the programmer (one expression) using regex. To match "Nurse" or "Nursing .... Specialist" or "Nursing .... Coordinator":
identity.getAttribute("jobTitle")
.matches("^(?=Nurse$|Nursing.*(Coordinator|Specialist)$).*")
and it's reasonably efficient for the machine.
See live demo for a full explanation of the regex.
If you just wanted to assert that the terms appear in any order, you would use two look aheads - one for each term:
matches("^(?=.*Nurs(e|ing))(?=.*(Coordinator|Specialist)).*")