Exemple #1
0
def existing_to_diff_graph(short_ids, graph):
	g = rdflib.Graph()
	for short in short_ids:
		uri = make_uri(short)
		for p, o in graph.predicate_objects(subject=uri):
			g.add((uri, p, o))
	return g
Exemple #2
0
def add_update_date(short_ids):
	add = Graph()
	logging.info("Adding create date for new faculty.")
	for short in short_ids:
		uri = make_uri(short)
		add.add((uri, BLOCAL.fisUpdated, TODAY))
	return add
Exemple #3
0
def deactivate_faculty(short_ids):
	remove = Graph()
	for short in short_ids:
		logging.debug("{0} is inactive faculty.")
		uri = make_uri(short)
		remove.add((uri, RDF.type, BLOCAL.BrownThing))
	return remove
Exemple #4
0
def add_create_date(short_ids):
	add = Graph()
	logging.info("Adding create date for new faculty.")
	for short in short_ids:
		#Don't add a create data if this short id is invalid.
		if common.valid_short_id(short) is True:
			uri = make_uri(short)
			add.add((uri, BLOCAL.fisCreated, TODAY))
	return add
Exemple #5
0
def graph_faculty_data(fac_info):
	"""
	New FIS data for a single row in the feed.
	"""
	#Add graph
	ag = rdflib.Graph()
	shortId = fac_info.get('shortId')
	#Validate the shortId - skip invalid ids.
	valid = common.valid_short_id(shortId)
	if valid is not True:
		logging.warning("Invalid shortId {}.".format(shortId))
		return
	uri = make_uri(shortId)
	ag.add((uri, RDF.type, VIVO.FacultyMember))
	ag.add((uri, RDF.type, BLOCAL.BrownThing))
	ag.add((uri, RDFS.label, Literal(fac_info['label'])))
	ag.add((uri, FOAF.firstName, Literal(fac_info['first'])))
	ag.add((uri, FOAF.lastName, Literal(fac_info['last'])))
	ag.add((uri, VIVO.preferredTitle, Literal(fac_info['title'])))
	ag.add((uri, BLOCAL.shortId, Literal(shortId)))
	#Required data properties - not requireing middle name or email now.
	optional_properties = ['middle', 'email', 'workdayID']
	for k, v in fac_info.items():
	    if (v is None) and (k not in optional_properties):
	        logging.error("Required data missing {} for {}.".format(k, shortId))
	        raise Exception("Required data missing in FIS file at fac_info {0}.".format(shortId))
	#Add optional data properties.
	#Email is now optional
	if fac_info['email'] is None:
	    logging.warning("Missing email for {}.".format(uri))
	else:
		ag.add((uri, VIVO.primaryEmail, Literal(fac_info['email'])))
	#Middle name is optional.
	middle = fac_info.get('middle')
	if middle is not None:
	    ag.add((uri, VIVO.middleName, Literal(middle)))
	#FIS sync date.
	ag.add((uri, BLOCAL.fisUpdated, TODAY))
	#if new is True:
	#	ag.add((uri, BLOCAL.fisCreated, TODAY))
	return ag
Exemple #6
0
def process_feed_file(filename):
	#Lookup keys.
	brown_id_map = get_brown_id_map()
	in_data = read_file(filename)
	error_count = 0
	out = {}
	for n, row in enumerate(in_data):
		brown_id = row.get('Brown_ID')
		last = row.get('Preferred_Last_Name')
		first = row.get('Preferred_First_Name')
		middle = row.get('Preferred_Middle_Name')
		#remove trailing periods.
		if middle:
			middle = middle.rstrip('.')
		title = row.get('Current_Person_Title').rstrip('\n').rstrip('\r')
		email = row.get('Employee_Email')
		short_id = row.get('AUTH_ID')
		#Make a string for logging errors.
		estring = "Row %s. %s" % (
			str(n + 1),
			" ".join([f for f in [short_id, first, last, title, email] if f is not None])
		)
		#Stop process if too many errors are found.
		if error_count > ERROR_MAX:
			logging.error("Too many errors. Exiting.")
			raise Exception("Too many missing auth ids to proceed. Verify faculty file.")
		if short_id is None:
			fail = False
			try:
				#Try to fetch short_id from LDAP
				short_id = brown_id_map[brown_id]['short_id']
			except IndexError:
				fail = True
			except KeyError:
				fail = True
			if (short_id is None) or (fail is True):
				logging.warning("Unable to lookup faculty by key. %s." % (estring))
				error_count += 1
				continue
		if (first is None):
			logging.error("Missing first name. %s." % (estring))
			continue
		if (last is None):
			logging.error("Missing last name. %s" % (estring))
			continue
		label = "{0}, {1}".format(last, first)
		uri = make_uri(short_id)
		d = {}
		d['brown_id'] = brown_id
		d['uri'] = uri
		d['label'] = label
		d['first'] = first
		d['last'] = last
		d['middle'] = middle
		d['title'] = title
		d['email'] = email
		d['shortId'] = short_id
		#Add other FIS data that might be needed later here.
		d['workdayID'] = row.get('Workday_ID')
		out[short_id] = d
		if (DEBUG is True) and (n > 15):
			break
	return out