Skip to content

Commit

Permalink
fix: ts push profile action after jamal review
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdellahitech committed Jan 29, 2024
1 parent d4a5ca2 commit e47fe74
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 108 deletions.
21 changes: 10 additions & 11 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3929,23 +3929,22 @@
"target": "TalentSoft Profiles",
"target_parameters": {
"title": "WriteProfileParameters",
"description": "Parameters for write action",
"type": "object",
"properties": {
"client_id_front": {
"title": "Client Id Front",
"client_id": {
"title": "Client Id",
"description": "client id used to access TalentSoft front office API",
"field_type": "Auth",
"type": "string"
},
"client_secret_front": {
"title": "Client Secret Front",
"client_secret": {
"title": "Client Secret",
"description": "client secret used to access TalentSoft front office API",
"field_type": "Auth",
"type": "string"
},
"client_url_front": {
"title": "Client Url Front",
"client_url": {
"title": "Client Url",
"description": "url used to access TalentSoft front office API",
"field_type": "Auth",
"type": "string"
Expand All @@ -3958,9 +3957,9 @@
}
},
"required": [
"client_id_front",
"client_secret_front",
"client_url_front"
"client_id",
"client_secret",
"client_url"
],
"additionalProperties": false
},
Expand All @@ -3969,7 +3968,7 @@
"type": "object",
"properties": {}
},
"workflow_code": "import typing as t\n\nfrom hrflow_connectors import TalentSoft\nfrom hrflow_connectors.core.connector import ActionInitError, Reason\n\nORIGIN_SETTINGS_PREFIX = \"origin_\"\nTARGET_SETTINGS_PREFIX = \"target_\"\n\n# << format_placeholder >>\n\n# << logics_placeholder >>\n\n# << event_parser_placeholder >>\n\n\ndef workflow(\n \n _request: t.Dict,\n \n settings: t.Dict\n ) -> None:\n actions_parameters = dict()\n try:\n format\n except NameError:\n pass\n else:\n actions_parameters[\"format\"] = format\n\n try:\n logics\n except NameError:\n pass\n else:\n actions_parameters[\"logics\"] = logics\n\n if \"__workflow_id\" not in settings:\n return TalentSoft.push_profile(\n workflow_id=\"\",\n action_parameters=dict(),\n origin_parameters=dict(),\n target_parameters=dict(),\n init_error=ActionInitError(\n reason=Reason.workflow_id_not_found,\n data=dict(error=\"__workflow_id not found in settings\", settings_keys=list(settings.keys())),\n )\n )\n workflow_id = settings[\"__workflow_id\"]\n\n \n try:\n event_parser\n _event_parser = event_parser\n except NameError as e:\n action = TalentSoft.model.action_by_name(\"push_profile\")\n # Without this trick event_parser is always only fetched from the local scope\n # meaning that try block always raises NameError even if the function is\n # defined in the placeholder\n _event_parser = action.parameters.__fields__[\"event_parser\"].default\n\n if _event_parser is not None:\n try:\n _request = _event_parser(_request)\n except Exception as e:\n return TalentSoft.push_profile(\n workflow_id=workflow_id,\n action_parameters=dict(),\n origin_parameters=dict(),\n target_parameters=dict(),\n init_error=ActionInitError(\n reason=Reason.event_parsing_failure,\n data=dict(error=e, event=_request),\n )\n )\n \n\n origin_parameters = dict()\n for parameter in ['api_secret', 'api_user', 'source_key', 'profile_key']:\n if \"{}{}\".format(ORIGIN_SETTINGS_PREFIX, parameter) in settings:\n origin_parameters[parameter] = settings[\"{}{}\".format(ORIGIN_SETTINGS_PREFIX, parameter)]\n \n if parameter in _request:\n origin_parameters[parameter] = _request[parameter]\n \n\n target_parameters = dict()\n for parameter in ['client_id_front', 'client_secret_front', 'client_url_front', 'job_reference']:\n if \"{}{}\".format(TARGET_SETTINGS_PREFIX, parameter) in settings:\n target_parameters[parameter] = settings[\"{}{}\".format(TARGET_SETTINGS_PREFIX, parameter)]\n \n if parameter in _request:\n target_parameters[parameter] = _request[parameter]\n \n\n return TalentSoft.push_profile(\n workflow_id=workflow_id,\n action_parameters=actions_parameters,\n origin_parameters=origin_parameters,\n target_parameters=target_parameters,\n )",
"workflow_code": "import typing as t\n\nfrom hrflow_connectors import TalentSoft\nfrom hrflow_connectors.core.connector import ActionInitError, Reason\n\nORIGIN_SETTINGS_PREFIX = \"origin_\"\nTARGET_SETTINGS_PREFIX = \"target_\"\n\n# << format_placeholder >>\n\n# << logics_placeholder >>\n\n# << event_parser_placeholder >>\n\n\ndef workflow(\n \n _request: t.Dict,\n \n settings: t.Dict\n ) -> None:\n actions_parameters = dict()\n try:\n format\n except NameError:\n pass\n else:\n actions_parameters[\"format\"] = format\n\n try:\n logics\n except NameError:\n pass\n else:\n actions_parameters[\"logics\"] = logics\n\n if \"__workflow_id\" not in settings:\n return TalentSoft.push_profile(\n workflow_id=\"\",\n action_parameters=dict(),\n origin_parameters=dict(),\n target_parameters=dict(),\n init_error=ActionInitError(\n reason=Reason.workflow_id_not_found,\n data=dict(error=\"__workflow_id not found in settings\", settings_keys=list(settings.keys())),\n )\n )\n workflow_id = settings[\"__workflow_id\"]\n\n \n try:\n event_parser\n _event_parser = event_parser\n except NameError as e:\n action = TalentSoft.model.action_by_name(\"push_profile\")\n # Without this trick event_parser is always only fetched from the local scope\n # meaning that try block always raises NameError even if the function is\n # defined in the placeholder\n _event_parser = action.parameters.__fields__[\"event_parser\"].default\n\n if _event_parser is not None:\n try:\n _request = _event_parser(_request)\n except Exception as e:\n return TalentSoft.push_profile(\n workflow_id=workflow_id,\n action_parameters=dict(),\n origin_parameters=dict(),\n target_parameters=dict(),\n init_error=ActionInitError(\n reason=Reason.event_parsing_failure,\n data=dict(error=e, event=_request),\n )\n )\n \n\n origin_parameters = dict()\n for parameter in ['api_secret', 'api_user', 'source_key', 'profile_key']:\n if \"{}{}\".format(ORIGIN_SETTINGS_PREFIX, parameter) in settings:\n origin_parameters[parameter] = settings[\"{}{}\".format(ORIGIN_SETTINGS_PREFIX, parameter)]\n \n if parameter in _request:\n origin_parameters[parameter] = _request[parameter]\n \n\n target_parameters = dict()\n for parameter in ['client_id', 'client_secret', 'client_url', 'job_reference']:\n if \"{}{}\".format(TARGET_SETTINGS_PREFIX, parameter) in settings:\n target_parameters[parameter] = settings[\"{}{}\".format(TARGET_SETTINGS_PREFIX, parameter)]\n \n if parameter in _request:\n target_parameters[parameter] = _request[parameter]\n \n\n return TalentSoft.push_profile(\n workflow_id=workflow_id,\n action_parameters=actions_parameters,\n origin_parameters=origin_parameters,\n target_parameters=target_parameters,\n )",
"workflow_code_format_placeholder": "# << format_placeholder >>",
"workflow_code_logics_placeholder": "# << logics_placeholder >>",
"workflow_code_event_parser_placeholder": "# << event_parser_placeholder >>",
Expand Down
37 changes: 13 additions & 24 deletions src/hrflow_connectors/connectors/talentsoft/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def retrieve_tag_value(tags: t.List[dict], tag_name: str) -> t.Any:
return None


def format_ts_applicant_civility(gender: t.Optional[str]) -> t.Optional[str]:
def format_ts_applicant_civility(gender: t.Optional[str]) -> t.Optional[t.Dict]:
civility_ts = {}
if gender is None:
return None
Expand All @@ -50,35 +50,27 @@ def format_ts_applicant_civility(gender: t.Optional[str]) -> t.Optional[str]:
return civility_ts


def extraire_annee(date_str: str) -> t.Optional[int]:
def extract_year(date_str: str) -> t.Optional[int]:
if not date_str:
return None
try:
# Convertir la chaîne de date en objet datetime
date_obj = datetime.fromisoformat(date_str)

# Extraire l'année de l'objet datetime
annee = date_obj.year

return annee
return datetime.fromisoformat(date_str).year
except ValueError:
return None


def calcul_ts_experience_duration(date_start: str, date_end: str) -> t.Optional[float]:
if not date_start or not date_end:
return None
try:
if not date_start or not date_end:
return None
date_start_obj = datetime.fromisoformat(date_start)
date_end_obj = datetime.fromisoformat(date_end)
experience_duration = date_end_obj - date_start_obj
experience_duration_years = experience_duration.days / 365
return experience_duration_years
return (date_end_obj - date_start_obj).days / 365
except ValueError:
return None


def format_contract_type(tags: t.List[dict]) -> t.Optional[str]:
def format_contract_type(tags: t.List[dict]) -> t.Optional[t.Dict]:
contract_type = retrieve_tag_value(tags, "talentsoft_contract_type")
if contract_type:
return CONTRACT_TYPE_REFERENTIAL.get(contract_type)
Expand All @@ -88,30 +80,27 @@ def format_contract_type(tags: t.List[dict]) -> t.Optional[str]:
def format_ts_educations(educations: t.List[dict], tags: t.List[dict]) -> dict:
education_level = retrieve_tag_value(tags, "talentsoft_education_level")

diplomas_list = (
diplomas = (
[{"educationLevel": EDUCATIONS_REFERENTIEL.get(education_level)}]
if education_level
else []
)

diplomas_list += [
diplomas += [
{
# "diplomaCode": 0,
# "specialisation": education["title"],
"yearObtained": (
extraire_annee(education["date_end"]) if education["date_end"] else ""
extract_year(education["date_end"]) if education["date_end"] else ""
),
"college": education["school"],
}
for education in educations
]

return {"diplomas": diplomas_list}
return {"diplomas": diplomas}


def format_ts_experiences(experiences: t.List[dict], tags: t.List[dict]) -> dict:
experience_level = retrieve_tag_value(tags, "talentsoft_experience_level")

experience_ts_level = experience_level if experience_level else None
experiences_ts_list = [
{
Expand Down Expand Up @@ -386,7 +375,7 @@ def applicant_update_parser(event: t.Dict) -> t.Dict:
return dict(filter="id::{}".format(event["applicantId"]))


def format_into_ts_applicant(profile_hrflow: t.Dict) -> t.Dict:
def format_info_ts_applicant(profile_hrflow: t.Dict) -> t.Dict:
info_profile_hrflow = profile_hrflow["info"]
attachment = profile_hrflow["attachments"][0]
personal_information = dict(
Expand Down Expand Up @@ -543,7 +532,7 @@ def format_into_ts_applicant(profile_hrflow: t.Dict) -> t.Dict:
" it to Applicant object in Talentsoft"
),
parameters=BaseActionParameters.with_defaults(
"PushProfileActionParameters", format=format_into_ts_applicant
"PushProfileActionParameters", format=format_info_ts_applicant
),
origin=HrFlowProfileWarehouse,
target=TalentSoftProfilesWarehouse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Handle TalentSoft 'applicant_new' event by fetching profile from TalentSoft and
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L246) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L235) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Handle TalentSoft 'applicant_resume_update' event by running a new HrFlow.ai Par
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L246) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L235) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Handle TalentSoft 'applicant_update' event by only updating tags coming from Tal
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L246) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L235) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Retrieves jobs from TalentSoft vacancies export API and send them to a ***Hrflow
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_vacancy`](../connector.py#L139) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_vacancy`](../connector.py#L128) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Retrieves profiles from TalentSoft candidates export API and send them to a ***H
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L246) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_ts_candidate`](../connector.py#L235) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand Down
14 changes: 7 additions & 7 deletions src/hrflow_connectors/connectors/talentsoft/docs/push_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pushs specific Profile from HrFlow and writes it to Applicant object in Talentso
| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `logics` | `typing.List[typing.Callable[[typing.Dict], typing.Optional[typing.Dict]]]` | [] | List of logic functions |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_into_ts_applicant`](../connector.py#L389) | Formatting function |
| `format` | `typing.Callable[[typing.Dict], typing.Dict]` | [`format_info_ts_applicant`](../connector.py#L378) | Formatting function |
| `read_mode` | `str` | ReadMode.sync | If 'incremental' then `read_from` of the last run is given to Origin Warehouse during read. **The actual behavior depends on implementation of read**. In 'sync' mode `read_from` is neither fetched nor given to Origin Warehouse during read. |

## Source Parameters
Expand All @@ -26,9 +26,9 @@ Pushs specific Profile from HrFlow and writes it to Applicant object in Talentso

| Field | Type | Default | Description |
| ----- | ---- | ------- | ----------- |
| `client_id_front` :red_circle: | `str` | None | client id used to access TalentSoft front office API |
| `client_secret_front` :red_circle: | `str` | None | client secret used to access TalentSoft front office API |
| `client_url_front` :red_circle: | `str` | None | url used to access TalentSoft front office API |
| `client_id` :red_circle: | `str` | None | client id used to access TalentSoft front office API |
| `client_secret` :red_circle: | `str` | None | client secret used to access TalentSoft front office API |
| `client_url` :red_circle: | `str` | None | url used to access TalentSoft front office API |
| `job_reference` | `str` | None | reference of the job offer to which the candidate is applying |

:red_circle: : *required*
Expand Down Expand Up @@ -58,9 +58,9 @@ TalentSoft.push_profile(
profile_key="your_profile_key",
),
target_parameters=dict(
client_id_front="your_client_id_front",
client_secret_front="your_client_secret_front",
client_url_front="your_client_url_front",
client_id="your_client_id",
client_secret="your_client_secret",
client_url="your_client_url",
job_reference="your_job_reference",
)
)
Expand Down
Loading

0 comments on commit e47fe74

Please sign in to comment.