Main Content

getBrokenLinks

Class: slreq.LinkSet
Namespace: slreq

Get links with invalid destination

Since R2024a

Description

example

brokenLinks = getBrokenLinks(myLinkSet) returns the links in the link set specified by myLinkSet that have invalid link destinations. The link destination can be invalid because either the destination artifact or the destination ID cannot be found.

example

[brokenLinks,details] = getBrokenLinks(myLinkSet) also returns the link destination values that make the link invalid.

Input Arguments

expand all

Link set, specified as an slreq.LinkSet object.

Output Arguments

expand all

Broken links, returned as an slreq.Link array.

Invalid link destination details, returned as a structure with these fields:

  • status — Status, returned as a logical 0 for invalid destinations

  • doc — Invalid document name or resource identifier

  • id — Invalid link destination identifier

Examples

expand all

This example shows how to find and repair broken links.

Load the myAddRequirements requirement set, which links to lines of code in myAddBroken.m.

rs = slreq.load("myAddBroken");

Get a handle to the link set.

myLinkSet = slreq.find(Type="LinkSet");

Find the broken links in the link set. Display the number of broken links.

brokenLinks = getBrokenLinks(myLinkSet);
numBrokenLinks = numel(brokenLinks)
numBrokenLinks = 1

Get a handle to the requirement that has the Summary property set to Add u and v.

req = slreq.find(Type="Requirement",Summary="Add u and v");

Repair the broken link by using the setDestination method.

setDestination(brokenLinks(1),req)

Confirm that there are no broken links.

brokenLinks = getBrokenLinks(myLinkSet)
brokenLinks =

     []

This example shows how to get and delete broken links.

Load the myAddRequirements requirement set, which links to lines of code in myAddBroken.m.

rs = slreq.load("myAddBroken");

Get a handle to the link set.

myLinkSet = slreq.find(Type="LinkSet");

Get the broken links in the link set. Display the number of broken links.

[brokenLinks,details] = getBrokenLinks(myLinkSet);
numBrokenLinks = numel(brokenLinks)
numBrokenLinks = 1

Delete the broken link.

remove(brokenLinks(1))

Confirm that there are no broken links.

brokenLinks = getBrokenLinks(myLinkSet)
brokenLinks =

     []

This example shows how to update link destinations when you rename a requirement set that has incoming links.

Load the Requirement Set

Load the mySubtractReqs requirement set, which has incoming links from the mySubtract~m link set.

rs = slreq.load("mySubtractReqs");

Get a handle to the link set that contains the incoming links.

myLinkSet = slreq.getDependentLinkSets(rs);

Display the source artifact file name for the link set.

[~,fname,ext] = fileparts(myLinkSet.Artifact);
shortname = [fname ext]
shortname = 
'mySubtract.m'

Rename the Requirement Set

Clear the loaded requirement and link data and the variables assigned to them.

slreq.clear
clear rs myLinkSet

Rename the mySubtractReqs requirement set to mySubtract.

movefile mySubtractReqs.slreqx mySubtract.slreqx

Load the mySubtract requirement set.

rs = slreq.load("mySubtract");

Load the link set associated with the mySubtract MATLAB® code file.

myLinkSet = slreq.load(shortname);
Warning: Unable to locate Requirement Set mySubtractReqs.slreqx (referrer mySubtract.m).

Get the broken links in the link set.

[brokenLinks,linkDetails] = getBrokenLinks(myLinkSet);

Display the details for the first broken link.

linkDetails(1)
ans = struct with fields:
    status: 0
       doc: 'mySubtractReqs.slreqx'
        id: ''

Assign the invalid document name to a variable.

oldDoc = string(linkDetails(1).doc)
oldDoc = 
"mySubtractReqs.slreqx"

Fix the Broken Links

Fix the broken links by updating the the link destinations to point to mySubtract.slreqx instead of mySubtractReqs.slreqx.

newDoc = "mySubtract.slreqx";
count = updateDocUri(myLinkSet,oldDoc,newDoc)
count = 4

Confirm that there are no broken links in the link set.

brokenLinks = getBrokenLinks(myLinkSet)
brokenLinks =

     []

Alternative Functionality

App

Use the Repair Invalid Links dialog box in the Requirements Editor to view the orphan links. For more information, see Resolve Links.

Version History

Introduced in R2024a