Questetra Role Membership Delete

Questetra ロールメンバー削除

Deletes a member from Questetra’s “Role” and stores the communication log in a String type Data Item

© Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/questetra-rolemembership-delete/

Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • A2: Set Application-Root URI ( https://your-sub-domain.questetra.net/ ) * #{EL}
  • B: Select STRING/CHECKBOX DATA for Qrole Id (Role Id) *
  • C: Select STRING/USER DATA for Quser Email *
  • X: Select STRING DATA for Access Log (update)
Script (click to open)


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main() {

  //// == Config Retrieving / 工程コンフィグの参照 ==
  //// == Data Retrieving / ワークフローデータの参照 ==
  //// == Validation / 入力チェック
  const oauth2  = configs.get( "conf_OAuth2" );
  const applicationRoot = configs.get( "conf_ApplicationRoot" );
  const conf_qroleId = configs.get( "conf_QroleId" );
  const conf_quser = configs.get( "conf_Quser" );
  const conf_response = configs.get( "conf_Response" );

  // ApplicationRoot
  if ( isEmpty(applicationRoot) ) {
    throw "Application-Root URI is empty.";
  } 

  // qroleId
  let targetRoles = [];
  if( engine.findDataDefinitionByNumber( conf_qroleId ).matchDataType( "SELECT_CHECKBOX" ) ) {
    const selectedRoles = engine.findDataByNumber( conf_qroleId ); // java.util.List<com.questetra.bpms.core.event.scripttask.ItemView>
    for( let i = 0; i < selectedRoles.size(); i++ ){
      const pushRoleId = selectedRoles.get(i).getValue(); // java.lang.String
      if ( !isEmpty(pushRoleId) ) {
        targetRoles.push( pushRoleId );
      }
    }
  } else {
    const pushRoleId = engine.findDataByNumber( conf_qroleId );
    if ( !isEmpty(pushRoleId) ) {
      targetRoles.push( pushRoleId );
    }
  }

  if ( targetRoles.length == 0 ) {
    throw "Qrole ID is empty.";
  } else if ( targetRoles.length > httpClient.getRequestingLimit() ) {
    throw "Number of requests is over the limit";
  }

  // quserId
  let userId = "";
  if( engine.findDataDefinitionByNumber( conf_quser ).matchDataType( "QUSER" ) ) {
    const quser = engine.findDataByNumber( conf_quser ); // com.questetra.bpms.core.event.scripttask.QuserView
    if ( quser != null ) {
      userId = quser.getId();
    } else {
      throw "Quser is empty.";
    }
  } else {
    const userEmail = engine.findDataByNumber( conf_quser ); // java.lang.String
    if ( !isEmpty(userEmail) ) {
      const quser = quserDao.findByEmail( userEmail ); // com.questetra.bpms.core.event.scripttask.QuserView
      if ( quser != null ) {
        userId = quser.getId();
      } else {
        throw "There is no user for Email.";
      }
    } else {
      throw "Email is empty.";
    }
  }

  if ( userId === "" ) {
    throw "Quser is invalid.";
  }


  //// == Calculating / 演算 ==
  const apiUri = applicationRoot + "API/UGA/RoleMembership/delete";

  let responseString = "";

  for( let j = 0; j < targetRoles.length; j++  ){ // javascript array

   // API Execute
   const httpResponse = httpClient.begin()
     .authSetting( oauth2 )
     .formParam( "quserId",  userId + "")
     .formParam( "qroleId", targetRoles[j] + "")
     .post( apiUri );

    const status = httpResponse.getStatusCode();
    const responseTxt = httpResponse.getResponseAsString();

    if (status >= 300) {
      const error = `Failed to create\nstatus:${status}`;
      engine.log(responseTxt);
      throw error;
    }

    responseString = responseString + "\n" + "delete from Role(ID:" + targetRoles[j] + ") success.";
  }

  //// == Data Updating / ワークフローデータへの代入 ==
  if ( conf_response !== null && conf_response !== "" ){
    engine.setDataByNumber( conf_response, responseString.slice(1) );
  }

} //////// END "main()" /////////////////////////////////////////////////////////////////



/**
 * NULL・空文字判定
 * @param {java.lang.String} param
 * @return {boolean} True: Null or empty text, False: Not Null text
 */
function isEmpty( param ) {

  if ( param != null && !param.equals("") ) {
    return false;
  }
  return true;
}

Download

Capture

Notes

  • Register an OAuth2 Client and aquire the Client ID and Client secret at [OAuth2 Clients] < [API Clients] < [System Settings]

See also

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top