@@ -915,98 +915,6 @@ def get(self, entity, fetch=False, query=None, order=None, **kwargs):
915915 find = get # offer interface approximately matching Ruby Rally REST API, App SDK Javascript RallyDataSource
916916
917917
918- def getCollection (self , collection_url , ** kwargs ):
919- """
920- Given a collection_url of the form:
921- http(s)://<server>(:<port>)/slm/webservice/v2.0/<entity>/OID/<attribute>
922- issue a request for the url and return back a list of hydrated instances for each item
923- in the collection.
924- """
925- context = self .contextHelper .currentContext ()
926- # craven ugly hackiness to support calls triggered from within ContextHelper.check ...
927- if not '?fetch=' in collection_url :
928- collection_url = "%s?pagesize=%d&start=1" % (collection_url , MAX_PAGESIZE )
929- resource = collection_url
930-
931- disabled_augments = kwargs .get ('_disableAugments' , False )
932- if not disabled_augments :
933- workspace_ref = self .contextHelper .currentWorkspaceRef ()
934- project_ref = self .contextHelper .currentProjectRef ()
935- resource = "%s&workspace=%s&project=%s" % (resource , workspace_ref , project_ref )
936- ##
937- ## print("Collection resource URL: %s" % resource)
938- ##
939- if self ._log :
940- self ._logDest .write ('%s GET %s\n ' % (timestamp (), resource ))
941- self ._logDest .flush ()
942- rally_rest_response = self ._getRequestResponse (context , resource , 0 )
943- return rally_rest_response
944-
945-
946- def addCollectionItems (self , target , items ):
947- """
948- Given a target which is a hydrated RallyEntity instance having a valid _type
949- and a items which is a list of hydrated Rally Entity instances
950- all of the same _type, construct a valid AC WSAPI collection url and
951- issue a POST request to that URL supplying the _greased items refs as the
952- payload.
953- """
954- if not items : return None
955- auth_token = self .obtainSecurityToken ()
956- target_type = target ._type
957- item_type = items [0 ]._type
958- resource = "%s/%s/%ss/add" % (target_type , target .oid , item_type )
959- collection_url = '%s/%s?fetch=Name&key=%s' % (self .service_url , resource , auth_token )
960- #print(collection_url)
961- payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
962- for item in items ]}
963- #print(payload)
964- #print("-------------------------------")
965- response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
966- #print(response.text)
967- #print(response.reason)
968- #print(response.content)
969- context = self .contextHelper .currentContext ()
970- response = RallyRESTResponse (self .session , context , resource , response , "shell" , 0 )
971- added_items = [str (item [u'Name' ]) for item in response .data [u'Results' ]]
972- return added_items
973-
974- def dropCollectionItems (self , target , items ):
975- """
976- Given a target which is a hydrated RallyEntity instance having a valid _type
977- and a items which is a list of hydrated Rally Entity instances
978- all of the same _type, construct a valid AC WSAPI collection url and
979- issue a POST request to that URL supplying the item refs in an appropriate
980- JSON structure as the payload.
981- """
982- if not items : return None
983- auth_token = self .obtainSecurityToken ()
984- target_type = target ._type
985- item_type = items [0 ]._type
986- resource = "%s/%s/%ss/delete" % (target_type , target .oid , item_type )
987- collection_url = '%s/%s?key=%s' % (self .service_url , resource , auth_token )
988- print (collection_url )
989- payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
990- for item in items ]}
991- print (payload )
992- print ("-------------------------------" )
993- response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
994- print (response .status_code )
995- print (response .reason )
996- #print(response.text)
997- #print(" - - - - - - - - - - - - - - - - - -")
998- #print(response.content)
999- print (" - - - - - - - - - - - - - - - - - -" )
1000- return response .reason
1001-
1002- #errors = response.errors
1003- #context = self.contextHelper.currentContext()
1004- #response = RallyRESTResponse(self.session, context, resource, response, "shell", 0)
1005- #errors = [item[u'Errors'] for item in response.data[u'OperationResult']]
1006- #errors = [item[u'Errors'] for item in response.data[u'QueryResult']]
1007- #return errors
1008-
1009-
1010918 def put (self , entityName , itemData , workspace = 'current' , project = 'current' , ** kwargs ):
1011919 """
1012920 Given a Rally entityName, a dict with data that the newly created entity should contain,
@@ -1193,6 +1101,79 @@ def delete(self, entityName, itemIdent, workspace='current', project='current',
11931101 return status
11941102
11951103
1104+ def getCollection (self , collection_url , ** kwargs ):
1105+ """
1106+ Given a collection_url of the form:
1107+ http(s)://<server>(:<port>)/slm/webservice/v2.0/<entity>/OID/<attribute>
1108+ issue a request for the url and return back a list of hydrated instances for each item
1109+ in the collection.
1110+ """
1111+ context = self .contextHelper .currentContext ()
1112+ # craven ugly hackiness to support calls triggered from within ContextHelper.check ...
1113+ if not '?fetch=' in collection_url :
1114+ collection_url = "%s?pagesize=%d&start=1" % (collection_url , MAX_PAGESIZE )
1115+ resource = collection_url
1116+
1117+ disabled_augments = kwargs .get ('_disableAugments' , False )
1118+ if not disabled_augments :
1119+ workspace_ref = self .contextHelper .currentWorkspaceRef ()
1120+ project_ref = self .contextHelper .currentProjectRef ()
1121+ resource = "%s&workspace=%s&project=%s" % (resource , workspace_ref , project_ref )
1122+ ##
1123+ ## print("Collection resource URL: %s" % resource)
1124+ ##
1125+ if self ._log :
1126+ self ._logDest .write ('%s GET %s\n ' % (timestamp (), resource ))
1127+ self ._logDest .flush ()
1128+ rally_rest_response = self ._getRequestResponse (context , resource , 0 )
1129+ return rally_rest_response
1130+
1131+
1132+ def addCollectionItems (self , target , items ):
1133+ """
1134+ Given a target which is a hydrated RallyEntity instance having a valid _type
1135+ and a items which is a list of hydrated Rally Entity instances
1136+ all of the same _type, construct a valid AC WSAPI collection url and
1137+ issue a POST request to that URL supplying the item refs in an appropriate
1138+ JSON structure as the payload.
1139+ """
1140+ if not items : return None
1141+ auth_token = self .obtainSecurityToken ()
1142+ target_type = target ._type
1143+ item_type = items [0 ]._type
1144+ resource = "%s/%s/%ss/add" % (target_type , target .oid , item_type )
1145+ collection_url = '%s/%s?fetch=Name&key=%s' % (self .service_url , resource , auth_token )
1146+ payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
1147+ for item in items ]}
1148+ response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
1149+ context = self .contextHelper .currentContext ()
1150+ response = RallyRESTResponse (self .session , context , resource , response , "shell" , 0 )
1151+ added_items = [str (item [u'Name' ]) for item in response .data [u'Results' ]]
1152+ return added_items
1153+
1154+
1155+ def dropCollectionItems (self , target , items ):
1156+ """
1157+ Given a target which is a hydrated RallyEntity instance having a valid _type
1158+ and a items which is a list of hydrated Rally Entity instances
1159+ all of the same _type, construct a valid AC WSAPI collection url and
1160+ issue a POST request to that URL supplying the item refs in an appropriate
1161+ JSON structure as the payload.
1162+ """
1163+ if not items : return None
1164+ auth_token = self .obtainSecurityToken ()
1165+ target_type = target ._type
1166+ item_type = items [0 ]._type
1167+ resource = "%s/%s/%ss/remove" % (target_type , target .oid , item_type )
1168+ collection_url = '%s/%s?key=%s' % (self .service_url , resource , auth_token )
1169+ payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
1170+ for item in items ]}
1171+ response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
1172+ context = self .contextHelper .currentContext ()
1173+ response = RallyRESTResponse (self .session , context , resource , response , "shell" , 0 )
1174+ return response
1175+
1176+
11961177 def search (self , keywords , ** kwargs ):
11971178 """
11981179 Given a list of keywords or a string with space separated words, issue
0 commit comments