Exemple #1
0
    def __init__(self, commit_obj=None, ctx=None, meta=None):
        """
        @param commit_obj: serializable blob

        @return: old_head, new_head, new_head.hash_value
        """
        super(DBO_block_chain__commit, self).__init__()

        blob = RZCommit.blob_from_diff_obj(commit_obj)
        hash_value = self.calc_blob_hash(blob)

        l_id = generate_random_id__uuid()

        q_arr = [
            'match (old_head:%s:%s)' % (neo4j_schema.META_LABEL__VC_HEAD,
                                        neo4j_schema.META_LABEL__VC_COMMIT),
            'create (new_head:%s:%s {commit_attr})' %
            (neo4j_schema.META_LABEL__VC_HEAD,
             neo4j_schema.META_LABEL__VC_COMMIT),
            'create (new_head)-[r:%s {link_attr}]->(old_head)' %
            (neo4j_schema.META_LABEL__VC_PARENT),
            'remove old_head:%s' % (neo4j_schema.META_LABEL__VC_HEAD),
            'set new_head.ts_created=timestamp()',
            'return {head_parent_commit: old_head, head_commit: new_head, ts_created: new_head.ts_created}'
        ]

        q_param_set = {
            'commit_attr': {
                'blob': blob,
                'hash': hash_value,
                'id': hash_value
            },
            'link_attr': {
                'id': l_id
            },
        }

        self.add_statement(q_arr, q_param_set)

        # cache values necessary to generate op result
        self.commit_obj = commit_obj
        self.n_id = hash_value
        self.l_id = l_id

        # create commit-[:__Authored-by]->__User link if possible
        if None != ctx and None != ctx.user_name:
            self.add_statement(self._add_statement__authored_by(ctx.user_name))

        if None != meta and 'sentence' in meta and meta['sentence'] != '':
            result_of_param_set = {
                'result_of_attr': {
                    'sentence': meta['sentence']
                }
            }
            self.add_statement(
                self._add_statement__result_of_sentence(ctx.user_name),
                result_of_param_set)
Exemple #2
0
def generate_random_node_dict(n_type, nid=None):
    """
    @param n_type: is converted to a label set
    
    @return: a dict based node object representation and the generated node id
    """
    if None == nid:
        nid = generate_random_id__uuid()

    return {'__label_set': [n_type], 'id': nid, 'name': gen_random_name()}, nid
Exemple #3
0
def generate_random_node_dict(n_type, nid=None):
    """
    @param n_type: is converted to a label set
    
    @return: a dict based node object representation and the generated node id
    """
    if None == nid:
        nid = generate_random_id__uuid()

    return {'__label_set': [n_type],
            'id': nid,
            'name': gen_random_name() }, nid
Exemple #4
0
def generate_random_link_dict(l_type, src_id, dst_id, lid=None):
    """
    @param l_type: is converted to a single item type array
    
    @return: a dict based node object representation and the generated node id
    """
    if None == lid:
        lid = generate_random_id__uuid()

    ret_dict = Link.link_ptr(src_id, dst_id)
    ret_dict['__type'] = [l_type]
    ret_dict['id'] = lid
    return ret_dict, lid
Exemple #5
0
def generate_random_link_dict(l_type, src_id, dst_id, lid=None):
    """
    @param l_type: is converted to a single item type array
    
    @return: a dict based node object representation and the generated node id
    """
    if None == lid:
        lid = generate_random_id__uuid()

    ret_dict = Link.link_ptr(src_id, dst_id)
    ret_dict['__type'] = [l_type]
    ret_dict['id'] = lid
    return ret_dict, lid
Exemple #6
0
    def __init__(self, commit_obj=None, ctx=None, meta=None):
        """
        @param commit_obj: serializable blob

        @return: old_head, new_head, new_head.hash_value
        """
        super(DBO_block_chain__commit, self).__init__()

        blob = RZCommit.blob_from_diff_obj(commit_obj)
        hash_value = self.calc_blob_hash(blob)

        l_id = generate_random_id__uuid()

        q_arr = ['match (old_head:%s:%s)' % (neo4j_schema.META_LABEL__VC_HEAD,
                                             neo4j_schema.META_LABEL__VC_COMMIT),
                 'create (new_head:%s:%s {commit_attr})' % (neo4j_schema.META_LABEL__VC_HEAD,
                                                            neo4j_schema.META_LABEL__VC_COMMIT),
                 'create (new_head)-[r:%s {link_attr}]->(old_head)' % (neo4j_schema.META_LABEL__VC_PARENT),
                 'remove old_head:%s' % (neo4j_schema.META_LABEL__VC_HEAD),
                 'set new_head.ts_created=timestamp()',
                 'return {head_parent_commit: old_head, head_commit: new_head, ts_created: new_head.ts_created}'
                 ]

        q_param_set = {'commit_attr': {'blob': blob,
                                       'hash': hash_value,
                                       'id': hash_value},
                       'link_attr': {'id': l_id},
                       }

        self.add_statement(q_arr, q_param_set)

        # cache values necessary to generate op result
        self.commit_obj = commit_obj
        self.n_id = hash_value
        self.l_id = l_id

        # create commit-[:__Authored-by]->__User link if possible
        if None != ctx and None != ctx.user_name:
            self.add_statement(self._add_statement__authored_by(ctx.user_name))

        if None != meta and 'sentence' in meta and meta['sentence'] != '':
            result_of_param_set = {'result_of_attr': {'sentence': meta['sentence']}}
            self.add_statement(self._add_statement__result_of_sentence(ctx.user_name),
                               result_of_param_set)