newUserCreate.bpmn20.xml revision a60d77aaed3324cd783f4e648fedfecd54f8e551
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.omg.org/spec/BPMN/20100524/MODEL http://local.openicf.forgerock.org/BPMN20.xsd">
<process id="newUserCreate" name="User onboarding process">
<startEvent id="start" activiti:initiator="startUserId" >
<extensionElements>
<activiti:formProperty id="_formGenerationTemplate" type="string" default="
&lt;style&gt;
#processDetails fieldset {
margin-top: 0;
}
#processDetails .group-field {
float: left !important;
width: 100%;
}
#processDetails .field label {
text-align: left;
}
#processDetails .field input,#processDetails .field select {
clear: both;
}
#processDetails .field .validation-message {
clear: none !important;
margin-left: 20px !important;
float: left !important;
}
&lt;/style&gt;
&lt;h2 class=&quot;header&quot;&gt;User Details&lt;/h2&gt;
&lt;fieldset&gt;
&lt;div class=&quot;fields&quot;&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.username&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;userName&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.givenName&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;givenName&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.familyName&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;familyName&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.emailAddress&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Country&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;country&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;City&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;city&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;State&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;stateProvince&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Postal Code&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;postalCode&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Address&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;address1&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.phoneNumber&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;phoneNumber&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Department&lt;/label&gt;
&lt;select name=&quot;department&quot;&gt;
&lt;option value=&quot;Human Resources&quot;&gt;Human Resources&lt;/option&gt;
&lt;option value=&quot;Production Planning&quot;&gt;Production Planning&lt;/option&gt;
&lt;option value=&quot;Sales &amp; Distribution&quot;&gt;Sales &amp; Distribution&lt;/option&gt;
&lt;option value=&quot;Treasury &amp; Payments&quot;&gt;Treasury &amp; Payments&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Employee Number&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;employeeNumber&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Display Name&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;displayName&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;User Type&lt;/label&gt;
&lt;select name=&quot;userType&quot;&gt;
&lt;option value=&quot;employee&quot;&gt;Employee&lt;/option&gt;
&lt;option value=&quot;contractor&quot;&gt;Contractor&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/fieldset&gt;
&lt;script&gt;
require([&quot;org/forgerock/commons/ui/common/main/ValidatorsManager&quot;], function (v) {
v.bindValidators($(&apos;#processDetails form&apos;), &quot;managed/user/&quot;);
});
&lt;/script&gt;
"/>
<activiti:formProperty id="userName"
name="Username"
required="true"
type="string" />
<activiti:formProperty id="givenName"
name="First Name"
required="true"
type="string" />
<activiti:formProperty id="familyName"
name="Last Name"
required="true"
type="string" />
<activiti:formProperty id="email"
name="Email"
required="true"
type="string" />
<activiti:formProperty id="country"
name="Country"
type="string" />
<activiti:formProperty id="city"
name="City"
type="string" />
<activiti:formProperty id="stateProvince"
name="State"
type="string" />
<activiti:formProperty id="postalCode"
name="Postal Code"
type="string" />
<activiti:formProperty id="address1"
name="Address"
type="string" />
<activiti:formProperty id="phoneNumber"
name="Phone Number"
required="true"
type="string" />
<activiti:formProperty id="department"
name="Department"
required="true"
type="enum">
<activiti:value id="Human Resources" name="Human Resources"/>
<activiti:value id="Production Planning" name="Production Planning"/>
<activiti:value id="Sales &amp; Distribution" name="Sales &amp; Distribution"/>
<activiti:value id="Treasury &amp; Payments" name="Treasury &amp; Payments"/>
</activiti:formProperty>
<activiti:formProperty id="employeeNumber"
name="Employee number"
required="true"
type="string" />
<activiti:formProperty id="displayName"
name="Display Name"
required="true"
type="string" />
<activiti:formProperty id="userType"
name="User Type"
required="true"
type="enum" >
<activiti:value id="employee" name="Employee"/>
<activiti:value id="contractor" name="Contractor"/>
</activiti:formProperty>
</extensionElements>
</startEvent>
<sequenceFlow sourceRef="start" targetRef="decisionPrep"/>
<scriptTask id="decisionPrep" name="Prepare Task" scriptFormat="groovy">
<script><![CDATA[
params = [_queryExpression:"select * from managed_user where title='manager' and department='"+department+"'"];
manager = openidm.query("managed/user", params)
StringBuilder builder = new StringBuilder();
for (String string : manager.result._id) {
if (builder.length() > 0) {
builder.append(",");
}
builder.append(string);
}
candidateUsers = builder.toString();
]]>
</script>
</scriptTask>
<sequenceFlow sourceRef="decisionPrep" targetRef="decideApprovalTask"/>
<userTask id="decideApprovalTask" name="Onboarding Approval" activiti:candidateUsers="${candidateUsers}">
<extensionElements>
<activiti:formProperty id="_formGenerationTemplate" type="string" default="
&lt;style&gt;
#taskDetails fieldset {
margin-top: 0;
}
#taskDetails .group-field {
float: left !important;
width: 100%;
}
#taskDetails .field label {
text-align: left;
}
#taskDetails .field input,#taskDetails .field select {
clear: both;
}
#taskDetails .field .validation-message {
clear: none !important;
margin-left: 20px !important;
float: left !important;
}
&lt;/style&gt;
&lt;h2 class=&quot;header&quot;&gt;User Approval&lt;/h2&gt;
&lt;fieldset&gt;
&lt;div class=&quot;fields&quot;&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.username&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;userName&quot; value=&quot;{{variables.userName}}&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.givenName&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;givenName&quot; value=&quot;{{variables.givenName}}&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.familyName&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;familyName&quot; value=&quot;{{variables.familyName}}&quot; data-validation-dependents=&quot;password&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.emailAddress&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;{{variables.email}}&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Country&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;country&quot; value=&quot;{{variables.country}}&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;City&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;city&quot; value=&quot;{{variables.city}}&quot;/&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;State&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;stateProvince&quot; value=&quot;{{variables.stateProvince}}&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Postal Code&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;postalCode&quot; value=&quot;{{variables.postalCode}}&quot;/&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Address&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;address1&quot; value=&quot;{{variables.address1}}&quot;/&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;{{t &quot;common.user.phoneNumber&quot;}}&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;phoneNumber&quot; value=&quot;{{variables.phoneNumber}}&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Department&lt;/label&gt;
&lt;select name=&quot;department&quot;&gt;
&lt;option value=&quot;Human Resources&quot;&gt;Human Resources&lt;/option&gt;
&lt;option value=&quot;Production Planning&quot;&gt;Production Planning&lt;/option&gt;
&lt;option value=&quot;Sales &amp; Distribution&quot;&gt;Sales &amp; Distribution&lt;/option&gt;
&lt;option value=&quot;Treasury &amp; Payments&quot;&gt;Treasury &amp; Payments&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Start Date (yyyy-MM-dd)&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;startDate&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;End Date (yyyy-MM-dd)&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;endDate&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Employee Number&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;employeeNumber&quot; value=&quot;{{variables.employeeNumber}}&quot; /&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Display Name&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;displayName&quot; value=&quot;{{{variables.displayName}}}&quot;/&gt;
&lt;span class=&quot;error&quot;&gt;x&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;User Type&lt;/label&gt;
&lt;select name=&quot;userType&quot;&gt;
&lt;option value=&quot;employee&quot;&gt;Employee&lt;/option&gt;
&lt;option value=&quot;contractor&quot;&gt;Contractor&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label&gt;Manager&lt;/label&gt;
&lt;select name=&quot;title&quot;&gt;
&lt;option value=&quot;yes&quot;&gt;Yes&lt;/option&gt;
&lt;option value=&quot;no&quot;&gt;No&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;label class=&quot;light&quot;&gt;{{t &quot;common.form.decision&quot;}}&lt;/label&gt;
&lt;select name=&quot;decision&quot; &quot; data-validator='required' &quot; &gt;
&lt;option value=&quot;accept&quot;&gt;Accept&lt;/option&gt;
&lt;option value=&quot;reject&quot;&gt;Reject&lt;/option&gt;
&lt;/select&gt;
&lt;span class=&quot;ok&quot; style=&quot;&quot;&gt;✔&lt;/span&gt;
&lt;div class=&quot;validation-message&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/fieldset&gt;
&lt;script&gt;
$(&apos;#taskDetails form select[name=department]&apos;).val(&quot;{{{variables.department}}}&quot;);
$(&apos;#taskDetails form select[name=userType]&apos;).val(&quot;{{variables.userType}}&quot;);
{{#if assignee}}
require([&quot;org/forgerock/commons/ui/common/main/ValidatorsManager&quot;], function (v) {
v.bindValidators($(&apos;#taskDetails form&apos;), &quot;managed/user/&quot;, function () {
v.validateAllFields($(&apos;#taskDetails form&apos;));
});
});
{{/if}}
&lt;/script&gt;
"/>
<activiti:formProperty id="userName"
name="Username"
required="true"
type="string" />
<activiti:formProperty id="givenName"
name="First Name"
required="true"
type="string" />
<activiti:formProperty id="familyName"
name="Last Name"
required="true"
type="string" />
<activiti:formProperty id="email"
name="Email"
required="true"
type="string" />
<activiti:formProperty id="country"
name="Country"
type="string" />
<activiti:formProperty id="city"
name="City"
required="true"
type="string" />
<activiti:formProperty id="stateProvince"
name="State"
type="string" />
<activiti:formProperty id="postalCode"
name="Postal Code"
required="true"
type="string" />
<activiti:formProperty id="address1"
name="Address"
required="true"
type="string" />
<activiti:formProperty id="phoneNumber"
name="Phone Number"
required="true"
type="string" />
<activiti:formProperty id="department"
name="Department"
required="true"
type="enum">
<activiti:value id="Human Resources" name="Human Resources"/>
<activiti:value id="Production Planning" name="Production Planning"/>
<activiti:value id="Sales &amp; Distribution" name="Sales &amp; Distribution"/>
<activiti:value id="Treasury &amp; Payments" name="Treasury &amp; Payments"/>
</activiti:formProperty>
<activiti:formProperty id="startDate"
name="Start Date (yyyy-MM-dd)"
type="string"/>
<activiti:formProperty id="endDate"
name="End Date (yyyy-MM-dd)"
type="string" />
<activiti:formProperty id="employeeNumber"
name="Employee number"
required="true"
type="string" />
<activiti:formProperty id="displayName"
name="Display Name"
required="true"
type="string" />
<activiti:formProperty id="userType"
name="User Type"
required="true"
type="enum" >
<activiti:value id="employee" name="Employee"/>
<activiti:value id="contractor" name="Contractor"/>
</activiti:formProperty>
<activiti:formProperty id="title"
name="Manager"
required="true"
type="enum" >
<activiti:value id="yes" name="Yes"/>
<activiti:value id="no" name="No"/>
</activiti:formProperty>
<activiti:formProperty id="decision" name="Decision" type="enum" required="true">
<activiti:value id="accept" name="Accept"></activiti:value>
<activiti:value id="reject" name="Reject"></activiti:value>
</activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow sourceRef="decideApprovalTask" targetRef="decisionMadeGateway"></sequenceFlow>
<exclusiveGateway id="decisionMadeGateway" name="Decision Made"></exclusiveGateway>
<sequenceFlow sourceRef="decisionMadeGateway" targetRef="createManagedUser">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[ ${decision=='accept'} ]]>
</conditionExpression>
</sequenceFlow>
<scriptTask id="createManagedUser" scriptFormat="groovy">
<script>
<![CDATA[
user = [_id:userName, userName:userName, givenName:givenName, familyName:familyName,
email:email, country:country, city:city, stateProvince:stateProvince,
postalCode:postalCode, address1:address1, phoneNumber:phoneNumber,
department:department, employeeNumber:employeeNumber, displayName:displayName,
userType:userType, password:"Passw0rd"]
if (title == 'yes') {
userTitle = 'manager'
user.put("title", userTitle)
}
if (userType=='employee') {
accountsList = ["Business"]
user.put("accounts", accountsList)
}
java.text.SimpleDateFormat formatUTCDate = new java.text.SimpleDateFormat("yyyy-MM-dd");
formatUTCDate.setTimeZone(TimeZone.getTimeZone("UTC"));
java.text.SimpleDateFormat formatUTC = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
if (startDate != "") {
startDateISO = formatUTC.format(formatUTCDate.parse(startDate))
sunriseMap = [date:startDateISO.toString()]
user.put("sunrise", sunriseMap)
user.put("accountStatus", "inactive")
}
if (endDate != "") {
endDateISO = formatUTC.format(formatUTCDate.parse(endDate))
sunsetMap = [date:endDateISO.toString()]
user.put("sunset", sunsetMap)
}
assignedManager = manager.result[0]
managerMap = [displayName:assignedManager.displayName, managerId:assignedManager._id]
managerMap.put('$ref', "managed/user/"+assignedManager._id)
user.put("manager", managerMap)
openidm.create('managed/user', user)
readNewUserFromRepoParams = [_queryId:'for-userName',uid:userName]
]]>
</script>
</scriptTask>
<sequenceFlow sourceRef="createManagedUser" targetRef="serviceTask"/>
<serviceTask id="serviceTask" activiti:expression="${openidm.query('managed/user', readNewUserFromRepoParams)}"
activiti:resultVariableName="newUserFromRepo"/>
<sequenceFlow sourceRef="serviceTask" targetRef="sendAcceptNotification"/>
<scriptTask id="sendAcceptNotification" scriptFormat="groovy">
<script>
java.text.SimpleDateFormat formatUTC = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
requestDate = formatUTC.format(new Date());
def newRequesterNotification = [
"receiverId": "hradmin",
"requesterId" : "",
"requester" : "",
"createDate" : requestDate,
"notificationType" : "info",
"notificationSubtype" : "",
"message" : "The requested user " + userName + " was successfully created"
];
def newContractorNotification = [
"receiverId": newUserFromRepo.result[0]._id,
"requesterId" : "",
"requester" : "",
"createDate" : requestDate,
"notificationType" : "info",
"notificationSubtype" : "",
"message" : "Welcome! Your work days are from " + startDate + " to " + endDate
];
openidm.create("repo/ui/notification/", newRequesterNotification)
openidm.create("repo/ui/notification/", newContractorNotification)
</script>
</scriptTask>
<sequenceFlow sourceRef="sendAcceptNotification" targetRef="end"/>
<sequenceFlow sourceRef="decisionMadeGateway" targetRef="sendDenyNotification">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[ ${decision=='reject'} ]]>
</conditionExpression>
</sequenceFlow>
<scriptTask id="sendDenyNotification" scriptFormat="groovy">
<script>
java.text.SimpleDateFormat formatUTC = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
requestDate = formatUTC.format(new Date());
def newRequesterNotification = [
"receiverId": "hradmin",
"requesterId" : "",
"requester" : "",
"createDate" : requestDate,
"notificationType" : "warning",
"notificationSubtype" : "",
"message" : "Your request to create user " + userName + " was denied."
];
openidm.create("repo/ui/notification/", newRequesterNotification)
</script>
</scriptTask>
<sequenceFlow sourceRef="sendDenyNotification" targetRef="end"/>
<endEvent id="end"/>
</process>
</definitions>