Questetra 組織メンバー追加

Questetra の「組織」にメンバーを追加し、通信ログを文字型データ項目に格納します

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

Configs
  • A: OAuth2通信許可設定名 (←[OAuth 2.0 設定]) *
  • A2: Application-Root URI をセットしてください ( https://your-sub-domain.questetra.net/ ) * #{EL}
  • B: Qgroup ID(組織ID)が格納されている文字列型or組織型orチェックボックス型データを選択してください *
  • C: Quser のメールアドレスが格納されている文字列型データorユーザ型データを選択してください *
  • X: 通信ログが格納される文字列型データを選択してください (更新)
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_qgroupId = configs.get( "conf_QgroupId" );
  const conf_quser = configs.get( "conf_Quser" );
  const conf_response = configs.get( "conf_Response" );

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

  // qgroupId
  let targetGroups = [];
  if( engine.findDataDefinitionByNumber( conf_qgroupId ).matchDataType( "SELECT_CHECKBOX" ) ) {
    const selectedGroups = engine.findDataByNumber( conf_qgroupId ); // java.util.List<com.questetra.bpms.core.event.scripttask.ItemView>
    for( let i = 0; i < selectedGroups.size(); i++ ){
      const pushGroupId = selectedGroups.get(i).getValue(); // java.lang.String
      if ( !isEmpty(pushGroupId) ) {
        targetGroups.push( pushGroupId );
      }
    }
  } else if( engine.findDataDefinitionByNumber( conf_qgroupId ).matchDataType( "QGROUP" ) ) {
    const pushGroup = engine.findDataByNumber( conf_qgroupId ); // com.questetra.bpms.core.event.scripttask.QgroupView
    if ( pushGroup !== null) {
      targetGroups.push( pushGroup.getId() );
    }
  } else {
    const pushGroupId = engine.findDataByNumber( conf_qgroupId );
    if ( !isEmpty(pushGroupId) ) {
      targetGroups.push( pushGroupId);
    }
  }

  if ( targetGroups.length == 0 ) {
    throw "Qgroup ID is empty.";
  } else if ( targetGroups.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/Membership/add";

  let responseString = "";

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

   // API Execute
   const httpResponse = httpClient.begin()
     .authSetting( oauth2 )
     .formParam( "quserId",  userId + "")
     .formParam( "qgroupId", targetGroups[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;
    }

    const responseJson = JSON.parse(responseTxt);
    responseString = responseString + "\n" + "add to Organization(ID:" + responseJson.membership.qgroupId + ", Name:" + responseJson.membership.qgroupName + ") 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

  • [システム設定]>[APIクライアント]>[OAuth2 クライアント一覧]より、「OAuth2 クライアント」を登録し、「クライアントID」「クライアントシークレット」を取得してください

See also

%d人のブロガーが「いいね」をつけました。