CRecordUserDbUpdateRight

This message saves changed data of a rights record in the user database.

This message belongs to the Session Manager API.
The Session Manager is part of the NY_Session2PlugIn plugin.

{
  "id": "5bac1cec-7e53-4ee5-9384-8d0fcc6d91ee",
  "name": "USER_DB_UPDATE_RIGHT",
  "description": "Update right data.",
  "slots": [
    {
      "key": "1",
      "name": "RIGHT_ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The right id."
    },
    {
      "key": "2",
      "name": "DESCRIPTION",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The description of the right."
    }
  ]
}

Usage

Sending the request

You need the microservice ID of the session manager:

public static final IId SESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");

To update a right record, we need the right ID. Additionally, we need the session token of the current user to check the right to this request. The executing user needs the NY_EditRight permission.

private void updateRight(final byte[] aToken,
                         @NotNull final String aRightId,
                         @NotNull final String aDescription) throws CException
{
    final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);
    env.setSessionToken(aToken);

    final CRecord record = CRecordUserDbUpdateRight.create();
    CRecordUserDbUpdateRight.setRightId(record,
                                        aRightId);
    CRecordUserDbUpdateRight.setDescription(record,
                                            aDescription);
    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(CRecordUserDbUpdateRight.ID,
                  this::asyncUpdateRight);
private boolean asyncUpdateRight(@NotNull final CEnvelope aEnvelope,
                                 @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        final int resultCode = aEnvelope.getResultCode();
        if (resultCode == CResultCode.SUCCESS)
        {
            final String rightId = CRecordUserDbUpdateRight.getRightId(aRecord,
                                                                       null);
            // ...
        }
        return true;
    }
    return false;
}