def convert_string_to_type_asserions(self, predicate_uuid): """ Converts xsd:string objects to type objects in the Assertions table """ output = False try: # look for the predicate item pred = Predicate.objects.get(uuid=predicate_uuid) pdata_type = pred.data_type except Predicate.DoesNotExist: pdata_type = False if pdata_type == 'id': # yes, the predicate has data_type = 'id', so it can take types bad_assertions = Assertion.objects\ .filter(predicate_uuid=predicate_uuid, object_type='xsd:string') output = len(bad_assertions) for bad_ass in bad_assertions: new_ass = bad_ass tm = TypeManagement() tm.get_make_type_pred_uuid_content_uuid( predicate_uuid, bad_ass.object_uuid) new_ass.object_uuid = tm.oc_type.uuid new_ass.object_type = 'types' Assertion.objects\ .filter(hash_id=bad_ass.hash_id).delete() new_ass.save() return output
def convert_string_to_type_asserions(self, predicate_uuid): """ Converts xsd:string objects to type objects in the Assertions table """ output = False try: # look for the predicate item pred = Predicate.objects.get(uuid=predicate_uuid) pdata_type = pred.data_type except Predicate.DoesNotExist: pdata_type = False if pdata_type == 'id': # yes, the predicate has data_type = 'id', so it can take types bad_assertions = Assertion.objects\ .filter(predicate_uuid=predicate_uuid, object_type='xsd:string') output = len(bad_assertions) for bad_ass in bad_assertions: new_ass = bad_ass tm = TypeManagement() tm.get_make_type_pred_uuid_content_uuid(predicate_uuid, bad_ass.object_uuid) new_ass.object_uuid = tm.oc_type.uuid new_ass.object_type = 'types' Assertion.objects\ .filter(hash_id=bad_ass.hash_id).delete() new_ass.save() return output
def reconcile_type_cell(self, predicate_uuid, content_uuid, imp_cell, row_num=False): """ reconciles a distinct type, with consideration for how the """ output = False if len(imp_cell.record) > 0 \ and predicate_uuid is not False \ and content_uuid is not False: output = True tm = TypeManagement() tm.project_uuid = imp_cell.project_uuid tm.source_id = imp_cell.source_id self.oc_type = tm.get_make_type_pred_uuid_content_uuid(predicate_uuid, content_uuid) # self.source_id = self.oc_type.source_id if self.oc_type.uuid != imp_cell.fl_uuid \ or self.oc_type.content_uuid != imp_cell.l_uuid: # update the reconcilted UUID for import cells with same rec_hash if row_num is False: up_cells = ImportCell.objects\ .filter(source_id=self.source_id, field_num=imp_cell.field_num, rec_hash=imp_cell.rec_hash) else: up_cells = ImportCell.objects\ .filter(source_id=self.source_id, field_num=imp_cell.field_num, row_num=row_num) for up_cell in up_cells: # save each cell with the correct UUID up_cell.fl_uuid = self.oc_type.uuid up_cell.l_uuid = self.oc_type.content_uuid up_cell.uuids_save() return output
def create_type(self, post_data): """ creates a type item into a project """ ok = True required_params = ['source_id', 'item_type', 'predicate_uuid', 'label', 'note'] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' self.errors.append(message) # now prep the type management ! tm = TypeManagement() tm.project_uuid = self.project_uuid uuid = False content_uuid = False if ok: # now check to see if this already exists label = post_data['label'].strip() type_note = post_data['note'].strip() tm.source_id = post_data['source_id'].strip() predicate_uuid = post_data['predicate_uuid'].strip() if self.check_non_blank_param(post_data, 'uuid')\ and self.check_non_blank_param(post_data, 'content_uuid'): uuid = post_data['uuid'].strip() if self.check_uuid_format(uuid): uuid_exists = self.check_uuid_exists(uuid) if uuid_exists: ok = False message = 'Cannot create a category called "' + label + '"' message += ', becuase the submitted UUID: ' + uuid message += ' already exists.' self.errors.append(message) note = '; '.join(self.errors) else: # ok! use this as the suggested UUID for making a new type tm.suggested_uuid = uuid content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = '; '.join(self.errors) else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: ok = False mesaage = 'Cannot create a category called "' + label + '"' mesaage += ', becuase the submitted UUID: ' + uuid mesaage += ' is badly formed.' self.errors.append(message) note = '; '.join(self.errors) elif self.check_non_blank_param(post_data, 'uuid') \ and not self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the type, but not the content. We can't # create the type however, since we're missing a content uuid uuid = post_data['uuid'].strip() ok = False mesaage = 'Cannot create a category called "' + label + '"' mesaage += ', becuase the submitted UUID: ' + str(uuid) mesaage += ' needs to have a valid Content UUID.' self.errors.append(message) note = '; '.join(self.errors) elif not self.check_non_blank_param(post_data, 'uuid') \ and self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the content only. a weird case, but possible content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = '; '.join(self.errors) else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: label = '[Item not created]' uuid = False if ok: type_uuid = tm.check_exists_pred_uuid_content(predicate_uuid, label, True) if type_uuid is not False: # we already have this type! ok = False uuid = str(type_uuid) message = 'Cannot create a category called "' + label + '"' message += ', becuase it already exists with UUID: ' + uuid self.errors.append(message) note = '; '.join(self.errors) if ok: tm.source_id = post_data['source_id'].strip() if content_uuid is False: newtype = tm.get_make_type_within_pred_uuid(predicate_uuid, label) content_uuid = str(newtype.content_uuid) uuid = str(newtype.uuid) else: tm.content = label newtype = tm.get_make_type_pred_uuid_content_uuid(predicate_uuid, content_uuid) content_uuid = newtype.content_uuid uuid = newtype.uuid # now add the note if not empty self.add_description_note(newtype.uuid, 'types', newtype.source_id, type_note) if ok: # now clear the cache a change was made self.created_uuid = uuid self.clear_caches() self.response = {'action': 'create-item-into', 'ok': ok, 'change': {'uuid': uuid, 'content_uuid': content_uuid, 'label': label, 'note': self.add_creation_note(ok)}} return self.response
def create_type(self, post_data): """ creates a type item into a project """ ok = True required_params = [ 'source_id', 'item_type', 'predicate_uuid', 'label', 'note' ] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' if self.errors['params'] is False: self.errors['params'] = message else: self.errors['params'] += '; ' + message # now prep the type management ! tm = TypeManagement() tm.project_uuid = self.project_uuid uuid = False content_uuid = False if ok: # now check to see if this already exists label = post_data['label'].strip() type_note = post_data['note'].strip() tm.source_id = post_data['source_id'].strip() predicate_uuid = post_data['predicate_uuid'].strip() if self.check_non_blank_param(post_data, 'uuid')\ and self.check_non_blank_param(post_data, 'content_uuid'): uuid = post_data['uuid'].strip() if self.check_uuid_format(uuid): uuid_exists = self.check_uuid_exists(uuid) if uuid_exists: ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase the submitted UUID: ' + uuid self.errors['uuid'] += ' already exists.' note = self.errors['uuid'] else: # ok! use this as the suggested UUID for making a new type tm.suggested_uuid = uuid content_uuid = self.validate_content_uuid( tm, post_data) if content_uuid is False: ok = False note = self.errors['content_uuid'] else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase the submitted UUID: ' + uuid self.errors['uuid'] += ' is badly formed.' note = self.errors['uuid'] elif self.check_non_blank_param(post_data, 'uuid') \ and not self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the type, but not the content. We can't # create the type however, since we're missing a content uuid uuid = post_data['uuid'].strip() ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors['uuid'] += ', becuase the submitted UUID: ' + str( uuid) self.errors['uuid'] += ' needs to have a valid Content UUID.' note = self.errors['uuid'] elif not self.check_non_blank_param(post_data, 'uuid') \ and self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the content only. a weird case, but possible content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = self.errors['content_uuid'] else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: label = '[Item not created]' uuid = False if ok: type_uuid = tm.check_exists_pred_uuid_content( predicate_uuid, label, True) if type_uuid is not False: # we already have this type! ok = False uuid = type_uuid self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase it already exists with UUID: ' + uuid note = self.errors['uuid'] if ok: tm.source_id = post_data['source_id'].strip() if content_uuid is False: newtype = tm.get_make_type_within_pred_uuid( predicate_uuid, label) content_uuid = newtype.content_uuid uuid = newtype.uuid else: tm.content = label newtype = tm.get_make_type_pred_uuid_content_uuid( predicate_uuid, content_uuid) content_uuid = newtype.content_uuid uuid = newtype.uuid # now add the note if not empty self.add_description_note(newtype.uuid, 'types', newtype.source_id, type_note) self.response = { 'action': 'create-item-into', 'ok': ok, 'change': { 'uuid': uuid, 'content_uuid': content_uuid, 'label': label, 'note': self.add_creation_note(ok) } } return self.response