Soft/Hard delete of Objects by ID?

Hi I want to write universal function which to be possible to delete object in modules by given id. I am wondering if I am missing something.

string delete(Module mod, string id, bool isSoftDeletion) {
    if(null id) halt
    if(null mod) halt
    
    Object deleted = object(id, mod)
    if(null deleted) halt
    
    if(isDeleted(deleted){
        halt
    }
    
    delete(module(fullName(mod)), isSoftDeletion)
    
}

Do I delete the history? And what happens with the baselines of the object which we want to delete?


Dinio - Fri Dec 25 03:26:32 EST 2015

Re: Soft/Hard delete of Objects by ID?
Mike.Scharnow - Sun Dec 27 15:00:59 EST 2015

some remarks

  • you should not call the function "delete" as there already are a lot of perms "delete" in DOORS. This may work now but might be a possible problem in future versions of DOORS
  • you should check whether the object is deletable (use perm "canDelete (Object)")
  • your function is of type "string", but you do not return anything. Is this intentional? It would be useful e.g. to return an error message if an error occurred, otherwise return nothing.
  • It might be helpful to check whether "mod" has been opened in an edit mode, but this is just of interest if you want to return a meaningful error message. Otherwise canDelete should suffice
  • "halt" will terminate the complete dxl program immediately. This might be ok in the first two lines, as an error in these lines indicates a severe programming error, but the other two halts should be replaced by returning an error message. But this depends on the concept of your script. For a "universal function" I think it is too fierce, if the complete program terminates in these cases
  • the function "object" takes an integer as argument, not a string. So, your function should be declared … mod, int id, bool …
  • the function "object" will take into account the current filter and display settings. So, if you have a view that does not include the object "id", your function will not find the object. Instead, use a construct like "Object o2BDeleted = null; Object o; for o in entire mod do {int nr = o."Absolute Number"; if nr == id then o2BDeleted = o; break} ; if null o2BDeleted […]"
  • Finally and most important: in your function you are deleting a module, not an object!! (well, you would, if you had the syntax correct). Instead, use the functions void hardDelete(o2BDeleted) and void softDelete (o2BDeleted) (and use noError()  / lastError() for checking whether the delete was successful

What happens with the baselines of the object?

  • There is no "baseline of an object", there are only baselines of modules. A baseline cannot be modified.So, it is not possible to delete an object in a baseline. When you delete an object from a current version, it will still exist in the baselines.

Do I delete the history?

  • This is independent of DXL, you can try this from the GUI: When you soft delete an object, the history of the object will still be visible for everyone. When you hard delete (purge) an object, the history is still there, but a normal user will only see entries that show "read locked data". Only the user "Administrator" (not any other user with admin privileges) will still be able to see the history.
  • Note that each module version will only contain the changes that are done in this version. So, when you create a baseline, the baseline will contain all the changes done since the baseline before that. The new current version will at first contain no history entries. So, when you purge an object from a current version, you will only erase the history entries done since the creation of the last baseline.

 

Re: Soft/Hard delete of Objects by ID?
Dinio - Mon Dec 28 11:24:16 EST 2015

Thanks Mike.Scharnow , a lot , for the deep explanations. Here I took into consideration your remarks and create new version of the function.  And have 2 questions.

  1. Is it save/good practice to turn off filtering?
  2. Are error messages properly used?

void deleteObject(Module mod, int id, bool isSoftDeletion) {
    if (null id) error "The specified id null"
    if (null mod) error "The specified module is null"
      
    filtering off
    
    Object o2BDeleted = null
    Object o
    for o in mod do {
        int currentId = o."Absolute Number"
        if currentId == id then {
                        o2BDeleted = o
                        break
                        }
     } 
     
     if (null o2BDeleted){
        error "No Object for deletion is found."
     }
    
     if (isDeleted(o2BDeleted)) {
        error "The object is already deleted."
     }
    
     if (!canDelete(o2BDeleted)) {
        error "The object can not be deleted!!!"
     }
    
    if (isSoftDeletion) {
        softDelete(o2BDeleted)
    } else {
        hardDelete(o2BDeleted) 
    }
      
}

 

deleteObject(current, 1, true)

Re: Soft/Hard delete of Objects by ID?
Mike.Scharnow - Tue Dec 29 04:41:47 EST 2015

Dinio - Mon Dec 28 11:24:16 EST 2015

Thanks Mike.Scharnow , a lot , for the deep explanations. Here I took into consideration your remarks and create new version of the function.  And have 2 questions.

  1. Is it save/good practice to turn off filtering?
  2. Are error messages properly used?

void deleteObject(Module mod, int id, bool isSoftDeletion) {
    if (null id) error "The specified id null"
    if (null mod) error "The specified module is null"
      
    filtering off
    
    Object o2BDeleted = null
    Object o
    for o in mod do {
        int currentId = o."Absolute Number"
        if currentId == id then {
                        o2BDeleted = o
                        break
                        }
     } 
     
     if (null o2BDeleted){
        error "No Object for deletion is found."
     }
    
     if (isDeleted(o2BDeleted)) {
        error "The object is already deleted."
     }
    
     if (!canDelete(o2BDeleted)) {
        error "The object can not be deleted!!!"
     }
    
    if (isSoftDeletion) {
        softDelete(o2BDeleted)
    } else {
        hardDelete(o2BDeleted) 
    }
      
}

 

deleteObject(current, 1, true)

Hi Dinio,

1. I think there is no best recommendation for this, this depends on what your company and the users need and partly of the purpose of the module and the standards applied in your company. Your script should just be aware of the fact that the object might not be visible. Note that usually the option "View -> show -> deletions" is switched off, so that the function "object (id, mod)" will not find the object. (by the way: again, this is the same in the GUI. If object 5 is deleted and you use "Edit -> Go To" and deletions are not shown then you get the message "Absolute Number 5 was not found". So "Go To" is the GUI equivalent of the function object (id))

2. Yes, that looks well for now. As mentioned before: you wrote this function as a central, universal function, perhaps to be added to a DXL library that you create later. This function will be used in a bigger script that you write later. Now, it depends on the calling script whether it is OK if the function terminates terminates the complete script when e.g. the object is already deleted or whether you want to be able to react in the calling script to the fact that the object could not be deleted. So, at a later time you might want to add a different kind of error reporting / transport system to your function. For now, everything looks OK.

Regards,
Mike

Re: Soft/Hard delete of Objects by ID?
Dinio - Wed Dec 30 09:47:09 EST 2015

Mike.Scharnow - Tue Dec 29 04:41:47 EST 2015

Hi Dinio,

1. I think there is no best recommendation for this, this depends on what your company and the users need and partly of the purpose of the module and the standards applied in your company. Your script should just be aware of the fact that the object might not be visible. Note that usually the option "View -> show -> deletions" is switched off, so that the function "object (id, mod)" will not find the object. (by the way: again, this is the same in the GUI. If object 5 is deleted and you use "Edit -> Go To" and deletions are not shown then you get the message "Absolute Number 5 was not found". So "Go To" is the GUI equivalent of the function object (id))

2. Yes, that looks well for now. As mentioned before: you wrote this function as a central, universal function, perhaps to be added to a DXL library that you create later. This function will be used in a bigger script that you write later. Now, it depends on the calling script whether it is OK if the function terminates terminates the complete script when e.g. the object is already deleted or whether you want to be able to react in the calling script to the fact that the object could not be deleted. So, at a later time you might want to add a different kind of error reporting / transport system to your function. For now, everything looks OK.

Regards,
Mike

(bow) Thank you for taking the trouble to help me. I do appreciate it

.