CREATE OR REPLACE FUNCTION evergreen.lu_update_barcode(usr_id INT) RETURNS TEXT AS $$
DECLARE
- barcode TEXT;
+ bc_gen TEXT;
+ bc_holder TEXT;
BEGIN
- barcode := evergreen.lu_generate_barcode();
- INSERT INTO actor.card (usr, barcode) VALUES (usr_id, barcode);
+ LOOP
+ bc_gen := evergreen.lu_generate_barcode();
+
+ SELECT barcode INTO bc_holder FROM actor.card WHERE barcode = bc_gen;
+ EXIT WHEN bc_holder IS NULL;
+ END LOOP;
+
+ INSERT INTO actor.card (usr, barcode) VALUES (usr_id, bc_gen);
UPDATE actor.usr
SET card = CURRVAL('actor.card_id_seq')
WHERE id = usr_id;
- RETURN barcode;
+ RETURN bc_gen;
END;
$$ LANGUAGE PLPGSQL;
WHERE actor.usr.ident_value = scratchpad.usr_staging.ident_value
AND status IS NULL;
- SELECT au.id, lu_generate_barcode()
+ SELECT au.id, lu_update_barcode(au.id)
FROM actor.usr au INNER JOIN scratchpad.usr_staging su ON su.ident_value = au.ident_value
WHERE au.home_ou IN (
SELECT id FROM actor.org_unit WHERE parent_ou = 105
given_name = result_data['givenName'][0].strip()
datatel = result_data['lulColleagueId'][0].strip()
+ if len(datatel) != 7:
+ print >> sys.stderr, 'Datatel number not 7 chars for %s (%s)' % (usrname, datatel)
+ return
+
if 'preferredLanguage' in result_data:
lang = result_data['preferredLanguage'][0].strip()
else:
for key in result_data[0][1]:
print(key, result_data[0][1][key])
+def list_new_accounts():
+ """
+ Generate CSV output of the new accounts that were created
+
+ Returns the Colleague ID and barcode in the requested format of
+ double-quoted values using comma delimiters.
+ """
+
+ return """
+COPY (
+ SELECT au.ident_value, ac.barcode
+ FROM actor.usr au
+ INNER JOIN actor.card ac ON au.card = ac.id
+ INNER JOIN scratchpad.usr_staging su ON su.ident_value = au.ident_value
+ WHERE su.status = 'new'
+ ) TO STDOUT WITH csv QUOTE '"' FORCE QUOTE * HEADER
+;"""
+
def generate_ldap_sql(create_date):
"""
Generate the SQL required to create and update Evergreen accounts
print(update_existing_users())
print(insert_new_users())
+ print(list_new_accounts())
if __name__ == '__main__':
import doctest