"Owner" bulk change

I have over 100 scheduled reports and jobs and user (owner) is leaving company, so I’m wondering if anyone done bulk change similar like this example. SDK will work, but I need a code. Non-SDK solution even better… :-X

Thanks in advance for your suggestions!

Alex

Come on guys… nobody have done this before? I can’t believe so… Anything would help.

Alex,

this is some code i found. i’m not sure if you can change the ownerships without SDK… Maybe with a tool like Motio http://www.inmotio.com/investigator/home.do or navision?

// Licensed Material - Property of IBM
// © Copyright IBM Corp. 2003, 2009
package cognos8;
/**
 * TakeOwnership.java
 *
 * Copyright © Cognos Incorporated. All Rights Reserved.
 * Cognos and the Cognos logo are trademarks of Cognos Incorporated.
 *
 * Description: (KB 1004715) - How to change the ownership of all objects in content using ReportNet SDK
 * 
 */

import com.cognos.developer.schemas.bibus._3.*;

public class TakeOwnership {
	
	private ContentManagerService_ServiceLocator cmServiceLocator = null;
			
	private ContentManagerService_Port cmService = null;

   	public static void main(String[] args) 
   	{
   		//if Anonymous is to be used comment the next lines up to TakeOwnership connect = new TakeOwnership();
   		if (args.length < 3)
   		{
   			System.out.println("Usage: \njava TakeOwnership <namespace> <userid> <password> ");
   			System.out.println("Example: \njava TakeOwnership sldap user1 password1");
   			System.exit(1);
   		}
   		
   		String nameSpace = args[0];
   		String userID = args[1];
   		String pass = args[2];
   		
   	
	   TakeOwnership connect = new TakeOwnership();
	   connect.connectToReportServer();
	   connect.quickLogon(nameSpace, userID, pass);	
	   connect.takeOwnership();
	}

	public void takeOwnership()
	{
		Account currentAccount = new Account();

		if(cmService != null)
		{
			try
			{
				SearchPathMultipleObject searchPath = new SearchPathMultipleObject();
				searchPath.setValue("~");
				
				BaseClass bc[] = cmService.query(searchPath, new PropEnum[]{PropEnum.searchPath}, new Sort[]{}, new QueryOptions());

				if(bc != null)
				{
					if(bc.length > 0)
					{
						for(int i = 0 ; i < bc.length; i ++)
						{
							currentAccount = (Account)bc[i];
						}
					}
				}
			}
			catch(Exception e)
			{
				System.out.println(e.getMessage());
			}
		}
		
		try 
		{
			PropEnum props[] = new PropEnum[] { PropEnum.searchPath, PropEnum.owner, PropEnum.defaultName };
			
			
			SearchPathMultipleObject searchPath = new SearchPathMultipleObject();
			//searchPath.setValue("/content//*"); // A large content store can lead to a java.lang.NullPointerException
			searchPath.setValue("/content/folder[@name='testing']//*");
			BaseClass obj[] = cmService.query(searchPath,props, new Sort[]{}, new QueryOptions());
			
			for (int i=0; i< obj.length; i++)
			{
				System.out.print(obj[i].getDefaultName().getValue() + "\n");
				System.out.print("    " + obj[i].getSearchPath().getValue() + "\n" );
				if (obj[i].getOwner().getValue() != null )
				{	
					
					if ((obj[i].getOwner().getValue()[0].getSearchPath().getValue()).compareToIgnoreCase(currentAccount.getSearchPath().getValue()) != 0)
					{	
						System.out.println("Old owner " + obj[i].getOwner().getValue()[0].getSearchPath().getValue()  );
						BaseClassArrayProp newOwner = new BaseClassArrayProp();
						newOwner.setValue(new BaseClass []{currentAccount});
						obj[i].setOwner(newOwner);
						cmService.update (new BaseClass []{obj[i]}, new UpdateOptions());
						System.out.println("New owner " + obj[i].getOwner().getValue()[0].getSearchPath().getValue()  );
					}
				}
				else {
					System.out.println("Owner is null");
					BaseClassArrayProp newOwner = new BaseClassArrayProp();
					newOwner.setValue(new BaseClass []{currentAccount});
					obj[i].setOwner(newOwner);
					cmService.update (new BaseClass []{obj[i]}, new UpdateOptions());
					System.out.println("New owner " + obj[i].getOwner().getValue()[0].getSearchPath().getValue()  );
				}
			}
			
			System.out.println("Complete - the owner has changed for all objects in content.");
		}
		catch( Exception ex) 
		{
			System.out.println(ex);
		}
		
	}


