plugins/tech/google/src/main/java/org/apache/hop/pipeline/transforms/googlesheets/GoogleSheetsInput.java
@Override
  public boolean init() {

    List<TransformMeta> transform = getPipelineMeta().findPreviousTransforms(getTransformMeta());
    data.hasInput = transform != null && transform.size() > 0;

    JsonFactory JSON_FACTORY = null;
    NetHttpTransport HTTP_TRANSPORT = null;
    String scope = SheetsScopes.SPREADSHEETS_READONLY;

    try {
      JSON_FACTORY = JacksonFactory.getDefaultInstance();
      HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    } catch (Exception e) {
      log.logError("cannot initiate HTTP transport" + e.getMessage());
      return false;
    }

    if (super.init()) {
      try {
        Sheets service =
            new Sheets.Builder(
                    HTTP_TRANSPORT,
                    JSON_FACTORY,
                    GoogleSheetsCredentials.getCredentialsJson(
                        scope, resolve(meta.getJsonCredentialPath())))
                .setApplicationName(GoogleSheetsCredentials.APPLICATION_NAME)
                .build();
        String range = resolve(meta.getWorksheetId());
        ValueRange response =
            service.spreadsheets().values().get(resolve(meta.getSpreadsheetKey()), range).execute();
        if (response == null) {
          log.logError(
              "No data found for worksheet : "
                  + resolve(meta.getWorksheetId())
                  + " in spreadsheet :"
                  + resolve(meta.getSpreadsheetKey()));
          return false;
        } else {
          List<List<Object>> values = response.getValues();
          log.logBasic("Reading Sheet, found: " + values.size() + " rows");
          if (values == null || values.isEmpty()) {
            throw new HopTransformException(
                "No response found for worksheet : "
                    + resolve(meta.getWorksheetId())
                    + " in spreadsheet :"
                    + resolve(meta.getSpreadsheetKey()));
          } else {
            data.rows = values;
          }
        }
      } catch (Exception e) {
        log.logError(
            "Error: for worksheet : "
                + resolve(meta.getWorksheetId())
                + " in spreadsheet :"
                + resolve(meta.getSpreadsheetKey())
                + e.getMessage(),
            e);
        return false;
      }

      return true;
    }
    return false;
  }
/** Initialize and do work where other transforms need to wait for... */
Initialize and do work where other transforms need to wait for
Initialize and do work where other transforms need to wait for
@Override
  public boolean init() {
    List<TransformMeta> transform = getPipelineMeta().findPreviousTransforms(getTransformMeta());
    data.hasInput = transform != null && transform.size() > 0;
    JsonFactory JSON_FACTORY = null;
    NetHttpTransport HTTP_TRANSPORT = null;
    String scope = SheetsScopes.SPREADSHEETS_READONLY;
    try {
      JSON_FACTORY = JacksonFactory.getDefaultInstance();
      HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    } catch (Exception e) {
      log.logError("cannot initiate HTTP transport" + e.getMessage());
      return false;
    }
    if (super.init()) {
      try {
        Sheets service =
            new Sheets.Builder(
                    HTTP_TRANSPORT,
                    JSON_FACTORY,
                    GoogleSheetsCredentials.getCredentialsJson(
                        scope, resolve(meta.getJsonCredentialPath())))
                .setApplicationName(GoogleSheetsCredentials.APPLICATION_NAME)
                .build();
        String range = resolve(meta.getWorksheetId());
        ValueRange response =
            service.spreadsheets().values().get(resolve(meta.getSpreadsheetKey()), range).execute();
        if (response == null) {
          log.logError(
              "No data found for worksheet : "
                  + resolve(meta.getWorksheetId())
                  + " in spreadsheet :"
                  + resolve(meta.getSpreadsheetKey()));
          return false;
        } else {
          List<List<Object>> values = response.getValues();
          log.logBasic("Reading Sheet, found: " + values.size() + " rows");
          if (values == null || values.isEmpty()) {
            throw new HopTransformException(
                "No response found for worksheet : "
                    + resolve(meta.getWorksheetId())
                    + " in spreadsheet :"
                    + resolve(meta.getSpreadsheetKey()));
          } else {
            data.rows = values;
          }
        }
      } catch (Exception e) {
        log.logError(
            "Error: for worksheet : "
                + resolve(meta.getWorksheetId())
                + " in spreadsheet :"
                + resolve(meta.getSpreadsheetKey())
                + e.getMessage(),
            e);
        return false;
      }
      return true;
    }
    return false;
  }
@ Override public boolean init ( ) { List < TransformMeta > transform = getPipelineMeta ( ) . findPreviousTransforms ( getTransformMeta ( ) ) ; data . hasInput = transform != null && transform . size ( ) > 0 ; JsonFactory JSON_FACTORY = null ; NetHttpTransport HTTP_TRANSPORT = null ; String scope = SheetsScopes . SPREADSHEETS_READONLY ; try { JSON_FACTORY = JacksonFactory . getDefaultInstance ( ) ; HTTP_TRANSPORT = GoogleNetHttpTransport . newTrustedTransport ( ) ; } catch ( Exception e ) { log . logError ( "cannot initiate HTTP transport" + e . getMessage ( ) ) ; return false ; } if ( super . init ( ) ) { try { Sheets service = new Sheets . Builder ( HTTP_TRANSPORT , JSON_FACTORY , GoogleSheetsCredentials . getCredentialsJson ( scope , resolve ( meta . getJsonCredentialPath ( ) ) ) ) . setApplicationName ( GoogleSheetsCredentials . APPLICATION_NAME ) . build ( ) ; String range = resolve ( meta . getWorksheetId ( ) ) ; ValueRange response = service . spreadsheets ( ) . values ( ) . get ( resolve ( meta . getSpreadsheetKey ( ) ) , range ) . execute ( ) ; if ( response == null ) { log . logError ( "No data found for worksheet : " + resolve ( meta . getWorksheetId ( ) ) + " in spreadsheet :" + resolve ( meta . getSpreadsheetKey ( ) ) ) ; return false ; } else { List < List < Object > > values = response . getValues ( ) ; log . logBasic ( "Reading Sheet, found: " + values . size ( ) + " rows" ) ; if ( values == null || values . isEmpty ( ) ) { throw new HopTransformException ( "No response found for worksheet : " + resolve ( meta . getWorksheetId ( ) ) + " in spreadsheet :" + resolve ( meta . getSpreadsheetKey ( ) ) ) ; } else { data . rows = values ; } } } catch ( Exception e ) { log . logError ( "Error: for worksheet : " + resolve ( meta . getWorksheetId ( ) ) + " in spreadsheet :" + resolve ( meta . getSpreadsheetKey ( ) ) + e . getMessage ( ) , e ) ; return false ; } return true ; } return false ; }
Initialize and do work where other transforms need to wait for...
Initialize and do work where other transforms need to wait for ...