def remove_by_id(self, identifier, commit=True): type_ = self.get_by_id(identifier) if type_.table_id: try: BrokerBase.remove_by_id(self, identifier, commit) except IntegrityException: raise IntegrityException( 'Item is still referenced cannot delete it') else: raise IntegrityException('Cannot remove the None element')
def remove_object_from_attribute(self, attr_id, obj_id, commit=True): """ Removes an attribute from an object :param obj_id: Identifier of the object :type obj_id: Integer :param attr_id: Identifier of the attribute :type attr_id: Integer """ try: obj = self.session.query(ObjectDefinition).filter(ObjectDefinition.identifier == obj_id).one() attribute = self.session.query(AttributeDefinition).filter(AttributeDefinition.identifier == attr_id).one() # check if chksum is not required required_chksums = self.findallchksums(obj) # remove self existing = required_chksums.get(attribute.chksum, None) if existing: raise IntegrityException((u'Attribute {0} is still required by attribute {1}.' + ' Please remove {1} first.').format(existing[1], existing[0])) else: attribute.remove_object(obj) self.do_commit(commit) except sqlalchemy.orm.exc.NoResultFound: raise NothingFoundException(u'Attribute or Object not found') except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error)
def remove_relations_for_event(self, event): try: self.session.query(Relation).filter( or_(Relation.event_id == event.identifier, Relation.rel_event_id == event.identifier)).delete( synchronize_session='fetch') except sqlalchemy.exc.IntegrityError as error: self.session.rollback() raise IntegrityException(error) except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error)
def remove_by_id(self, identifier, commit=True): """ Removes the <<get_broker_class()>> with the given identifier :param identifier: the id of the requested user object :type identifier: integer """ try: self.session.query(AttributeDefinition).filter(AttributeDefinition.identifier == identifier, AttributeDefinition.cybox_std is False ).delete(synchronize_session='fetch') except sqlalchemy.exc.OperationalError as error: self.session.rollback() raise IntegrityException(error) except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error) self.do_commit(commit)
def remove_by_attribute(self, attribute, commit): """ Removes one Value with the information given by the attribute :param attribute: the attribute in context :type attribute: Attribute :param commit: do a commit after :type commit: Boolean """ self.__set_class_by_attribute(attribute) try: self.session.query(self.get_broker_class()).filter( self.get_broker_class().attribute_id == attribute.identifier).delete(synchronize_session='fetch') self.do_commit(commit) except sqlalchemy.exc.OperationalError as error: self.session.rollback() raise IntegrityException(error) except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error)
def update(self, instance, commit=True, validate=True): type_ = self.get_by_id(instance.identifier) if type_.table_id: BrokerBase.update(self, instance, commit) else: raise IntegrityException('Cannot update the None element')