cancel
Showing results for 
Search instead for 
Did you mean: 

Copy or Create PCD Role Programmatically

0 Kudos

Hello,

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.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
envAdm.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_ADMINISTRATION);
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,

Luisa

Accepted Solutions (0)

Answers (1)

Answers (1)

detlev_beutner
Active Contributor
0 Kudos

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
Detlev