@@ -1196,7 +1196,6 @@ def update_file_metadata(session, file_guid):
1196
1196
item_id = file_guid ,
1197
1197
)
1198
1198
1199
-
1200
1199
def get_registration_resource_id (registration_id ):
1201
1200
"""This function returns the most recent resource id
1202
1201
added to the given registration"""
@@ -1229,7 +1228,6 @@ def delete_registration_resource(registration_id):
1229
1228
1230
1229
session .delete (url , item_type = 'resources' )
1231
1230
1232
-
1233
1231
def create_registration_resource (registration_guid , resource_type ):
1234
1232
"""This method creates new registration output resource for a given
1235
1233
registration."""
@@ -1279,3 +1277,36 @@ def create_registration_resource(registration_guid, resource_type):
1279
1277
item_id = resource_id ,
1280
1278
item_type = 'resources' ,
1281
1279
)['data' ]
1280
+
1281
+
1282
+ def get_registration_resource_id (registration_id ):
1283
+ """This function returns the most recent resource id
1284
+ added to the given registration"""
1285
+ session = client .Session (
1286
+ api_base_url = settings .API_DOMAIN ,
1287
+ auth = (settings .REGISTRATIONS_USER , settings .REGISTRATIONS_USER_PASSWORD ),
1288
+ )
1289
+
1290
+ url = '/v2/registrations/{}/resources/' .format (registration_id )
1291
+ data = session .get (url )['data' ]
1292
+ if data :
1293
+ for i in range (0 , len (data )):
1294
+ date_created = data [i ]['attributes' ]['date_created' ]
1295
+ now = datetime .datetime .now ()
1296
+ current_date = now .strftime ('%Y-%m-%d' )
1297
+ if current_date in date_created :
1298
+ return data [i ]['id' ]
1299
+ break
1300
+ return None
1301
+
1302
+
1303
+ def delete_registration_resource (registration_id ):
1304
+ """This function deletes the resource added to the given registration"""
1305
+ session = client .Session (
1306
+ api_base_url = settings .API_DOMAIN ,
1307
+ auth = (settings .REGISTRATIONS_USER , settings .REGISTRATIONS_USER_PASSWORD ),
1308
+ )
1309
+ registration_resource_id = get_registration_resource_id (registration_id )
1310
+ url = '/v2/resources/{}' .format (registration_resource_id )
1311
+
1312
+ session .delete (url , item_type = 'resources' )
0 commit comments