If your organization requires that the creation of new shared workspaces must be approved by responsible parties, you can use the Workspace API to enable this process.
You do so by implementing a portal service that extends the AbstractApprovalRequest class.
It works as follows:
When a new workspace is created, the system calls the needApproval method of your service to check if the approval is needed for the specified user.
If true, the system calls the requestApproval method of your service to initiate an asynchronous approval request.
Once the approval request is processed, you notify the system of the result by calling the approve method of the IApproval service.
The following code samples illustrate how to implement a workspace creation approval process.
Approval Classpublic class ApprovalOfWorkspaceCreation extends AbstractApprovalRequest { // Check if the workspace creation by the specified user needs approval public boolean needApproval(IUser user) { if (user.isMemberOfGroup("all_managers_group_ID", true)) { // If more than 1000 shared workspaces exist in the system, managers also need approval if (countWorkspaces(user) < 1000) { return false; } } return true; } private int countWorkspaces(IUser user) { IWorkspaceDirectory workspaceDirectory = (IWorkspaceDirectory) RuntimeFactory.getWorkspacesRuntime().getService(IWorkspaceDirectory.class); WorkspaceFilter filter = new WorkspaceFilter(); // Private, public and restricted workspaces filter.setPermissionPolicies(new PermissionPolicy[]{PermissionPolicy.PRIVATE, PermissionPolicy.PUBLIC, PermissionPolicy.RESTRICTED}); // Draft, pending and published, but not closed workspaces filter.setStatuses(new Status[]{Status.DRAFT, Status.PENDING, Status.PUBLISHED}); // Only shared workspaces filter.setTypes(new Type[]{Type.SHARED}); return workspaceDirectory.getWorkspacesCount(user, filter); } // Check if the approver can approve the workspace creation public boolean canApprove(IUser user, IUser approver) { if (user.isMemberOfGroup("IT_managers_group_ID", true)) { return true; } else { return false; } } // Start an offline approval process, for example, by sending an email to request approval. // The email can provide a link to UI in which the user can process the approval request. public void requestApproval(IUser user, IWorkspace workspace) { // ... } }
From the UI in which the approval request is processed, you call the approve method of the IApproval interface to notify the system of the result. Note that this call should not be part of the above class.
Notification of Approvalpublic void approve(IUser approverUser, IWorkspace workspace, boolean approved,String reason) { IApproval approval = (IApproval) RuntimeFactory.getWorkspacesRuntime().getService(IApproval.class); approval.approve(approved, approverUser, workspace, reason); }
Finalize and deploy your service.
Navigate to
.In the Handle Workspace Approval Requests (Service) field, enter prt_service:<your service key>.