Esempio n. 1
0
def upload_new(**kwargs):
    from RESTClient import MozuRestClient
    from db import mozu_image_table_instance

    mzclient = MozuRestClient(**kwargs)
    mz_imageid, document_resource = mzclient.create_new_mz_image()
    print mz_imageid, document_resource, ' <-- MozuID -- Docresource'
    if document_resource == "Keyerror":
        print mz_imageid, ' <-- MozuID'
    elif document_resource == "documentTree":
        bf_imageid = mzclient.bf_imageid
        kwargs['bf_imageid'] = bf_imageid
    elif document_resource == "documentListDocumentContent":
        kwargs['mz_imageid'] = mz_imageid
    mozu_image_table = mozu_image_table_instance()
    table_args = include_keys(kwargs, __mozu_image_table_valid_keys__)
    insert_db = mozu_image_table.insert(values=dict(**table_args))
    print "Inserting with, ", insert_db
    if kwargs['bf_imageid']:
        content_response = update_content_mz_image(**kwargs)
        try:
            insert_db.execute()
            print 'Inserted --> ', kwargs.items(), ' <-- ', insert_db
        except sqlalchemy.exc.IntegrityError:
            update_db = mozu_image_table.update(values=dict(**table_args),whereclause=mozu_image_table.c.bf_imageid == table_args['bf_imageid'])
            print 'Updating after IntegrityERR with args--> ', kwargs     # # Insert to mz_imageid + **kwargs to Oracle
            update_db.execute()
        return content_response
Esempio n. 2
0
def count_total_files_documents(**kwargs):
    from RESTClient import MozuRestClient
    mzclient = MozuRestClient(**kwargs)
    if not kwargs.get('page_size'):
        returned_item_count = mzclient.get_mz_image_document_list()['totalCount']
    else:
        returned_item_count = mzclient.get_mz_image_document_list(**kwargs)['totalCount']
    print "Total Files in DocumentList: {}".format(returned_item_count)
    return returned_item_count
Esempio n. 3
0
def update_content_mz_image(**kwargs):
    from RESTClient import MozuRestClient
    from db import mozu_image_table_instance
    mzclient = MozuRestClient(**kwargs)
    content_response = mzclient.send_content(**kwargs)
    print content_response.headers, "\nUpdate Mozu Content"
    mozu_image_table = mozu_image_table_instance()
    table_args = include_keys(kwargs, __mozu_image_table_valid_keys__)
    update_db = mozu_image_table.update(values=dict(**table_args))
    print content_response.headers, "\nUpdate DB MZ_IMAGE"
    return content_response
Esempio n. 4
0
def delete_document_data_content(**kwargs):
    from RESTClient import MozuRestClient
    from db import mozu_image_table_instance
    mzclient = MozuRestClient(**kwargs)
    delete_resp = mzclient.delete_mz_image()
    mozu_image_table = mozu_image_table_instance()
    if kwargs.get('mz_imageid'):
        delete_db = mozu_image_table.delete( whereclause=(mozu_image_table.c.mz_imageid == kwargs.get('mz_imageid')) )
    else:
        delete_db = mozu_image_table.delete( whereclause=(mozu_image_table.c.bf_imageid == kwargs.get('bf_imageid')) )
    # res = delete_db.execute()
    print delete_resp.headers, "Delete \n", delete_db, "\nMZ CLIENTID in FUNCtion: ", kwargs
    return delete_resp
Esempio n. 5
0
def upsert_data_mz_image(**kwargs):
    #import pdb
    #pdb.set_trace()
    from RESTClient import MozuRestClient
    from db import mozu_image_table_instance
    mozu_image_table = mozu_image_table_instance()
    select_result = mozu_image_table.select( whereclause=(mozu_image_table.c.bf_imageid == kwargs.get('bf_imageid')) ).execute().fetchone()
    # test = [ row for row in select_result ]
    print select_result, '\n\nTEST -->\n', kwargs  # , test
    if select_result:
        try:
            if select_result['mz_imageid']:
                kwargs['mz_imageid'] = select_result['mz_imageid']
                md5checksum = []
                kwargs['md5checksum'] = md5checksum
                mzclient = MozuRestClient(**kwargs)
                update_resp = mzclient.update_mz_image(**kwargs)
                table_args = include_keys(kwargs, __mozu_image_table_valid_keys__)
                update_db = mozu_image_table.update(values=dict(**table_args), whereclause=mozu_image_table.c.bf_imageid==kwargs.get('bf_imageid'))
                print "1\nUpdate Statement: \t", update_db
                update_result = update_db.execute()
                print update_result, '2-Updated--> ', kwargs.items(), ' <--kwargs.items ', update_db
                return update_resp
            else:
                mzclient = MozuRestClient(**kwargs)
                # mz_imageid, document_resource = mzclient.create_new_mz_image()
                mz_imageid = mzclient.get_mz_image_document_list(name=kwargs.get('bf_imageid'))['id']
                # kwargs['mz_imageid'], kwargs['mozu_url'] =  mzclient.create_new_mz_image() #mzclient.create_new_mz_image(**kwargs)
                if mz_imageid: #type(post_resp) == dict:
                    kwargs['mz_imageid'] = mz_imageid # mz_imageid.keys()[0]
                    table_args = include_keys(kwargs, __mozu_image_table_valid_keys__)
                    try:
                        content_response = mzclient.send_content(**kwargs)
                        insert_db = mozu_image_table.insert(**table_args)
                        print "3-\nInsert Statement: \t", insert_db
                        insert_result = insert_db.execute()
                        print content_response, "Not in DB. Insert Result: ", insert_result.fetchone()['mz_imageid']
                        return insert_result.fetchone()
                    except sqlalchemy.exc.IntegrityError:
                        content_response = mzclient.send_content(**kwargs)
                        if kwargs.get('bf_imageid'):
                            kwargs.get('bf_imageid')
                            update_db = mozu_image_table.update(values=dict(**table_args),
                                                                whereclause=  # mozu_image_table.c.bf_imageid==kwargs.get('bf_imageid')
                                                                (mozu_image_table.c.bf_imageid == table_args['bf_imageid'])
                                                                |
                                                                (mozu_image_table.c.mz_imageid == table_args['mz_imageid'])
                                                                )

                            print "4-\nUpdate Statement: \t", update_db
                            update_result = update_db.execute()
                            print content_response, '4.5-Updated--> Maybe', kwargs.items(), ' <--kwargs.items ', update_db
                            return update_result.fetchone()
                        else:

                            # print 'NO BFID to update ', locals()

                            insert_db = mozu_image_table.insert(**table_args)
                            print "5-\nFailed Insert Statement: \t", insert_db
                else:
                    print mz_imageid, ' Failed'
        except TypeError:
            print ' 128 Type-aka-OldAttribError in Upsert_mz_exec Locals -->', locals()
            #pass

    else:
        res = upload_new(**kwargs)
        return res
Esempio n. 6
0
def resource_documents_list(**kwargs):
    from RESTClient import MozuRestClient
    mzclient = MozuRestClient(**kwargs)
    documents_list = mzclient.get_mz_image_document_list()
    return documents_list
Esempio n. 7
0
def list_documents(**kwargs):
    from RESTClient import MozuRestClient
    mzclient = MozuRestClient(**kwargs)
    documents = mzclient.get_mz_image_document_list()['items']
    return documents