Show TOC

Enabling Approval of Workspace CreationLocate this document in the navigation structure

Use

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:

  1. 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.

  2. If true, the system calls the requestApproval method of your service to initiate an asynchronous approval request.

  3. Once the approval request is processed, you notify the system of the result by calling the approve method of the IApproval service.

Implementing an Approval Service

The following code samples illustrate how to implement a workspace creation approval process.

Approval Class
public 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 Approval
public void approve(IUser approverUser, IWorkspace workspace, boolean approved,String reason) 
{
	IApproval approval = (IApproval) RuntimeFactory.getWorkspacesRuntime().getService(IApproval.class);
	approval.approve(approved, approverUser, workspace, reason);
}
Configuring the Approval Service
  1. Finalize and deploy your service.

  2. Navigate to Start of the navigation path Workspace Administration  Next navigation step Workspaces Next navigation step Management  End of the navigation path.

  3. In the Handle Workspace Approval Requests (Service) field, enter prt_service:<your service key>.