Doors Next Generation Extensions: Find Requirements with Links

Today we will go a step further…in our first code snippet we will access Requirements inside DNG.
First we get all the Requirements inside a DNG Module
Then we look for Links on the Requirements and print the Linktype on the console. For this functionality we have to include the followin code inside status.js. The complete DNG Extension code be downloaded here.

BTW, to get results you have to create a Module with Requirements in it. Some of the Requirements should have Links to other Requirements. Links outside DNG, so called external Links, will not displayed.

function getLinksAndDrawGraph(moduleOrCollectionRef, name) {
        RM.Data.getContentsAttributes(moduleOrCollectionRef, "Status", function(opResult) {
            if (opResult.code === RM.OperationResult.OPERATION_OK) {
                opResult.data.forEach(function(aa) {
                        RM.Data.getLinkedArtifacts(aa.ref, function (response) {
                                var artLinks = response.data.artifactLinks;
                                if (artLinks.length != 0 ){
                                    console.log("Found link: " + artLinks[0].linktype.uri);
                               }
                        });
                 });
             }
         });
}

[Update 6.03.2104]
Lets have a closer look how the code work. Please remember that in the context of DNG Extensions we use a lot of callback with anonymous functions! Anonymous function are crucial concept we all need to be familiar with if we are striving Javascript.

2014-03-06 10_32_39-358_ SR1 - Requirements Management (RM)

1. We subscribe to the RM.Event.ARTIFACT_OPENED, this means every time an DNG Artefact is opened the anonymous function is called with “ref” as a parameter. This could also be an Array but to keep the code snippet easy to understand, we don’t check this. In the next Post we have to.

2. Inside the function checkFormatAndProceed(ref)  we look for the Name and the Format of the “ref” and…

3. Check if the reference to the Artefact is  a Module or Collection.

4. Fetch attribute value “Status” for all of the artifacts that are in the artifact. Also in this codeline there is another anonymous callback function.

5. At least we get the Links to a given Artefactreference. Also here we have a simplification, normaly we should take care about different Linktypes, external/internal Links, Backreferences etc.

 

In the next Post we will update our  Open Social Widget so it will include the identified Requirements. For this we will upgrade the DOM.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: