CRecordUserDbCreateRole
Create a role in the user database.
    This message belongs to the Session Manager API.
    The Session Manager is part of the NY_Session2PlugIn plugin.
{
  "id": "8c254063-959a-4cb3-8736-242c1a59ad69",
  "name": "USER_DB_CREATE_ROLE ",
  "description": "Create a role.",
  "slots": [
    {
      "key": "1",
      "name": "ROLE_RECORD",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "RECORD",
      "description": "The role record."
    }
  ]
}
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IIdSESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");
    The own SessionToken is needed to verify the authorization for the change.
    You need the permission NY_CreateRole.
    In addition, the role id, the role description and a protected flag are required.
    The protected flag is used only by system roles. It prevents the deletion of the new role.
private void createRole(final byte[] aToken,
                        @NotNull final String aRoleId,
                        @NotNull final String aDescription,
                        final boolean aIsProtected) throws CException
{
    final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID );
    env.setSessionToken(aToken);
    final CRecord record = CRecordUserDbCreateRole .create();
    // create role record:
    final CRecord recordRole = CRecordUserDbRoleRecord.create();
    CRecordUserDbRoleRecord.setRoleId(recordRole,
                                      aRoleId);
    CRecordUserDbRoleRecord.setDescription(recordRole,
                                           aDescription);
    CRecordUserDbRoleRecord.setIsProtected(recordRole,
                                           aIsProtected);
    // createdBy and timeCreated are set by the user database
    // add role record:
    CRecordUserDbCreateRole .setRoleRecord(record,
                                          recordRole);
    sendRequest(env,
                record);
}
Dealing with the response
To catch the response of the request, we need a message handler. We add it in the constructor of the message handler registry.
// constructor: addMessageHandler(CRecordUserDbCreateRole .ID, this::asyncCreateRole );
private booleanasyncCreateRole (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { // ... } return true; } return false; }
