Google Drive Files Retrieve

Google Drive Files Get
GoogleDrive-filesGet-20171120-addonxml.txt
(md5:899fcd706db12a3274c0ae758ec41021)

    • B’: The file ID of the copy source file stored in the Data Item selected at config B
    • Retrieving the file which file ID of B’, stores it into the data item selected at config C
    • The communication logs are stored in the data item selected in config X
    • You need to register Project at Google API Manager beforehand
    • The file ID is acquired from the shared link in the detailed setting of Shared menu
    • https://drive.google.com/file/d/023W9z6__EXAMPLE__D45EFmY1E/view

    A. Set OAuth2 Config Name (at [OAuth 2.0 Setting])Single-line inputRequired
    B. Select STRING/SELECT DATA for File IDData selectString(single line)orSelect(radio/select/search)Required
    C. Select FILE DATA for File Saved (update)Data selectFileRequired
    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])
    Bconf_DataIdBSelect STRING/SELECT DATA for File ID
    Cconf_DataIdCSelect FILE DATA for File Saved (update)
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Google Drive Files Get (ver. 20171120)
    // (c) 2017, Questetra, Inc. (the MIT License)
    // by Google Drive APIs Files get
    // https://developers.google.com/drive/v3/reference/files/get
    // https://developers.google.com/drive/v3/web/manage-downloads
    
    // OAuth2 config sample at [OAuth 2.0 Setting]
    // - Authorization Endpoint URL: https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    // - Token Endpoint URL: https://accounts.google.com/o/oauth2/token
    // - Scope: https://www.googleapis.com/auth/drive.readonly
    // - Consumer Key: (Get by Google Developers Console)
    // - Consumer Secret: (Get by Google Developers Console)
    
    
    //// == Config Retrieving / 工程コンフィグの参照 ==
    var oauth2 = configs.get( "conf_OAuth2" ) + "";
    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 fileId = "";
    if( engine.findDataDefinitionByNumber( dataIdB ).matchDataType( "SELECT_SINGLE" ) ){
        fileId = engine.findDataByNumber( dataIdB ).get(0).getValue() + "";
    }else{
        fileId = engine.findDataByNumber( dataIdB ) + "";
    }
    var processFiles = engine.findDataByNumber( dataIdC );
    // java.util.ArrayList 
    if (processFiles === null) {
      processFiles = new java.util.ArrayList();
    }
    
    
    //// == Calculating / 演算 ==
    // preparing for API Request
    var apiRequest = httpClient.begin(); // HttpRequestWrapper
    // com.questetra.bpms.core.event.scripttask.HttpClientWrapper
    
    // Request HEADER (OAuth2 Token, HTTP Basic Auth, etc)
    var token  = httpClient.getOAuth2Token( oauth2 );
    apiRequest = apiRequest.bearer( token );
    
    // Request PATH (https://example.com/abc/def/)
    var apiUri = "https://www.googleapis.com/drive/v3/files/";
        apiUri += fileId;
    
    // Request QUERY (?a=b)
    apiRequest = apiRequest.queryParam( "supportsTeamDrives", "true" );
    
    // Request BODY (JSON, Form Parameters, etc)
    // (no set)
    
    // Access to the API (POST, GET, PUT, etc)
    var response = apiRequest.get( apiUri ); // HttpResponseWrapper
    var httpStatus = response.getStatusCode() + "";
    var accessLog = "---GET request--- " + httpStatus + "\n";
    accessLog += response.getResponseAsString() + "\n";
    var responseObj = JSON.parse( response.getResponseAsString() );
    
    // Retrieve Properties from Response-JSON
    var fileName = responseObj.name;
    
    // Error Handling
    // (no action)
    
    // 2nd) preparing for API Request
    var apiRequest2 = httpClient.begin(); // HttpRequestWrapper
    // com.questetra.bpms.core.event.scripttask.HttpClientWrapper
    
    // 2nd) Request HEADER (OAuth2 Token, HTTP Basic Auth, etc)
    apiRequest2 = apiRequest2.bearer( token );
    
    // 2nd) Request QUERY (?a=b)
    apiRequest2 = apiRequest2.queryParam( "supportsTeamDrives", "true" );
    apiRequest2 = apiRequest2.queryParam( "alt", "media" );
    
    // 2nd) Request BODY (JSON, Form Parameters, etc)
    // (no set)
    
    // 2nd) Access to the API (POST, GET, PUT, etc)
    var response2 = apiRequest2.get( apiUri ); // HttpResponseWrapper
    var httpStatus2 = response2.getStatusCode() + "";
    accessLog += "---GET request--- " + httpStatus2 + "\n";
    
    
    //// == Data Updating / ワークフローデータへの代入 ==
    processFiles.add(
      new com.questetra.bpms.core.event.scripttask.NewQfile( 
        fileName, response2.getContentType(), response2.getResponse()
      )
    );
    engine.setDataByNumber( dataIdC, processFiles );
    if ( dataIdX !== "" ){ engine.setDataByNumber( dataIdX, accessLog ); }