def test_index_solr_doc(): from opencontext_py.apps.ocitems.manifest.models import Manifest from opencontext_py.apps.indexer.reindex import SolrReIndex uuids = ['3FAAA477-5572-4B05-8DC1-CA264FE1FC10'] sri = SolrReIndex() sri.reindex_uuids(uuids)
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists item_type = None label = None try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True if isinstance(field_data, dict): # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label item_type = item_man.item_type # the act_sub_field below is a field from field_data # submitted by the user for sub_field_key, act_sub_field in field_data.items(): self.profile_field_update(item_man, sub_field_key, act_sub_field) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' else: self.ok = False label = 'No item' note += '.. "field_data" needs to be a dictionary object (parsed from JSON)' if self.ok: # now clear the cache a change was made self.clear_caches() self.response = { 'action': action, 'ok': self.ok, 'change': { 'uuid': self.edit_uuid, 'item_type': item_type, 'label': label, 'note': note } } return self.response
def collect_solr_reindex_uuids(self, uuid): """ collects uuids for solr to reindex """ sri = SolrReIndex() uuids = sri.get_related_uuids(uuid) for solr_uuid in uuids: if solr_uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(solr_uuid) return self.solr_reindex_uuids
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists item_type = None label = None try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True if isinstance(field_data, dict): # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label item_type = item_man.item_type # the act_sub_field below is a field from field_data # submitted by the user for sub_field_key, act_sub_field in field_data.items(): self.profile_field_update(item_man, sub_field_key, act_sub_field) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' else: self.ok = False label = 'No item' note += '.. "field_data" needs to be a dictionary object (parsed from JSON)' if self.ok: # now clear the cache a change was made self.clear_caches() self.response = {'action': action, 'ok': self.ok, 'change': {'uuid': self.edit_uuid, 'item_type': item_type, 'label': label, 'note': note}} return self.response
def index_linked_dinaa_sites(self): """ indexes DINAA sites liked to the federal registry """ uuids = [] links = LinkAnnotation.objects\ .filter(source_id=self.source_id, subject_type='subjects') for link in links: if link.subject not in uuids: uuids.append(link.subject) # reindex those links sri = SolrReIndex() sri.reindex_uuids(uuids)
def update_label(self, label, post_data): """ Updates an item's label. Generally straightforward except for subjects """ ok = True old_label = self.manifest.label self.manifest.label = label self.manifest.save() self.manifest.revised_save() note = '' if self.manifest.item_type == 'projects': try: cobj = Project.objects.get(uuid=self.manifest.uuid) cobj.label = label cobj.save() ok = True except Project.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False elif self.manifest.item_type == 'subjects': # we need to adjust context paths for this subject + its children subj_gen = SubjectGeneration() subj_gen.generate_save_context_path_from_uuid(self.manifest.uuid) note = str(subj_gen.changes) + ' items affected' elif self.manifest.item_type == 'persons': # we need to adjust person's combined name try: cobj = Person.objects.get(uuid=self.manifest.uuid) cobj.combined_name = label if 'given_name' in post_data: cobj.given_name = post_data['given_name'] if 'surname' in post_data: cobj.surname = post_data['surname'] if 'initials' in post_data: cobj.initials = post_data['initials'] cobj.save() ok = True except Person.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False # now reindex for solr, including child items impacted by the changes sri = SolrReIndex() sri.reindex_related(self.manifest.uuid) self.response = {'action': 'update-label', 'ok': ok, 'change': {'prop': 'label', 'new': label, 'old': old_label, 'note': note}} return self.response
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label for field_uuid, field_values in field_data.items(): self.profile_field_update(item_man, field_uuid, field_values) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' self.response = { 'action': action, 'ok': self.ok, 'change': { 'uuid': self.edit_uuid, 'label': label, 'note': note } } return self.response
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label for field_uuid, field_values in field_data.items(): self.profile_field_update(item_man, field_uuid, field_values) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' self.response = {'action': action, 'ok': self.ok, 'change': {'uuid': self.edit_uuid, 'label': label, 'note': note}} return self.response
def update_label(self, label, post_data): """ Updates an item's label. Generally straightforward except for subjects """ ok = True note = '' old_label = self.manifest.label if 'language' in post_data: language = post_data['language'] else: language = Languages.DEFAULT_LANGUAGE if 'script' in post_data: script = post_data['script'] else: script = None if language != Languages.DEFAULT_LANGUAGE: # editing another language, not the default lan_obj = Languages() key = lan_obj.get_language_script_key(language, script) self.manifest.localized_json = lan_obj.modify_localization_json(self.manifest.localized_json, key, label) self.manifest.save() self.manifest.revised_save() else: # editing the default language self.manifest.label = label self.manifest.save() self.manifest.revised_save() # only do additional label changes in default language if self.manifest.item_type == 'projects': try: cobj = Project.objects.get(uuid=self.manifest.uuid) cobj.label = label cobj.save() ok = True except Project.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False elif self.manifest.item_type == 'subjects': # we need to adjust context paths for this subject + its children subj_gen = SubjectGeneration() subj_gen.generate_save_context_path_from_uuid(self.manifest.uuid) note = str(subj_gen.changes) + ' items affected' elif self.manifest.item_type == 'tables': ex_id = ExpTableIdentifiers() ex_id.make_all_identifiers(self.manifest.uuid) try: cobj = ExpTable.objects.get(table_id=ex_id.table_id) cobj.label = label cobj.save() ok = True except ExpTable.DoesNotExist: self.errors['uuid'] = ex_id.table_id + ' not in tables' ok = False elif self.manifest.item_type == 'persons': # we need to adjust person's combined name try: cobj = Person.objects.get(uuid=self.manifest.uuid) cobj.combined_name = label if 'given_name' in post_data: cobj.given_name = post_data['given_name'] if 'surname' in post_data: cobj.surname = post_data['surname'] if 'initials' in post_data: cobj.initials = post_data['initials'] if 'mid_init' in post_data: cobj.mid_init = post_data['mid_init'] cobj.save() ok = True except Person.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in persons' ok = False # now reindex for solr, including child items impacted by the changes if self.manifest.item_type != 'tables' and self.edit_status > 0: if 'reindex' in post_data: sri = SolrReIndex() sri.reindex_related(self.manifest.uuid) if ok: # now clear the cache a change was made self.clear_caches() self.response = {'action': 'update-label', 'ok': ok, 'change': {'prop': 'label', 'new': label, 'old': old_label, 'note': note}} return self.response