Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Introduction

Each Core Identity can have zero to N employments, whereas an employment is the combination of an organizational unit assignment, an optional function, an optional employment type, a validity range and optional attributes.

Properties

Whenever you are creating or updating an emplyoment, you have to specify the following properties:

Property

Data Type

Mandatory

Example

Description

Valid From

Date

(tick)

1.1.2022

When the employment validity starts

Valid To

Date

31.12.2030

When the employment validity ends

Employment Number

Int

(tick)

1

A unique number of the employment

Percentage

Int

100

The employments percentage. Will affect the main employment calculation.

Function

DropDown

CEO

The associated function.

Organizational Unit

DropDown

(tick)

ITSENSE AG

The organizational assignment.

Employment Type

DropDown

Intern

The associated employment type.

State

DropDown

(tick)

Active

The state of the employment.

Main Employment

Bool

True

Indicates if this is the main employment or not.

Main Employment

If a person has more than one employment, there is often a need to determinate its main employment. This is can be used in many places such as mappings. For example a Core Identity can have two emplyoments but you would like to provision its job title to a target system. In order to determinate the job title, the main employment is used.

The rules to choose the main employment are as following:

Only consider employments, which are not in state “deleted”, then:

  • Main Employment is set

  • Order by

    • Valid From and not expired

    • Percentage

    • Has valid to

    • Valid to

    • Id

The actual implementation might clear up any remaining questions:

return employments
    .Where(a => a.EmploymentState.Id != (uint)CoreIdentityEmploymentStates.Deleted)
    .OrderByDescending(a => a.EmploymentState.Id)
    .ThenByDescending(a => a.MainEmployment)
    .ThenByDescending(a => a.ValidFrom <= DateTime.Now && (!a.ValidTo.HasValue || a.ValidTo.Value >= DateTime.Now.Date))
    .ThenByDescending(a => a.Percentage)
    .ThenBy(a => a.ValidFrom)
    .ThenBy(a => a.ValidTo.HasValue)
    .ThenBy(a => a.ValidTo)
    .ThenBy(a => a.Id);

If this logic is needed in the new Elsa Workflow Engine a JavaScript representation would look like this:

function employmentSorter(a, b) {
    var boolA = a.employment_state.system_name == "Deleted";
    var boolB = b.employment_state.system_name == "Deleted";
    if (boolA && !boolB) {
        return 1;
    } else if (!boolA && boolB) {
        return -1;
    } else {
        if (a.employment_state.id > b.employment_state.id) {
            return -1;
        } else if (a.employment_state.id < b.employment_state.id) {
            return 1;
        } else {
            if (a.main_employment && !b.main_employment) {
                return -1;
            } else if (!a.main_employment && b.main_employment) {
                return 1;
            } else {
                var today = new Date(Date.now());
                boolA = new Date(a.valid_from) <= today && (!a.valid_to || new Date(a.valid_to) >= today);
                boolB = new Date(b.valid_from) <= today && (!b.valid_to || new Date(b.valid_to) >= today);
                if (boolA && !boolB) {
                    return -1;
                } else if (!boolA && boolB) {
                    return 1;
                } else {
                    if (a.percentage > b.percentage) {
                        return -1;
                    } else if (a.percentage < b.percentage) {
                        return 1;
                    } else {
                        if (a.valid_from < b.valid_from) {
                            return -1;
                        } else if (a.valid_from > b.valid_from) {
                            return 1;
                        } else {
                            if (a.valid_to && !b.valid_to) {
                                return -1;
                            } else if (!a.valid_to && b.valid_to) {
                                return 1;
                            } else {
                                if (new Date(a.valid_to) < new Date(b.valid_to)) {
                                    return -1;
                                } else if (new Date(a.valid_to) > new Date(b.valid_to)) {
                                    return 1;
                                } else {
                                    if (a.id < b.id) {
                                        return -1;
                                    } else if (a.id > b.id) {
                                        return 1;
                                    } else {
                                        return 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

So given an employment Array as a result of a GetAllCoreIdentityEmploymentActivity (with loaded properties valid_from, valid_to, percentage, id, main_employment; and loaded attributes employment_state.id, employment_state.system_name), it can be sorted like this:

employments.sort(employmentSorter);

After this sort, the main employment is at employments[0]

  • No labels