Skip to content

Commit 3baebc3

Browse files
fixed bugs with AppLaunchResponse; change appsession authentication method; started properties API
1 parent 821c3e4 commit 3baebc3

2 files changed

Lines changed: 68 additions & 10 deletions

File tree

src/BaseSpacePy/api/BaseSpaceAPI.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def getAppSessionById(self, Id):
190190
'''
191191
return self.getAppSession(Id=Id)
192192

193-
def getAppSession(self, Id=None):
193+
def getAppSessionOld(self, Id=None):
194194
'''
195195
Get metadata about an AppSession.
196196
Note that the client key and secret must match those of the AppSession's Application.
@@ -219,6 +219,18 @@ def getAppSession(self, Id=None):
219219
resp_dict = json.loads(response.text)
220220
return self.__deserializeAppSessionResponse__(resp_dict)
221221

222+
def getAppSession(self, Id=None, queryPars=None):
223+
if Id is None:
224+
Id = self.appSessionId
225+
if not Id:
226+
raise AppSessionException("An AppSession Id is required")
227+
resourcePath = '/appsessions/{AppSessionId}'
228+
resourcePath = resourcePath.replace('{AppSessionId}', Id)
229+
method = 'GET'
230+
headerParams = {}
231+
queryParams = {}
232+
return self.__singleRequest__(AppSessionResponse.AppSessionResponse, resourcePath, method, queryParams, headerParams, verbose=0)
233+
222234
def __deserializeAppSessionResponse__(self, response):
223235
'''
224236
Converts a AppSession response from the API server to an AppSession object.
@@ -440,6 +452,20 @@ def getUserById(self, Id):
440452
headerParams = {}
441453
return self.__singleRequest__(UserResponse.UserResponse, resourcePath, method, queryParams, headerParams)
442454

455+
def getAppResultFromAppSessionId(self, Id):
456+
'''
457+
Returns an AppResult object from an AppSession Id.
458+
Requires that there is exactly one AppResult, so the app must have finished
459+
460+
:param Id: The Id of the AppSession
461+
:returns: An AppResult instance
462+
'''
463+
ars = self.getAppSessionPropertyByName(Id, 'Output.AppResults')
464+
if len(ars.Items) != 1:
465+
raise AppSessionException("App session: %s did not have exactly one AppResult" % Id)
466+
appresult = ars.Items[0]
467+
return appresult
468+
443469
def getAppResultById(self, Id, queryPars=None):
444470
'''
445471
Returns an AppResult object corresponding to Id
@@ -500,6 +526,29 @@ def getAppResultFiles(self, Id, queryPars=None):
500526
'''
501527
return self.getAppResultFilesById(Id, queryPars)
502528

529+
def downloadAppResultFilesByExtension(self, Id, extension, localDir, queryPars=None):
530+
'''
531+
Convenience method to dowload all the files in an AppSession's AppResult that match a file extension
532+
Uses fileDownload without in its simplest form - may need to be refined later.
533+
534+
:param Id: The AppSession Id
535+
:param pattern: The regexp pattern to look for in the generated files
536+
:param localDir: The local directory where files will be downloaded to
537+
:param queryPars: the additional query parameters to pass into the appresult call (primarily to remove limits)
538+
:returns a list of File instances
539+
'''
540+
appResult = self.getAppResultFromAppSessionId(Id)
541+
appResultId = appResult.Content.Id
542+
appResultFiles = self.getAppResultFiles(appResultId, queryPars)
543+
allDownloads = []
544+
for appResultFile in appResultFiles:
545+
fileName = appResultFile.Name
546+
if fileName.endswith(extension):
547+
fileId = appResultFile.Id
548+
download = self.fileDownload(fileId, localDir)
549+
allDownloads.append(download)
550+
return allDownloads
551+
503552
def getProjectById(self, Id, queryPars=None):
504553
'''
505554
Request a project object by Id
@@ -1235,3 +1284,21 @@ def _validateQueryParameters(self, queryPars):
12351284
except AttributeError:
12361285
raise QueryParameterException("Query parameter argument must be a QueryParameter object")
12371286
return queryPars.getParameterDict()
1287+
1288+
def _dictionaryToProperties(rawProperties):
1289+
pass
1290+
1291+
def setResourceProperties(self, resourceType, resourceId, rawProperties):
1292+
'''
1293+
Pushes a set of properties into a BaseSpace resource:
1294+
1295+
https://developer.basespace.illumina.com/docs/content/documentation/rest-api/api-reference#Properties
1296+
1297+
:param resourceType: resource type for the property
1298+
:param resourceId: identifier for the resource
1299+
'''
1300+
PERMITTED_RESOURCE_TYPES = set([ "sample", "appresult", "run", "appsession", "project" ])
1301+
if resourceType not in PERMITTED_RESOURCE_TYPES:
1302+
raise UnknownParameterException(resourceType, PERMITTED_RESOURCE_TYPES)
1303+
resourcePath = '/%s/%s/properties' % (resourceType, resourceId)
1304+

src/BaseSpacePy/model/AppLaunchResponse.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11

2-
# class AppLaunchResponse(object):
3-
4-
# def __init__(self):
5-
# self.swaggerTypes = {
6-
# 'ResponseStatus': 'ResponseStatus',
7-
# 'Response': 'AppLaunch',
8-
# 'Notifications': 'list<Str>'
9-
# }
10-
112
class AppLaunchResponse(object):
123
'''
134
Represents a BaseSpace AppLaunch object.

0 commit comments

Comments
 (0)