def update_registers(self): """ This method is used when the namespace exists, and you only want to update the fields, or create the fields that do not exist before """ try: ent = Entidad.objects.all() ent = ent.filter(nombre=self.name) ent = ent.filter(namespace__url=self.url) self.entity = ent.get() #Si continua, es que el elemento existe y debemos actualizarlo self.entity.etiqueta = self.label self.entity.descripcion = self.description #Save on DB self.entity.save() except Entidad.DoesNotExist: #Create de entity object if self.url == self.namespace.url: self.entity = Entidad(nombre=self.name, descripcion=self.description, etiqueta=self.label, namespace=self.namespace) #Save on DB self.entity.save()
def update_fathers(self): """ This methos is only used when the namespace exists, and you only want to update the relations between the entities """ if not self.entity is None: for father in self.fathers: try: father_entity = Entidad.objects.all() father_entity = father_entity.filter(nombre=father['name']) father_entity = father_entity.filter( namespace__url=father['url']) father_entity = father_entity.get() if not father_entity in self.entity.padres.all(): self.entity.padres.add(father_entity) self.entity.save() except Entidad.DoesNotExist: # Si son del mismo namespace if father['url'] == self.namespace.url and \ father['name'] != "": father_entity = Entidad(nombre=father['name'], namespace=self.namespace) father_entity.save() self.entity.padres.add(father_entity) self.entity.save()
def update_registers(self): """ This method is used when the namespace exists, and you only want to update the fields, or create the fields that do not exist before """ #Get de property object try: propiedades = Propiedad.objects.all() propiedades = propiedades.filter(nombre=self.name) propiedades = propiedades.filter(namespace__url=self.url) propiedades = propiedades.distinct() self.property = propiedades.get() #Si llegamos aqui es que existe y se debe de actualizar if not self.description is None and self.description != '': self.property.descripcion = self.description if not self.label is None and self.label != '': self.property.etiqueta = self.label self.property.simple = self.simple self.property.save() except Propiedad.DoesNotExist: if self.url == self.namespace.url: self.property = Propiedad(namespace=self.namespace, nombre=self.name, descripcion=self.description, etiqueta=self.label, simple=self.simple) #Save on DB self.property.save() if not self.property is None: for tipo in self.types: if tipo['url'] != "http://www.w3.org/2000/01/rdf-schema#": entidades = Entidad.objects.all() entidades = entidades.filter(nombre=tipo['name']) entidades = entidades.filter(namespace__url=tipo['url']) try: entidades = entidades.get() if not entidades in self.property.tipo.all(): self.property.tipo.add(entidades) except Entidad.DoesNotExist: # Si son del mismo namespace if self.namespace.url == tipo['url'] and \ tipo['name'] != "": entidades = Entidad(nombre=tipo['name'], namespace=self.namespace) entidades.save() self.property.tipo.add(entidades) self.property.save() if self.property.tipo.all().count() == 0: self.property.simple = True self.property.save()
def setUp(self): """ Este metodo se encarga de preparar los datos para las pruebas """ # Create namespace name = NameSpace(namespace="Test", url="http://test.com/", short_name="test") name.save() # Create two entities ent1 = Entidad(nombre="father", namespace=name, descripcion="descripcion de un elemento de prueba 1", etiqueta="etiqueta de prueba 1") ent1.save() ent2 = Entidad(nombre="son", namespace=name, descripcion="descripcion de un elemento de prueba 2", etiqueta="etiqueta de prueba 2") ent2.save() # Create some properties prop1 = Propiedad(nombre="proptest1", simple=True, descripcion="desc test 1", etiqueta="prop test 1", namespace=name) prop1.save() prop1.entidades.add(ent1) prop2 = Propiedad(nombre="proptest2", simple=True, descripcion="desc test 2", etiqueta="prop test 2", namespace=name) prop2.save() prop2.entidades.add(ent1) prop3 = Propiedad(nombre="proptest3", simple=True, descripcion="desc test 3", etiqueta="prop test 3", namespace=name) prop3.save() prop3.entidades.add(ent2) prop3.tipo.add(ent2) prop3.save() mod = Modelo(nombre="Propiedad", aplicacion="easydata", visibilidad='V', entidad=ent2) mod.save() atri = Atributo(nombre="nombre", modelo=mod, visibilidad='V', propiedad=prop3, tipo_field="CharField") atri.save()
def register(self): """ Salva en la base de datos la propiedad que almacena el registro """ #Get de property object try: propiedades = Propiedad.objects.all() propiedades = propiedades.filter(nombre=self.name) propiedades = propiedades.filter(namespace__url=self.url) propiedades = propiedades.distinct() self.property = propiedades.get() #Si llegamos aqui es que existe y no se debe de hacer nada except Propiedad.DoesNotExist: if self.namespace.url == self.url: self.property = Propiedad(namespace=self.namespace, nombre=self.name, descripcion=self.description, etiqueta=self.label, simple=self.simple) if not self.property is None: #Save on DB self.property.save() for tipo in self.types: if tipo['url'] != "http://www.w3.org/2000/01/rdf-schema#": entidades = Entidad.objects.all() entidades = entidades.filter(nombre=tipo['name']) entidades = entidades.filter(namespace__url=tipo['url']) try: entidades = entidades.get() self.property.tipo.add(entidades) except Entidad.DoesNotExist: # Si son del mismo namespace if self.url == tipo['url'] and tipo['name'] != "": entidades = Entidad(nombre=tipo['name'], namespace=self.namespace) entidades.save() self.property.tipo.add(entidades) self.property.save() if self.property.tipo.all().count() == 0: self.property.simple = True self.property.save()
def register(self): """ Salva en la base de datos la entidad que almacena el registro """ try: ent = Entidad.objects.all() ent = ent.filter(nombre=self.name) ent = ent.filter(namespace__url=self.url) self.entity = ent.get() #Si continua, es que el elemento existe y no se debe de modificar except Entidad.DoesNotExist: #Create de entity object if self.url == self.namespace.url and self.name != "": self.entity = Entidad(nombre=self.name, descripcion=self.description, etiqueta=self.label, namespace=self.namespace) #Save on DB self.entity.save()
def register_fathers(self): """ Agrega las relaciones de la entidad con su padre, si posee """ if not self.entity is None: for father in self.fathers: try: father_entity = Entidad.objects.all() father_entity = father_entity.filter(nombre=father['name']) father_entity = father_entity.filter( namespace__url=father['url']) father_entity = father_entity.get() self.entity.padres.add(father_entity) self.entity.save() except Entidad.DoesNotExist: # Si son del mismo namespace if self.namespace.url == father['url'] and \ father['name'] != "": father_entity = Entidad(nombre=father['name'], namespace=self.namespace) father_entity.save() self.entity.padres.add(father_entity) self.entity.save()
def setUp(self): """ Este metodo se encarga de preparar los datos para las pruebas """ name = NameSpace(namespace="Test", url="http://test.com/", short_name="test") name.save() ent = Entidad(nombre="test", namespace=name, descripcion="descripcion de un elemento de prueba", etiqueta="etiqueta de prueba") ent.save() prop = Propiedad(nombre="proptest", simple=True, descripcion="desc test", etiqueta="prop test", namespace=name) prop.save() prop.entidades.add(ent)
def register_relations(self): """ Agrega las relaciones de la propiedad con las distintas entidades """ if not self.property is None: for rel in self.relations: try: ent = Entidad.objects.all() ent = ent.filter(nombre=rel['name']) ent = ent.filter(namespace__url=rel['url']) ent = ent.get() self.property.entidades.add(ent) except Entidad.DoesNotExist: # Si son del mismo namespace if self.url == rel['url'] and not rel['name'] is None and \ rel['name'] != "": ent = Entidad(nombre=rel['name'], namespace=self.namespace) ent.save() self.property.entidades.add(ent) self.property.save()
def setUp(self): """ Este metodo se encarga de preparar los datos para las pruebas """ # Create namespace name = NameSpace(namespace="Test", url="http://test.com/", short_name="test") name.save() # Create two entities ent1 = Entidad(nombre="father", namespace=name, descripcion="descripcion de un elemento de prueba 1", etiqueta="etiqueta de prueba 1") ent1.save() ent2 = Entidad(nombre="son", namespace=name, descripcion="descripcion de un elemento de prueba 2", etiqueta="etiqueta de prueba 2") ent2.save() # Create some properties prop1 = Propiedad(nombre="proptest1", simple=True, descripcion="desc test 1", etiqueta="prop test 1", namespace=name) prop1.save() prop1.entidades.add(ent1) prop2 = Propiedad(nombre="proptest2", simple=True, descripcion="desc test 2", etiqueta="prop test 2", namespace=name) prop2.save() prop2.entidades.add(ent1) prop3 = Propiedad(nombre="proptest3", simple=True, descripcion="desc test 3", etiqueta="prop test 3", namespace=name) prop3.save() prop3.entidades.add(ent2) prop3.tipo.add(ent2) prop3.save() mod1 = Modelo(nombre="Propiedad", aplicacion="easydata", visibilidad='V', entidad=ent2) mod2 = Modelo(nombre="Entidad", aplicacion="easydata", visibilidad='V', entidad=ent2) mod1.save() mod2.save() rel1 = Relacion(nombre="entidades", modelo=mod1, modelo_relacionado=mod2, visibilidad="V", tipo_relacion="M") rel2 = Relacion(nombre="propiedades", modelo=mod2, modelo_relacionado=mod1, visibilidad="V", tipo_relacion="M") rel1.save() rel2.save()
class RegisterEntity(object): """ Este registro se usa para almacenar las entidades de las que estara compuesto un determinado namespace. Este registro se encargara de administrar la correcta creacion de la entidad, asi como de crear sus relaciones entre ellos. """ name = None """almacena el nombre de la entidad""" description = None """almacena la descripcion asociada a la entidad""" label = None """almacena la etiqueta asociada a la entidad""" namespace = None """almacena el namespace al que pertenece la entidad""" fathers = None """almacena las entidades padre de las que hereda la entidad""" entity = None """almacena la instancia de entidad una vez creada""" url = None """almacena la url asociada a la entidad""" def __init__(self, name, description, label, namespace, fathers, url=""): """ Constructor de la clase RegisterEntity que almacena los datos de una determinada entidad :param name: Nombre de la entidad :param description: Descripcion asociada a la entidad :param label: etiqueta asociada a la entidad :param namespace: namespace al que pertenece :param fathers: padres del que hereda sus propiedades :param url: url donde se encuentra su especificacion """ self.name = name if not description is None: self.description = description[0:500] if not label is None: self.label = label[0:100] self.namespace = namespace self.fathers = fathers self.url = url if namespace.url == "" or namespace.url is None: namespace.url = self.url namespace.save() def register(self): """ Salva en la base de datos la entidad que almacena el registro """ try: ent = Entidad.objects.all() ent = ent.filter(nombre=self.name) ent = ent.filter(namespace__url=self.url) self.entity = ent.get() #Si continua, es que el elemento existe y no se debe de modificar except Entidad.DoesNotExist: #Create de entity object if self.url == self.namespace.url and self.name != "": self.entity = Entidad(nombre=self.name, descripcion=self.description, etiqueta=self.label, namespace=self.namespace) #Save on DB self.entity.save() def register_fathers(self): """ Agrega las relaciones de la entidad con su padre, si posee """ if not self.entity is None: for father in self.fathers: try: father_entity = Entidad.objects.all() father_entity = father_entity.filter(nombre=father['name']) father_entity = father_entity.filter( namespace__url=father['url']) father_entity = father_entity.get() self.entity.padres.add(father_entity) self.entity.save() except Entidad.DoesNotExist: # Si son del mismo namespace if self.namespace.url == father['url'] and \ father['name'] != "": father_entity = Entidad(nombre=father['name'], namespace=self.namespace) father_entity.save() self.entity.padres.add(father_entity) self.entity.save() def update_registers(self): """ This method is used when the namespace exists, and you only want to update the fields, or create the fields that do not exist before """ try: ent = Entidad.objects.all() ent = ent.filter(nombre=self.name) ent = ent.filter(namespace__url=self.url) self.entity = ent.get() #Si continua, es que el elemento existe y debemos actualizarlo self.entity.etiqueta = self.label self.entity.descripcion = self.description #Save on DB self.entity.save() except Entidad.DoesNotExist: #Create de entity object if self.url == self.namespace.url: self.entity = Entidad(nombre=self.name, descripcion=self.description, etiqueta=self.label, namespace=self.namespace) #Save on DB self.entity.save() def update_fathers(self): """ This methos is only used when the namespace exists, and you only want to update the relations between the entities """ if not self.entity is None: for father in self.fathers: try: father_entity = Entidad.objects.all() father_entity = father_entity.filter(nombre=father['name']) father_entity = father_entity.filter( namespace__url=father['url']) father_entity = father_entity.get() if not father_entity in self.entity.padres.all(): self.entity.padres.add(father_entity) self.entity.save() except Entidad.DoesNotExist: # Si son del mismo namespace if father['url'] == self.namespace.url and \ father['name'] != "": father_entity = Entidad(nombre=father['name'], namespace=self.namespace) father_entity.save() self.entity.padres.add(father_entity) self.entity.save()