| 1 | """Oracle Recruiting Cloud: the candidate-experience REST API. |
| 2 | |
| 3 | One listing call returns up to 200 requisitions, newest first, with the |
| 4 | board's total; one more call per role gives its full text. A board lives on |
| 5 | the tenant's ``*.fa.*.oraclecloud.com`` host or under the company's own host |
| 6 | (Dell), and is named by its site number (``CX_1001``). ``PostedDate`` is the |
| 7 | day the requisition was posted to that site. |
| 8 | """ |
| 9 | |
| 10 | from __future__ import annotations |
| 11 | |
| 12 | from typing import Any, Callable |
| 13 | from urllib.parse import quote |
| 14 | |
| 15 | from .. import http, jobs |
| 16 | from . import detect |
| 17 | from .detect import PROVIDER_ORACLE |
| 18 | |
| 19 | PAGE_SIZE = 200 |
| 20 | _LIST_PATH = "/hcmRestApi/resources/latest/recruitingCEJobRequisitions" |
| 21 | _DETAIL_PATH = "/hcmRestApi/resources/latest/recruitingCEJobRequisitionDetails" |
| 22 | |
| 23 | |
| 24 | def listing_url(entry: dict[str, Any], offset: int = 0) -> str: |
| 25 | site = quote(str(entry["site_number"]), safe="") |
| 26 | finder = ( |
| 27 | f"findReqs;siteNumber={site},limit={PAGE_SIZE}," |
| 28 | f"offset={offset},sortBy=POSTING_DATES_DESC" |
| 29 | ) |
| 30 | return ( |
| 31 | f"https://{entry['board']}{_LIST_PATH}?onlyData=true" |
| 32 | f"&expand=requisitionList.secondaryLocations&finder={finder}" |
| 33 | ) |
| 34 | |
| 35 | |
| 36 | def detail_url(entry: dict[str, Any], ident: str) -> str: |
| 37 | encoded_ident = quote(str(ident), safe="") |
| 38 | site = quote(str(entry["site_number"]), safe="") |
| 39 | return ( |
| 40 | f"https://{entry['board']}{_DETAIL_PATH}?expand=all&onlyData=true" |
| 41 | f'&finder=ById;Id="{encoded_ident}",siteNumber={site}' |
| 42 | ) |
| 43 | |
| 44 | |
| 45 | def parse_listing(payload: Any, entry: dict[str, Any]) -> tuple[list[dict[str, Any]], int]: |
| 46 | """Rows and the reported total from one listing page.""" |
| 47 | found = payload.get("items") if isinstance(payload, dict) else None |
| 48 | search = found[0] if isinstance(found, list) and found and isinstance(found[0], dict) else None |
| 49 | rows = search.get("requisitionList") if search else None |
| 50 | if not isinstance(rows, list): |
| 51 | raise jobs.BoardShapeError("no requisitionList") |
| 52 | board, site = entry["board"], entry["site_number"] |
| 53 | encoded_site = quote(str(site), safe="") |
| 54 | items: list[dict[str, Any]] = [] |
| 55 | for row in rows: |
| 56 | if not isinstance(row, dict) or not row.get("Id") or not row.get("Title"): |
| 57 | continue |
| 58 | ident = str(row["Id"]) |
| 59 | posted = jobs._date_part(row.get("PostedDate")) |
| 60 | places = [str(row.get("PrimaryLocation") or "").strip()] |
| 61 | for extra in row.get("secondaryLocations") or []: |
| 62 | if isinstance(extra, dict) and extra.get("Name"): |
| 63 | places.append(str(extra["Name"]).strip()) |
| 64 | places = [place for place in dict.fromkeys(places) if place] |
| 65 | summary = str(row.get("ShortDescriptionStr") or "").strip() |
| 66 | item = jobs._ats_item( |
| 67 | provider=PROVIDER_ORACLE, |
| 68 | slug=board, |
| 69 | ident=ident, |
| 70 | title=str(row["Title"]).strip(), |
| 71 | url=f"https://{board}/hcmUI/CandidateExperience/en/sites/{encoded_site}/job/{quote(ident, safe='')}", |
| 72 | description=summary, |
| 73 | description_blocks=summary, |
| 74 | date=posted, |
| 75 | posted_date_true=bool(posted), |
| 76 | department=str(row.get("JobFamily") or row.get("JobFunction") or "").strip(), |
| 77 | location=places[0] if places else "", |
| 78 | company_name=str(entry.get("name") or ""), |
| 79 | whole_posting=True, |
| 80 | ) |
| 81 | item["locations"] = places |
| 82 | item["detail_url"] = detail_url(entry, ident) |
| 83 | items.append(item) |
| 84 | return items, jobs._reported_total(search, "TotalJobsCount") |
| 85 | |
| 86 | |
| 87 | def read_board( |
| 88 | entry: dict[str, Any], *, deadline: float, date_range: tuple[str, str], |
| 89 | ) -> tuple[list[dict[str, Any]], dict[str, Any]]: |
| 90 | """The board's roles, newest first, with the total it reports.""" |
| 91 | |
| 92 | def page(offset: int) -> Callable[[float], Any]: |
| 93 | url = listing_url(entry, offset) |
| 94 | |
| 95 | def fetch(http_deadline: float) -> Any: |
| 96 | if not detect.is_safe_public_url(url): |
| 97 | raise http.HTTPError("Refused non-public URL") |
| 98 | return http.get( |
| 99 | url, headers={"Accept": "application/json"}, |
| 100 | timeout=jobs.API_TIMEOUT_SECONDS, retries=2, deadline_monotonic=http_deadline, |
| 101 | public_only=True, redirect_guard=detect.same_site_redirect_guard(url), |
| 102 | ) |
| 103 | |
| 104 | return fetch |
| 105 | |
| 106 | return jobs._read_newest_first( |
| 107 | page, lambda payload: parse_listing(payload, entry), page_size=PAGE_SIZE, |
| 108 | row_ceiling=jobs.COMPANY_BOARD_ROW_CEILING, window_start=date_range[0], |
| 109 | deadline=deadline, |
| 110 | ) |
| 111 | |
| 112 | |
| 113 | def fetch_details(items: list[dict[str, Any]], *, deadline: float) -> tuple[int, int]: |
| 114 | """Fill the full text of the given roles, one call each.""" |
| 115 | |
| 116 | def call(item: dict[str, Any]) -> Callable[[float], Any]: |
| 117 | url = str(item.get("detail_url") or "") |
| 118 | if not detect.is_safe_public_url(url): |
| 119 | return lambda _http_deadline: None |
| 120 | return lambda http_deadline: http.get( |
| 121 | url, headers={"Accept": "application/json"}, |
| 122 | timeout=jobs.API_TIMEOUT_SECONDS, retries=1, deadline_monotonic=http_deadline, |
| 123 | public_only=True, redirect_guard=detect.same_site_redirect_guard(url), |
| 124 | ) |
| 125 | |
| 126 | def text_of(payload: Any) -> tuple[str, str] | None: |
| 127 | found = payload.get("items") if isinstance(payload, dict) else None |
| 128 | role = found[0] if isinstance(found, list) and found and isinstance(found[0], dict) else None |
| 129 | if role is None: |
| 130 | return None |
| 131 | parts = [ |
| 132 | str(role.get(key) or "") |
| 133 | for key in ( |
| 134 | "ExternalDescriptionStr", "ExternalResponsibilitiesStr", |
| 135 | "ExternalQualificationsStr", |
| 136 | ) |
| 137 | if role.get(key) |
| 138 | ] |
| 139 | html = "<br/>".join(parts) |
| 140 | return (jobs._block_text(html), jobs._clean_html(html)) if html.strip() else None |
| 141 | |
| 142 | return jobs._fill_role_text(items, call, text_of, deadline=deadline) |
| 143 |