Source code used in the demo
controllers.xml
import-custs.xml
/integration/check-custs.js
checkCusts
check-custs.js
function checkCusts(firstName, surName, phone, email) {
var matchReq = userManager.newProfileMatchRequest().or();
// this will return all profiles matching all given non-blank params
if( email ) {
matchReq.newSubCriteria().and()
.firstName(firstName)
.email(email);
}
if( phone ) {
matchReq.newSubCriteria().and()
.firstName(firstName)
.phone(phone);
}
var matched = userManager.findMatching(matchReq);
log.info("Matched {} profiles", matched.size());
if( matched.size() == 0 ) {
nextStep.exec(firstName, surName, phone, email, null);
} else if( matched.size() == 1) {
var existing = matched.get(0);
nextStep.exec(firstName, surName, phone, email, existing.userName);
} else {
// Choose the first as the merge target. Merge others into that, and then continue with it
var mergeDest = matched.get(0);
matched.remove(0);
userManager.mergeProfiles(mergeDest, matched);
nextStep.exec(firstName, surName, phone, email, mergeDest.userName);
}
}
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro labore architecto fuga tempore omnis aliquid, rerum numquam deleniti ipsam earum velit aliquam deserunt, molestiae officiis mollitia accusantium suscipit fugiat esse magnam eaque cumque, iste corrupti magni? Illo dicta saepe, maiores fugit aliquid consequuntur aut, rem ex iusto dolorem molestias obcaecati eveniet vel voluptatibus recusandae illum, voluptatem! Odit est possimus nesciunt.