COGNOiSe.com - The IBM Cognos Community

Legacy Business Intelligence => COGNOS ReportNet => SDK => Topic started by: woowoo on 08 Apr 2008 12:27:23 PM

Title: Removing reports that belong to a user
Post by: woowoo on 08 Apr 2008 12:27:23 PM
When removing user accounts from our Access Manager, for some reason, the reports that the user owns are not being removed. As we have about 200+ accts to remove, we are looking for a way to use the SDK to remove the reports before removing the accts, so we do not get orphaned reports. Does anyone have this type of script already?

TIA
Title: Re: Removing reports that belong to a user
Post by: avitabj on 09 Apr 2008 12:15:59 PM
Hi!  Here's a snippet of the code I use

userPath = namespaceSearchPath + "//account[@userName=\"" + username +"\"]";
PropEnum props[] = new PropEnum[]{   PropEnum.defaultName,
            PropEnum.modificationTime,
            PropEnum.screenTip,
            PropEnum.searchPath};   
try
{
   BaseClass[] user = oCrn.query(userPath, props, new Sort[]{}, new QueryOptions());
   if (user.length == 0)
   {
      (unknown user)   
             }
   else
   {
   //   if user has modification time then they've logged in to ReportNet and have a My Folders
      if (user[0].getModificationTime().getValue() != null)
      {
         //   Get name of My Folders folder, user can change
         String userFolderPath = user[0].getSearchPath().getValue() + "/child::folder";
         PropEnum folderprops[] = new PropEnum[] {PropEnum.searchPath,
                                                                            PropEnum.objectClass,
                  PropEnum.modificationTime,                        PropEnum.defaultName};
         //Query the Content Store for user's folder
         try
         {
            BaseClass bc[] = oCrn.query(userFolderPath, folderprops, new Sort[]{}, new QueryOptions());
            if (bc != null && bc.length > 0)
            {
               //   delete user's My Folders and all it's contents
               DeleteOptions del = new DeleteOptions();
               del.setForce(true);         //   this option will force the delete regardless of owner
               del.setRecursive(true);   //   this option will delete all children
               try
               {
                  BigInteger rc = oCrn.delete(new BaseClass [] {bc[0]}, del);

yadayadayada

hth...jean


Title: Re: Removing reports that belong to a user
Post by: Darek on 15 Jun 2008 07:46:01 PM
Keep in mind this code should be executed BEFORE a user is deleted. Afterwards the userName attribute will be absent.
Title: Re: Removing reports that belong to a user
Post by: avitabj on 16 Jun 2008 09:18:34 AM
judging from the sunday date on your post, i hope you didn't find out the hard way that you need to do the delete reports first    if you did delete the user, i think you can still figure out what reports should be whacked by checking if the owner is null   i haven't had to do this but it seems logical

hth....jean