def migrate_journals(source): # read in the content f = open(source) xml = etree.parse(f) f.close() journals = xml.getroot() print "migrating", str(len(journals)), "journal records" clusters = _get_journal_clusters(journals) # make a journal object, and map the main and historic records to it for canon, rest in clusters: j = Journal() cb = _to_journal_bibjson(canon) j.set_bibjson(cb) j.set_in_doaj(_is_in_doaj(canon)) j.set_created(_created_date(canon)) for p in rest: replaces = _get_replaces(p) isreplacedby = _get_isreplacedby(p) j.add_history(_to_journal_bibjson(p), replaces=replaces, isreplacedby=isreplacedby) j.save()
def make_journal(self): # first make a raw copy of the content into a journal journal_data = deepcopy(self.data) if "suggestion" in journal_data: del journal_data['suggestion'] if "index" in journal_data: del journal_data['index'] if "admin" in journal_data and "application_status" in journal_data["admin"]: del journal_data['admin']['application_status'] if "id" in journal_data: del journal_data['id'] if "created_date" in journal_data: del journal_data['created_date'] if "last_updated" in journal_data: del journal_data['last_updated'] if "bibjson" not in journal_data: journal_data["bibjson"] = {} journal_data['bibjson']['active'] = True new_j = Journal(**journal_data) # now deal with the fact that this could be a replacement of an existing journal if self.current_journal is not None: cj = Journal.pull(self.current_journal) # carry the id and the created date new_j.set_id(self.current_journal) new_j.set_created(cj.created_date) # set a reapplication date new_j.set_last_reapplication() # carry any continuations hist = cj.get_history_raw() if hist is not None and len(hist) > 0: new_j.set_history(cj.get_history_raw()) # remove the reference to the current_journal del new_j.data["admin"]["current_journal"] return new_j