Example #1
0
#                print('Validation of ' + object_id + ' failed.')
#                print(e)
#
#            # did validate
#            else:
#                # inform the user of the success
#                print('Validation of ' + object_id + ' succeeded.')
#
#                # post the new object(s).  SHOULD HANDLE ERRORS GRACEFULLY
#                response = new_ENCODE(object_collection,new_object)

        # if object is not found, verify and post it
        if (old_object.get(u'title') == u'Not Found') | (old_object.get(u'title') == u'Home'):

            # clean object of unpatchable or nonexistent properties.  SHOULD INFORM USER OF ANYTHING THAT DOESN"T GET POSTED.
            new_object = CleanJSON(new_object,object_schema,'POST')
    
            new_object = FlatJSON(new_object,keys)
            print(new_object)

            # test the new object       
            if ValidJSON(object_type,object_id,new_object,keys):
                # post the new object(s).  SHOULD HANDLE ERRORS GRACEFULLY
                new_object = CleanJSON(new_object,object_schema,'POST')
                response = new_ENCODE(object_type,new_object,keys)
                
                object_check = GetENCODE(str(response[u'@graph'][0][u'@id']),keys)
                print(object_check[u'@id'], object_check[u'uuid'])

        # if object is found, check for differences and patch it if needed/valid.
        elif put_status:
Example #2
0
        else:
            object_uuid = ''
        #print('Getting Schema.')
        object_schema = GetENCODE(('/profiles/' + object_type + '.json'),keys)
        # check to see if object already exists
        #print('Checking Object.')
        if object_id != '':
            old_object = GetENCODE(object_id,keys)
        # if object is not found, verify and post it
        if (old_object.get(u'title') == u'Not Found') | (old_object.get(u'title') == u'Home'):
            #new_object = FlatJSON(new_object,keys)
            print '\n\nalias:',new_object[u'aliases'][0],'is new.'
            # test the new object
            if ValidJSON(object_schema,object_type,object_id,new_object,keys):
            	# post the new object(s). SHOULD HANDLE ERRORS GRACEFULLY
                new_object = CleanJSON(new_object,object_schema,'POST')
                response = new_ENCODE(object_type,new_object,keys)
		#print response['status']
		if response['status'] == 'success':
			object_check = GetENCODE(str(response[u'@graph'][0][u'@id']),keys)
	         #	print object_check
			print 'uuid:', object_check[u'uuid']
                        filename.write(str(new_object['aliases'][0])+'\t'+str(object_check['uuid'])+'\n')
			posted_objects.append(object_check)
                elif response['status'] == 'error':
			new_object.update({'description':response['description']})
			new_object.update({'errors':response['errors']})
			new_object.update({'object_type':object_type})
			error_objects.append(new_object)
                else:
                    sys.exit()