Skip to Content

Copy or Create PCD Role Programmatically

Aug 09, 2017 at 03:47 PM


avatar image
Former Member


I'm working with PCD APIs on an 7.4 environment.

We need to duplicate or create a PCD Role programmatically.

I saw in an archived post that there was the possibility to copy a PCD Role using:

Hashtable envAdm = new Hashtable();
envAdm.put(Context.SECURITY_PRINCIPAL, user);
IAdminBase roleToCopy = (IAdminBase) admCtx.lookup(fullPath);
PcmInteractiveDirOperations op = (PcmInteractiveDirOperations) roleToCopy.getImplementation(IAdminBase.INTERACTIVE_DIR_OPERATION);
op.copy(fullTargetPathWithID, null);

I tried to use it but it gives me a "java.lang.UnsupportedOperationException: copy() not supported by default pcm implementation".

Is there a way to perform, programmatically, a copy or a creation of a PCD Portal Role?

Thanks in advance,


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Detlev Beutner Jan 07 at 11:49 AM

Hi Luisa,

The code fragment you found was published by me, and now I have run into the same issue during an upgrade project. Anyhow, although finding these following code lines was all but trivial, the solution is shorter than it was before:

String pathFrom = "pcd:portal_content/original_path/to/original_role";
String pathTo = "pcd:portal_content/folder_path/to_copy_role_to"; IUser user = request.getUser(); String sessionID = request.getServletRequest().getSession().getId();
AbstractAdvancedOperation copyOperation = new CopyOperation();
copyOperation.init(pathFrom, pathTo, sessionID, null, null, user);
copyOperation.execute(pathFrom, pathTo, sessionID, user);

Keep in mind: pathFrom is a full ID including the role itself; whereas pathTo is just the folder object to copy that role to.

The API is - exactly as the old version - not published by SAP and therefore not to be used officially. It is also counterintuitive (to pass all elements twice), but hey, it's just an API which should never see the public daylight, so, it was not developed by API designers. Anyhow: It works!

If you would want to learn a bit more about it, decompile "AbstractAdvancedOperation", then you'd learn how "execute" is just a helper around "deBefore", "doOperation", "doAfter" & "doOperationCleanup". The parameters of "execute" are totally superflous, so you also could call "execute" with "null, null, null, null".

Hope it helps

10 |10000 characters needed characters left characters exceeded