Jump to content


p4java - Submit changelist of another user using superuser

submit p4java

  • Please log in to reply
4 replies to this topic

#1 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 07 July 2014 - 01:32 PM

Hi
I want to use a super user to submit any changelist (from any user)
I know that using CLI, I can run P4 login UserName without password and than submit.
How can I do it with Java API?

Thanks in advance,
Eran.

#2 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 08 July 2014 - 11:58 AM

some clarifications:
I'm getting a shelved changelist Id and I need to submit it.
The changelist was created by any user in the organization...

I want that after the submission, the same changelist will be submitted and the owner will remain the original user.

Currently I managed to get this flow to work:
1) Change changelist owner to the super-user.
2) Submit the shelved files.

The problems are:
1) The original changelist is deleted (the super user submit the files in a different changelist = different ID)
2) I can't get (by script) the new changelist ID (I need it for changing the owner to the original user from the original changelist)

my questions are:
1) Why is the changelist change number when submitting it? Is there a way to prevent it  from happening?
2) Is there a better way to do what I try to do?


Thanks in advance
Eran

#3 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 09 July 2014 - 12:35 AM

To login as a Super user and impersonate another use the 'IOptionsServer' login method:

void login(IUser user,
		   StringBuffer ticket,
		   LoginOptions opts)
		   throws P4JavaException


For example:

			// Connect as the super user (super)
			IOptionsServer server = ServerFactory.getOptionsServer("p4java://localhost:1666", null);
			server.connect();
			server.setUserName("super");
			server.login("Password");

			// Impersonate the other user (test)
			IUser otherUser = server.getUser("test");
			server.login(otherUser,null,null) ;   // gets ticket, no password needed
			server.setUserName("test");	   


An example of using this would be to update a user's changelist description:

			// Update the description for 'test' users changelist
			IChangelist myPendingChange = server.getChangelist(246186);
			myPendingChange.setDescription("This is the new description text.");
			myPendingChange.update();

To answer your other questions about changelist numbers changing upon submit, see the following:

    http://answers.perfo...bered-on-Submit

#4 eranb

eranb

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts

Posted 09 July 2014 - 11:19 AM

Thanks!
Any idea if I can get "Original Changelist" using JAVA API? (is there an implementation for p4 change -o -O changeNum described in the link above)
I prefer not to run server.execStreamCmd(...) and parse output.
I couldn't see any variable for this value in the Changelist implementation.

Thanks

#5 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 09 July 2014 - 05:13 PM

Yes, in the p4java manual there is a method under 'IOptionsServer.getChangelist' to set original changelist:

	  ChangelistOptions  setOriginalChangelist(boolean originalChangelist)

The field summary mentions:

   Options: -s, -f, -u, -O

I am not sure where you were looking but you definitely want to use the Java API manual (http://www.perforce....p4java-javadoc/) for reference as these answers are there.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users