This chapter provides a use case for the Role API that describes how to create, read, update, delete, or query a role in Oracle Enterprise Repository.
This chapter includes the following sections:
The Role Subsystem provides a Web Services-based mechanism that is used to create, read, update, query, and otherwise manipulate Oracle Enterprise Repository Roles.
For more information, see Chapter 31, "User API".
import com.flashline.registry.openapi.entity.Role; import com.flashline.registry.openapi.query.RoleCriteria;
This section describes the use case using the Role API. It includes the following topic:
Create a new role
Read a role
Update a role
Delete a role
Query for roles
Example 28-1 Use Case: Manipulate Roles
package com.flashline.sample.roleapi; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import java.util.Calendar; import javax.xml.rpc.ServiceException; import com.flashline.registry.openapi.base.OpenAPIException; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.entity.Role; import com.flashline.registry.openapi.query.RoleCriteria; import com.flashline.registry.openapi.service.v300.FlashlineRegistry; import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator; public class Roles { public static void main(String pArgs[]) throws OpenAPIException, RemoteException, ServiceException { try { /////////////////////////////////////////////////////////// // Connect to Oracle Enterprise Repository /////////////////////////////////////////////////////////// URL lURL = null; lURL = new URL(pArgs[0]); FlashlineRegistry repository = new FlashlineRegistryServiceLocator() .getFlashlineRegistry(lURL); // ////////////////////////////// // Authenticate with OER // ////////////////////////////// AuthToken authToken = repository.authTokenCreate(pArgs[1], pArgs[2]); // ----------------------------------------- // Create a new role String lName = "new_role_type_name"; String lDesc = "new_role_type_desc"; boolean lDeafultForNewUser = true; Role lRole = null; lRole = repository.roleCreate(authToken, lName, lDesc, lDeafultForNewUser); // ----------------------------------------- // Read a Role String lRoleName = lName; Role lRole2 = null; lRole2 = repository.roleRead(authToken, lRoleName); // ----------------------------------------- // Update a Role String lRoleName3 = lName; Role lRole3 = null; lRole3 = repository.roleRead(authToken, lRoleName3); lRole3.setName("user_modified"); lRole3.setStatus(20); lRole3 = repository.roleUpdate(authToken, lRole); // ----------------------------------------- // Delete a Role String lRoleName4 = "user_modified"; // role name must exist in OER Role lRole4 = repository.roleRead(authToken, lRoleName4); if (lRole4==null) { lRole4 = repository.roleRead(authToken, lName); } if (lRole4!=null) { try { repository.roleDelete(authToken, lRole4.getName()); } catch (OpenAPIException e) { e.printStackTrace(); } } // ----------------------------------------- // This method is used to query for roles. Role[] lRoles = null; RoleCriteria lRoleCriteria = null; lRoleCriteria = new RoleCriteria(); lRoleCriteria.setNameCriteria("user"); lRoles = repository.roleQuery(authToken, lRoleCriteria); } catch (OpenAPIException lEx) { System.out.println("ServerCode = " + lEx.getServerErrorCode()); System.out.println("Message = " + lEx.getMessage()); System.out.println("StackTrace:"); lEx.printStackTrace(); } catch (RemoteException lEx) { lEx.printStackTrace(); } catch (ServiceException lEx) { lEx.printStackTrace(); } catch (MalformedURLException lEx) { lEx.printStackTrace(); } } }