select * from aait_imp_perslid

alter table aait_imp_perslid add prs_perslid_apikey VARCHAR2(128)

--xd_primary_bedrijfkey gezet op 83

UPDATE prs_perslid p
   SET p.prs_perslid_apikey = DBMS_RANDOM.string ('a', 32)
 WHERE p.prs_perslid_apikey IS NULL AND p.prs_perslid_verwijder IS NULL
   AND p.prs_perslid_key IN
             (SELECT pa.prs_perslid_key
                FROM prs_perslid pa, prs_v_afdeling a
               WHERE pa.prs_afdeling_key = a.prs_afdeling_key
                 AND a.prs_bedrijf_key =
                        fac.getsetting ('xd_primary_bedrijfkey'));

UPDATE aait_imp_perslid i set prs_perslid_apikey = (select prs_perslid_apikey from prs_perslid p
where p.prs_perslid_key = i.prs_perslid_key);

grant select on prs_perslid to aahu_test, aasa_test, aalb_test;

-- host file aanpassen

-- instelling xd_secundarydomains 
/*
{
  "aait": {
    "name": "it",
    "url": "https://aait-a.facilitor.nl/api_intern/"
  },
  "aasa": {
    "name": "sabic",
    "url": "https://aasa-a.facilitor.nl/api_intern/"
  },
  "aalb": {
    "name": "lyondellbasell",
    "url": "https://aalb-a.facilitor.nl/api_intern/"
  },
  "aahu": {
    "name": "huntsman",
    "url": "https://aahu-a.facilitor.nl/api_intern/"
  }
}
*/

--Op alle andere omgevingen:
UPDATE prs_perslid p
   SET prs_perslid_apikey =
          (SELECT DISTINCT i.prs_perslid_apikey
             FROM aait_test.aait_imp_perslid i,
                  (SELECT prs_perslid_key,
                          prs_perslid_nr,
                          prs_kenmerklink_waarde aait_prs_perslid_key
                     FROM prs_perslid p2, prs_kenmerklink kl
                    WHERE p2.prs_perslid_key = kl.prs_link_key
                      AND kl.prs_kenmerk_key = 4
                      AND p2.prs_perslid_verwijder IS NULL
                      AND kl.prs_kenmerklink_verwijder IS NULL) ap
            WHERE i.prs_perslid_key = ap.aait_prs_perslid_key
              AND ap.prs_perslid_key = p.prs_perslid_key
              AND i.personeelsnummer <> 'N/A');