	public String quickLogon(String namespace, String uid, String pwd)
	{
		StringBuffer credentialXML = new StringBuffer();

		credentialXML.append("<credential>");
		credentialXML.append("<namespace>").append(namespace).append("</namespace>");
		credentialXML.append("<username>").append(uid).append("</username>");
		credentialXML.append("<password>").append(pwd).append("</password>");
		credentialXML.append("</credential>");

		String encodedCredentials = credentialXML.toString();
		try
		{		cmService.logon(new XmlEncodedXML(encodedCredentials), new SearchPathSingleObject[]{});
		}catch (Exception e)
		{System.out.println(e);}
		return ("Logon successful as " + uid);
	}
	
	public void connectToReportServer ()
		{		
			// Default URL for CRN Content Manager
			String endPoint = "http://localhost:9300/p2pd/servlet/dispatch";        
			// Retrieve the service            
			cmServiceLocator = new ContentManagerService_ServiceLocator();


			try
			{
				java.net.URL serverURL = new java.net.URL(endPoint);
			
				//acquire references to Cognos 8 Services
				//
				
				cmService = cmServiceLocator.getcontentManagerService(serverURL);
			}
			catch(Exception e)
			{
				System.out.println(e.getMessage());
			}
		}

}

Thanks! I’ll review JAVA file and Motio. BTW: I know Motio and I’m using MotioPI for a while now, but I didn’t see anything there… well, I’ll look again, more deeper… 8)

Alex

sorry, what i meant was that you may use MotioPI to get a list of reports of the user who is leaving your company. I have not used MotioPI recently, so i can be mistaken… :o

here is also a SDK script which changes the scheduled by owner.

// Licensed Material - Property of IBM
// © Copyright IBM Corp. 2003, 2010
/**
 * updateSchedule.java
 *
 * Copyright © Cognos Incorporated. All Rights Reserved.
 * Cognos and the Cognos logo are trademarks of Cognos Incorporated.
 *
 * Description: (technote 1423681) - SDK Sample to change the scheduled by owner to the current user.     
 * 
 */
import org.apache.axis.client.Stub;

import com.cognos.developer.schemas.bibus._3.*;

public class updateSchedule
{
	public ContentManagerService_ServiceLocator cmServiceLocator = null;
	public ContentManagerService_Port cmService = null;
 
