Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Create reference term links for an artifact in DNG is struck after processing for some artifacts

 Hi Everyone,


We have a requirement to create a link for reference term using api. 

What we are  doing now is the following:
POST to: <RM_SERVER_ADDRESS>/rm/links

headers:
{'DoorsRP-Request-Type': 'private', 
'Content-Type': 'application/rdf+xml', 
'oslc.configuration': '<GC_SERVER_ADDRESS>/gc/configuration/145', 'net.jazz.jfs.owning-context': '<RM_SERVER_ADDRESS>/rm/rm-projects/IrrUYfOtEealZ_zm_SstCA/components/_na2ccCWuEeu1LM6pSS3uxg',  
'X-Requested-With': 'XMLHttpRequest'}

<rdf:RDF xmlns:rm="http://www.ibm.com/xmlns/rdm/rdf/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<rm:Link rdf:about="">

<rdf:subject rdf:resource=""/>

<rdf:object rdf:resource="_"/>

<rdf:predicate rdf:resource="http://www.ibm.com/xmlns/rdm/types/ArtifactTermReferenceLink"/>

<rm:suspectSubjectCleared/>

<rm:suspectObjectCleared/>

<rdf:type rdf:resource="http://www.ibm.com/xmlns/rdm/rdf/Link"/>

<rdf:value rdf:datatype="http://www.w3.org/2001/XMLSchema#string"></rdf:value>

</rm:Link>

</rdf:RDF>


We are calling this api to 'n' artifacts in a loop

This POST call is working and creating reference term links for 'n' artifacts , but when we try to update same 'n' artifacts

again then it is not creating and hanging around 5th call , we are not getting error as well in return.


Please help us !


Thanks in advance,

Jyothsna.

0 votes



2 answers

Permanent link

'DoorsRP-Request-Type': 'private'

This is a private API

0 votes

Comments

Hi Ian,


Thanks for reply. Can't we use Private apis? Is there any restrictions to use?

Thanks,
Jyothsna. 


Permanent link

Hi Jyothsna,

I think this issue happened because of the way RM API handles concurrent requests. To avoid this, create a batch of link objects in memory and call the rm/links endpoint once to create all of them. 
Following the code:
import requests

def create_reference_term_links(rm_server_address, gc_server_address, artifacts):
  """Creates reference term links for the given artifacts.

  Args:
    rm_server_address: The address of the RM server.
    gc_server_address: The address of the GC server.
    artifacts: A list of artifact IDs.
  """

  # Create a batch of link objects in memory.
  link_objects = []
  for artifact_id in artifacts:
    link_object = {
      "subject": "http://%s/_%s" % (rm_server_address, artifact_id),
      "object": "",
      "suspectSubjectCleared": True,
      "suspectObjectCleared": True,
      "value": ""
    }
    link_objects.append(link_object)

  # Call the rm/links endpoint once to create all of the link objects in the batch.
  response = requests.post(
    "%s/rm/links" % rm_server_address,
    headers={
      "DoorsRP-Request-Type": "private",
      "Content-Type": "application/rdf+xml",
      "oslc.configuration": "%s/gc/configuration/145" % gc_server_address,
      "net.jazz.jfs.owning-context": "%s/rm/rm-projects/IrrUYfOtEealZ_zm_SstCA/components/_na2ccCWuEeu1LM6pSS3uxg" % rm_server_address,
      "X-Requested-With": "XMLHttpRequest"
    },
    data="".join([
      "".join([
        "<rm:Link rdf:about=\"\">",
        "<rdf:subject rdf:resource=\"%s\"/>" % link_object["subject"],
        "<rdf:object rdf:resource=\"\"/>",
        "<rdf:predicate rdf:resource=\"http://www.ibm.com/xmlns/rdm/types/ArtifactTermReferenceLink\"/>",
        "<rm:suspectSubjectCleared/>",
        "<rm:suspectObjectCleared/>",
        "<rdf:type rdf:resource=\"http://www.ibm.com/xmlns/rdm/rdf/Link\"/>",
        "<rdf:value rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</rdf:value>" % link_object["value"],
        "</rm:Link>"
      ] for link_object in link_objects),
      "</rdf:RDF>"
    ])
  )

  # Wait for the RM API to finish creating the link objects.
  response.raise_for_status()

  # Check the response content to make sure that all of the link objects were created successfully.
  response_content = response.content.decode("utf-8")
  if "error" in response_content:
    raise Exception("Failed to create reference term links: %s" % response_content)

if name == "main":


0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,948

Question asked: Nov 07 '23, 6:10 a.m.

Question was seen: 921 times

Last updated: Jan 12 '24, 4:44 a.m.

Confirmation Cancel Confirm