Questetra Role Membership Deletion

Deletes a member from Questetra's "Role" and stores the communication log in a String type Data Item.
Questetra Role Delete Membership
Questetra-rolemembershipDel-20171211-addonxml.txt
(md5:c1d533fee50780ef223d5bb76c12aa2c)

    • B’: Role stored in the selected Data Item at B
    • C’: User stored in the selected Data Item at C
    • User C’ will be deleted from the Role of B’
    • The communication logs will be stored in the data item selected at X
    • Register an “OAuth2 Client” and aquire the “Client ID” and “Client secret” at [OAuth2 Clients] < [API Clients] < [System Settings]

    A. Set OAuth2 Config Name (at [OAuth 2.0 Setting])Single-line inputRequired
    A2. Set Application-Root URI ( https://... )Single-line inputInserting EL expressions is also possibleRequired
    B. Select STRING/CHECKBOX DATA for Qrole Id (Role Id)Data selectString(single line)orSelect(check box)Required
    C. Select STRING/USER DATA for Quser EmailData selectUserorString(single line)Required
    X. Select STRING DATA for Access Log (update)Data selectString(multiple line)
    -variable namevariable label
    Aconf_OAuth2Set OAuth2 Config Name (at [OAuth 2.0 Setting])
    A2conf_ApplicationRootSet Application-Root URI ( https://... )
    Bconf_DataIdBSelect STRING/CHECKBOX DATA for Qrole Id (Role Id)
    Cconf_DataIdCSelect STRING/USER DATA for Quser Email
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Deleting a Quser from Qrole via Questetra System Settings API (ver. 20171211)
    // (c) 2017, Questetra, Inc. (the MIT License)
    
    //// == Config Retrieving / 工程コンフィグの参照 ==
    var oauth2  = configs.get( "conf_OAuth2" ) + "";
    var applicationRoot = configs.get( "conf_ApplicationRoot" ) + "";
    var dataIdB = configs.get( "conf_DataIdB" ) + "";
    var dataIdC = configs.get( "conf_DataIdC" ) + "";
    var dataIdX = configs.get( "conf_DataIdX" ) + "";
    // convert 'java.lang.String' to 'javascript string'
    
    
    //// == Data Retrieving / ワークフローデータの参照 ==
    var targetGroups = [];
    if( engine.findDataDefinitionByNumber( dataIdB ).matchDataType("SELECT_CHECKBOX") ){
      var selectedGroups = engine.findDataByNumber( dataIdB );
      for( var i = 0; i < selectedGroups.size(); i++ ){ // java.util.ArrayList
        var pushGroup = selectedGroups.get(i).getValue() + "";
        targetGroups.push( pushGroup );
      }
    }else{
      var pushGroup = engine.findDataByNumber( dataIdB ) + "";
      targetGroups.push( pushGroup );
    }
    var userId = "";
    if( engine.findDataDefinitionByNumber( dataIdC ).matchDataType("QUSER") ){
      userId = engine.findDataByNumber( dataIdC ).getId() + "";
      // com.questetra.bpms.core.event.scripttask.QuserView	
    }else{
      var userEmail = engine.findDataByNumber( dataIdC ) + "";
      userId = quserDao.findByEmail( userEmail ).getId() + "";
    }
    
    
    //// == Calculating / 演算 ==
    var accessLog = "";
    var token  = httpClient.getOAuth2Token( oauth2 );
    var apiUri = applicationRoot + "API/UGA/RoleMembership/delete";
    
    for( var i = 0; i < targetGroups.length; i++  ){ // javascript array
      // preparing for API Request
      var apiRequest = httpClient.begin(); // HttpRequestWrapper
      // com.questetra.bpms.core.event.scripttask.HttpClientWrapper
      apiRequest = apiRequest.bearer( token );
      apiRequest = apiRequest.formParam( "quserId",  userId );
      apiRequest = apiRequest.formParam( "qroleId", targetGroups[i] );
    
      // Access to the API (POST, GET, PUT, etc)
      var response = apiRequest.post( apiUri ); // HttpResponseWrapper
      var httpStatus = response.getStatusCode() + "";
      accessLog = "---POST request--- " + httpStatus + "\n";
      accessLog += response.getResponseAsString() + "\n";
    
      // Error Handling
      if( httpStatus !== "200" ){
        if( dataIdX !== "" ){ engine.setDataByNumber( dataIdX, accessLog ); }
        throw new Error( accessLog );
      }
    }
    
    
    //// == Data Updating / ワークフローデータへの代入 ==
    if ( dataIdX !== "" ){ engine.setDataByNumber( dataIdX, accessLog ); }