  	public updateSchedule(String endpoint)
	{
		// Retrieve the service           
  		cmServiceLocator = new ContentManagerService_ServiceLocator();
		try
		{
			cmService = cmServiceLocator.getcontentManagerService(new java.net.URL(endpoint));			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
  	
	public String quickLogon(String namespace, String uid, String pwd)
	{
		StringBuffer credentialXML = new StringBuffer();

		credentialXML.append("<credential>");
		credentialXML.append("<namespace>").append(namespace).append("</namespace>");
		credentialXML.append("<username>").append(uid).append("</username>");
		credentialXML.append("<password>").append(pwd).append("</password>");
		credentialXML.append("</credential>");

		String encodedCredentials = credentialXML.toString();
		try
		{		cmService.logon(new XmlEncodedXML(encodedCredentials), new SearchPathSingleObject[]{});
		}catch (Exception e)
		{System.out.println(e);}
		return ("Logon successful as " + uid);
	}
	
	public void generateCredentials(String search)
	{
		try
		{
            PropEnum[] props = {PropEnum.searchPath};
                                    
            BiBusHeader bibus = (BiBusHeader)((Stub)cmService).getHeaderObject("","biBusHeader");
            
            if(bibus != null)
            {
            	CAM newCam = bibus.getCAM();
            	if(newCam != null)
            	{
            		newCam.setAction("generateTC");
	            	
	            	bibus.setCAM(newCam);
		            BiBusHeader bibus2 = (BiBusHeader)((Stub)cmService).getHeaderObject("","biBusHeader");
		            CAM c = bibus.getCAM();
            	}

	            ((Stub)cmService).setHeader("","biBusHeader", bibus);
            }

	      BaseClass[] objects2 = cmService.query(new SearchPathMultipleObject(search), props, 
	      		new Sort[] {}, new QueryOptions());
        }
        catch(Exception e)
        {
            System.out.println("Login exception message: " + e.getMessage() );
        }
		
	}
  	
	public void updSchedule(String sPath) 
	{
		try 
		{
			
			PropEnum props[] = new PropEnum[]{ PropEnum.searchPath, PropEnum.credentials};
			
			//Query content store to get the schedule of the report
			BaseClass[] selectSchedule = cmService.query(new SearchPathMultipleObject(sPath + "/schedule"),props,new Sort[]{},new QueryOptions());
			if (selectSchedule != null && selectSchedule.length >0)
			{	
				//get the search path of the user that is currently logged in
				PropEnum[] properties =
					{ PropEnum.defaultName, PropEnum.searchPath };
				SearchPathMultipleObject qPath = new SearchPathMultipleObject();
				qPath.setValue("~");
				
				BaseClass[] results= new BaseClass[1];
				try 
				{
					 results =
						 cmService.query(qPath, properties, new Sort[]{}, new QueryOptions());
				}
				catch( Exception ex ) 
				{
					System.out.println( "Unhandled exception!" );
					System.out.println( "Message: " + ex.getMessage() );
					ex.printStackTrace();
					return;
				} 

				//set the credential used to run the report to the current user or "Anonymous" user.
				BaseClassArrayProp credentials = new BaseClassArrayProp();
				Credential crd = new Credential();

				StringProp crdPath = new StringProp();
				
				//comment out the following line if you want to use current SDK users credential
				//crdPath.setValue("CAMID('::Anonymous')/credential[@name='Credential']");
				
				//Generate credential for the user
				generateCredentials(results[0].getSearchPath().getValue());
				
				//comment out the following line if you want to use "Anonymous" users credential
				crdPath.setValue(results[0].getSearchPath().getValue() + "/credential[@name='Credential']");
				crd.setSearchPath(crdPath);

				//Get schedule object and update to new credential
				for (int i=0; i<selectSchedule.length;i++)
				{
					Schedule schedule = (Schedule)selectSchedule[i];
					
					schedule.setCredential(credentials);
					schedule.getCredential().setValue(new BaseClass[] { crd });
					
					selectSchedule = new BaseClass[]{schedule};
					cmService.update(selectSchedule, null);
					System.out.println("schedule is updated");						
				}
			}
			else
				System.out.println("No schedule is found");
			
		}
		catch( Exception ex) 
		{
			System.out.println(ex);
		}
	}
	
	public static void main(String[] args)
	{
			
		// Variable that contains the default URL for CRN.			
		String endpoint = "http://localhost:9300/p2pd/servlet/dispatch";
		
		// Variable for report search path
		String sPath = "/content/package[@name='GO Sales (query)']/folder[@name='Report Studio Report Samples']/report[@name='Horizontal Pagination']";

		updateSchedule et = new updateSchedule(endpoint);
		
		// Login to cognos CM service
		String nameSpaceID = "LOCALNT";
		String userName = "test";
		String password = "Education1!";
		
		String loginas = et.quickLogon(nameSpaceID, userName, password);
		
		System.out.println(loginas);
		
		// Update the schedule credential with logged in user
		et.updSchedule(sPath);
	}
}


I see… thanks for the second file! I’ll check that out as well…

In MotioPI there is a panel called Orphaned Objects. In there you can search for any report/query/analysis (Update: Jobs and Schedules were added to beta recently) that has an owner specified but the user isn’t found in your namespace. From there you can select objects and click the “Change Ownership” button to take ownership of the object.

So if you delete the user that is leaving your company from cognos, then open up the panel in MotioPI, you should get back a list of objects owned by them. Currently all objects that fit the criteria of “owner not found in current namespace” will show up, so you may have to go through and select each object individually. There is a feature being worked on that will allow you to specify user name and namespace (ETA is ~1-2 days).

You can email pi-support@motio.com and request to be notified when the Orphaned Object panel user name and namespace filter is available.

He Tony,

this sounds like inside information! ;D Are you a developer for MotioPI ???

thx!

Thanks Tony! I saw that option under MotioPI, but that won’t exactly work for me as I need assign an owner somebody else, not myself. As you mentioned, maybe in 2-3 days new version will be able to help me, but for now I’m still looking into JAVA solution. Please update this topic when new version will be available on your site.

The current release of MotioPI has changed login to allow non-Admin login. So if the desired owner logs in to MotioPI and opens the orphaned objects panel they will be able to change the ownership of those objects to themselves.

I want to do this for them: I’m (Administrator) want to change orphan entry to someone else, not them to do it.

Alex,

What is the status of this script to change the owner of some reports. It sounds interesting for a client in the near future… ;D

cheers

It get lower priority for me now… but I’ll get back to it soon to finish that up. Will post resolution here, once I’m done, don’t worry… 8)

Here you go… I was able to finish it only for scheduler owner, not an actual report. See attached script (rename it from .TXT to .JAVA prior to use), but please use caution when use it. Read my tips throughout this script that will help you to adjust it for your own environment.

Also, keep in mind, I’m not a JAVA guru, so I did it as much as my knowledge allowed me… ::slight_smile:

Please post back if you may offer any improvement as I would like to hear any feedback if I can do this better, next time.

Good luck and I hope you can find it useful.

Alex

P.S. Not sure if this code should go here or under other content such as Library, Knowledge Articles, etc., so maybe Administrator can move it, if necessary.