Link Deletion

Hi All,

I seem to be experiencing a wierd behaviour in that DOORS is deleting links in Modules that I am not asking it too.

The script I am running in multistage:

Stage 1 - make a copy of a set of modules into a different project and rename them
Stage 2 - remove any links these modules may have
Stage 3 - compare the copied module with another module (previous months version) and idneitfy those objects that haven't changed and create a link between them.

The problem I am experiencing is that links seem to be getting deleted in the original module that a created the copy from.

script is copied in below:
 

/*************************************************************************************
 *                Monthly Metrics Copy,Loop and Comparison Functions.                *
 *************************************************************************************/
 
 
//************************************************************************************
 
bool checkModuleName (string strModuleName) {
 
 
    int i = 0
        numEle = noElems (moduleListDBE)
 
        for (i = 0; i < numEle; i++) {
 
                strValue = getColumnValue (moduleListDBE, i, 0)
 
                if (strValue == strModuleName) return true
        }
 
        return false
 
}
 
//************************************************************************************
 
void doModuleComparison (Item itemRef) {
 
        string strNewerModuleName = name itemRef
        monthPos = get (monthSelectDBE)
 
        if (monthPos == 0) monthPos = 12
        string strOlderModuleName = strDestinations[monthPos*3-2] "/" strNewerModuleName ""
 
        newerModule = edit (strNewerModuleName, true)
        olderModule = edit (strOlderModuleName, true)
 
        if (!null olderModule) {
 
                (current ModuleRef__) = newerModule
                set flt1
                filtering on
                refresh newerModule
 
        
                for o in newerModule do {
 
                        iAbsno     = o.strAttrAbsNumber
                        othero     = object (iAbsno, olderModule)
                        
 
                        strNewText = probeAttr_(o, strAttrObjectText)
                        strNewMOP  = probeAttr_(o, strAttrMOP)
 
                        if (!null othero) {
                                strOldText = probeAttr_(othero, strAttrObjectText)
                                strOldMOP  = probeAttr_(othero, strAttrMOP)
 
                                if ((strNewText == strOldText) && (strNewMOP == strOldMOP)) o -> "No Change" -> othero
                                if (strNewText == " ") o -> "No Change" -> othero
                        }
 
                }
 
        } else {
                buf_Error += "Older Version of " strNewerModuleName "is not present in the Metrics Reporting Project.\n"
                bError = true
        }
 
        save  newerModule
        close newerModule
        close olderModule
 
}
 
//************************************************************************************
 
void copyItems (string strDestination) {
 
 
        p = project strSource
 
        for itemRef in p do {        
 
                itemType = type (itemRef)
 
                strModuleName = name itemRef
 
                if (checkModuleName (strModuleName)) {
 
                        print strModuleName "\n"
 
                        clipCopy(itemRef)
                        clipPaste( folder strDestination )
                        clipClear()
                }
        }
 
}
 
//************************************************************************************
 
void deleteLinks (string strDestination) {
 
        f = folder strDestination
 
        for itemRef in f do {
 
                itemType = type itemRef
                strModuleName = name itemRef
                print strModuleName "2\n"
                if (itemType == "Formal") {
 
                        m = edit (strModuleName, true)
 
                        for o in m do {
 
                                for lnk in o -> "*" do {
                                        delete lnk
                                }
                                for lnk in o <- "*" do {
                                        delete lnk
                                }
                        }
                        flushDeletions
 
                        modName = module strModuleName
                        setLinkModuleDescriptorsExclusive (f, modName, false)
 
                        save m
                        close m
 
                        string strRename = rename(itemRef, strModuleName " - Metrics Only", "For Monthly Metrics Use Only not live Data")
 
                        doModuleComparison (itemRef)
 
                }
 
        }
 
}
 
//************************************************************************************
 
void deleteLinkModules (string strDestination) {
 
        f = folder strDestination
 
        for itemRef in f do {
 
                itemType = type itemRef
                strModuleName = name itemRef
                modName = module strModuleName
 
                if (itemType == "Link" && strModuleName != "No Change") {
                        softDelete modName
                        hardDelete modName
                }
        }
 
}
 
//************************************************************************************
 
void doMetricsCollection (string strDestination) {
 
        f = folder strDestination
 
        print "strDestination \t" strDestination "\n"
 
        monthPos = get (monthSelectDBE)
 
        strAttr = strDestinations[monthPos*3 + 2]
 
        for itemRef in f do {
 
                itemType = type itemRef
                strModuleName = name itemRef
                modName = module strModuleName
                metricsModule = edit (strMetrics, true)
 
                print "strModuleName \t" strModuleName "\n"
 
                if (itemType == "Formal") {
 
                        for o in metricsModule do {
 
                                strValue = probeAttr_(o, strAttrObjectText)
 
                                if (strValue == strModuleName) {
                                        othero = o
                                        continue
                                }
                        }
 
 
                        m = edit (strModuleName, true)
 
                        objCount = 0
                        linkedCount = 0
 
                        for o in m do {
 
                                lnkCount = 0                            
 
                                for lnk in o -> "*" do {
 
                                        lnkCount++
                                }
 
                                if (lnkCount > 0) linkedCount++
 
                                objCount++
 
                                print "linkedCount \t " linkedCount "\tobjCount \t " objCount "\n"
                        }
 
                        othero.strAttr = (objCount - linkedCount) ""
                }
 
        }
 
}
 
//************************************************************************************

 


not sure why and it is disconcerting as not every link in the original source module is deleted - if it were all it would make more sense.

cheers Ben

 


BenSharples - Wed Dec 19 10:27:14 EST 2012

Re: Link Deletion
llandale - Thu Dec 20 14:09:33 EST 2012

Did not study your code but this is what I saw:
  • Golly I HATE auto-declare.
  • You need to open the SOURCE module of a link before you can delete it. In fact, you need to open the source module before you can even SEE the "Link". The DXL Manual shows the extra open-source step you need to do before an in-link loop, look for "LinkRef".
  • Do NOT delete links inside an object-link loop; it messes up the loop. Surprised you are not getting DXL errors for objects with more than one link.
    • Skip skpDeletes = create()
    • for l in o ->"*" do put(skpDeletes, i, i)
    • for l in skpDeletes do delete(i)
    • flushDeletions
    • delete(skpDeletes)
  • If you are deleting all links it may be better to delete all link-sets instead. Specifically, those link-sets in the new project.
  • I don't remember what happens vis-a-vis links when you copy modules. I'm suspecting that your new modules A have links associated in the OLD module B; not the corresponding new module B.
  • My memory is that "hardDelete(mod)" only works on UNDELETED modules. If your code works (has a softDelete first) then I remember wrong.
  • Do not open modules "edit" unless you figure to change them. Use "read" most of the time.

-Louie