Skip to content

Commit 2cc8849

Browse files
committed
oslcquery: fixed problem with ETM opt-out projects not working
1 parent 0352096 commit 2cc8849

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

elmclient/_qm.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,8 @@ def load_components_and_configurations(self,force=False):
5050
nconfs = 0
5151
# retrieve components and configurations for this project
5252
if not self.is_optin:
53-
logger.debug( f"{self.is_optin=}" )
54-
# get the default configuration
55-
projx = self.execute_get_xml( self.reluri( 'rm-projects/' + self.iid ), intent="Retrieve the project definition (opt-out)" )
56-
compsu = rdfxml.xmlrdf_get_resource_text( projx, './/jp06:components' )
57-
compsx = self.execute_get_xml(compsu, intent="Retrieve the component definition (opt-out)" )
58-
defaultcompu = rdfxml.xmlrdf_get_resource_uri( compsx, './/oslc_config:component' )
59-
60-
# register the only component
61-
ncomps += 1
62-
self._components[defaultcompu] = {'name': self.name, 'configurations': {}}
63-
thisconfu = defaultcompu+"/configurations"
64-
configs = self.execute_get_json( thisconfu, intent="Retrieve all configurations (opt-out)" )
65-
configdetails = configs[defaultcompu+"/configurations"]
66-
if type(configs[thisconfu]["http://www.w3.org/2000/01/rdf-schema#member"])==dict:
67-
confs = [configs[thisconfu]["http://www.w3.org/2000/01/rdf-schema#member"]]
68-
else:
69-
confs = configs[thisconfu]["http://www.w3.org/2000/01/rdf-schema#member"]
70-
for aconf in confs:
71-
confu = aconf['value']
72-
confx = self.execute_get_xml( confu, intent="Retrieve configuration definition (opt-out)" )
73-
conftitle = rdfxml.xmlrdf_get_resource_text(confx,'.//dcterms:title')
74-
conftype = 'Stream' if 'stream' in confu else 'Baseline'
75-
self._components[defaultcompu]['configurations'][confu] = {'name': conftitle, 'conftype': conftype, 'confXml': confx}
76-
self._configurations[defaultcompu] = self._components[defaultcompu]['configurations'][confu]
77-
nconfs += 1
53+
# for QM, no configs to load!
54+
return
7855
elif self.singlemode:
7956
logger.debug( f"{self.singlemode=}" )
8057
#get the single component from a QueryCapability
@@ -123,9 +100,11 @@ def load_components_and_configurations(self,force=False):
123100

124101
components_uri = rdfxml.xmlrdf_get_resource_uri(cmsp_xml, './/rdf:Description/rdf:type[@rdf:resource="http://open-services.net/ns/core#QueryCapability"]/../oslc:resourceType[@rdf:resource="http://open-services.net/ns/config#Component"]/../oslc:queryBase')
125102
logger.info( f"{components_uri=}" )
103+
print( f"{components_uri=}" )
126104
# get all components
127105
crx = self.execute_get_xml( components_uri, intent="Retrieve component definition" )
128-
106+
logger.info( f"{crx=}" )
107+
print( f"{crx=}" )
129108
# <oslc_config:Component rdf:about="https://jazz.ibm.com:9443/qm/oslc_config/resources/com.ibm.team.vvc.Component/_iw4s4EB3Eeus6Zk4qsm_Cw">
130109
# <dcterms:title rdf:parseType="Literal">SGC Agile</dcterms:title>
131110
# <oslc:instanceShape rdf:resource="https://jazz.ibm.com:9443/qm/oslc_config/resourceShapes/com.ibm.team.vvc.Component"/>
@@ -226,11 +205,14 @@ def get_local_component_details(self):
226205
return results
227206

228207
def find_local_component(self, name_or_uri):
229-
self.load_components_and_configurations()
230-
for compuri, compdetail in self._components.items():
231-
logger.info( f"Checking {name_or_uri} {compdetail}" )
232-
if compuri == name_or_uri or compdetail['name'] == name_or_uri:
233-
return compdetail['component']
208+
if self.is_optin:
209+
self.load_components_and_configurations()
210+
for compuri, compdetail in self._components.items():
211+
logger.info( f"Checking {name_or_uri} {compdetail}" )
212+
if compuri == name_or_uri or compdetail['name'] == name_or_uri:
213+
return compdetail['component']
214+
else:
215+
return self
234216
return None
235217

236218
def _create_component_api(self, component_prj_url, component_name):

elmclient/examples/oslcquery.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,25 +511,44 @@ def safeint(s,nonereturns=0):
511511

512512
print( f"Query result has {len(results.keys())} {resultsentries}" )
513513

514-
# THIS IS UNTESTED!
514+
# COMPARE IS UNTESTED!
515515
if args.outputfile or args.compareresults:
516516
# write to CSV and/or compare with CSV
517+
# FIRST merge columns with same name - this merges types across components based on name
518+
# which is only need for queries in a GC. NOTE this doesn't attempt to use RDF URIs which it probably should :-o
519+
# but having different (as in totally different) types with same name is not exactly human-friendly!
517520
# build a list of all properties - these will be column headings for the CSV
518521
headings = []
522+
rawheadings = [] # this is used so headings are only resolved once - the raw headings are remembered in this list
523+
actualheadings = {}
519524
for k, v in list(results.items()):
520525
# add the URI to the value so it will be exported (first char is $ so the uri will always be in first column after the column titles are sorted)
521526
v["$uri"] = k
522527
for sk in list(v.keys()):
523-
sk1 = queryon.resolve_uri_to_name(sk)
524-
if sk1 is not None:
528+
sk1 = queryon.resolve_uri_to_name(sk) if args.resolvenames else sk
529+
if sk not in rawheadings:
530+
rawheadings.append(sk)
531+
if sk1 == sk: # if heading name hasn't been resolved before
532+
sk1 = queryon.resolve_uri_to_name(sk) # always resolve - only for headings
533+
if sk1 not in headings:
534+
headings.append(sk1)
535+
actualheadings[sk] = sk1
536+
# # also store the reverse actual->raw
537+
# actualheadings[sk1] = sk
538+
logger.info( f"Mapping {sk} to {sk1}" )
539+
else:
540+
sk1 = actualheadings[sk]
541+
if sk!=sk1:
525542
logger.debug(f"renaming {sk=} {sk1=}" )
543+
# if ernaming need to merge column content!
526544
existing = v[sk]
545+
otherexisting = v.get(sk1)
527546
del v[sk]
528-
v[sk1] = existing
529-
else:
530-
sk1 = sk
531-
if sk1 not in headings:
532-
headings.append(sk1)
547+
if existing and otherexisting:
548+
if existing != otherexisting:
549+
logger.info( f"MERGE {existing=} {otherexisting=}" )
550+
burp
551+
v[sk1] = otherexisting if otherexisting else existing
533552

534553
fieldnames = sorted(headings)
535554
if args.outputfile:

0 commit comments

Comments
 (0)