From 5766cdd5dde3296189e8d390cfa256131059429b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 1 Sep 2020 16:09:17 -0300 Subject: [PATCH 1/4] Updated EG_COLOR class to define if we have a default setting. Updated Eiffel to JSON mapping. --- sheets/src/json/eg_sheets_json.e | 39 +++++++++++++++++------- sheets/src/objects/eg_color.e | 52 +++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/sheets/src/json/eg_sheets_json.e b/sheets/src/json/eg_sheets_json.e index b9a59ca..6605e81 100644 --- a/sheets/src/json/eg_sheets_json.e +++ b/sheets/src/json/eg_sheets_json.e @@ -299,17 +299,19 @@ feature {NONE} -- JSON To Eiffel -- Create an object `EG_COLOR` from a json rerpesentation `a_json`. do create Result - if attached real_value_from_json (a_json, "red") as l_val then - Result.set_red (l_val) - end - if attached real_value_from_json (a_json, "green") as l_val then - Result.set_green (l_val) - end - if attached real_value_from_json (a_json, "blue") as l_val then - Result.set_blue (l_val) - end - if attached real_value_from_json (a_json, "alpha") as l_val then - Result.set_alpha (l_val) + if not a_json.is_empty then + if attached color_value_from_json (a_json, "red") as l_val then + Result.set_red (l_val) + end + if attached color_value_from_json (a_json, "green") as l_val then + Result.set_green (l_val) + end + if attached color_value_from_json (a_json, "blue") as l_val then + Result.set_blue (l_val) + end + if attached color_value_from_json (a_json, "alpha") as l_val then + Result.set_alpha (l_val) + end end end @@ -638,6 +640,21 @@ feature {NONE} -- Implementation end end + color_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): REAL + do + if + attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then + v.numeric_type = v.real_type + then + Result := v.item.to_real + elseif attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then + v.numeric_type = v.integer_type + then + Result := v.item.to_integer + end + + end + integer_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): INTEGER do if diff --git a/sheets/src/objects/eg_color.e b/sheets/src/objects/eg_color.e index d803efa..876629a 100644 --- a/sheets/src/objects/eg_color.e +++ b/sheets/src/objects/eg_color.e @@ -18,6 +18,22 @@ note class EG_COLOR +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature {NONE} -- Initialization + + default_create + do + is_default := True + end feature -- Access @@ -37,47 +53,73 @@ feature -- Access -- This uses a wrapper message rather than a simple float scalar so that it is possible to distinguish between a default value and the value being unset. -- If omitted, this color object is to be rendered as a solid color (as if the alpha value had been explicitly given with a value of 1.0). + is_default: BOOLEAN + -- Are the attributes in default values? + feature -- Element Change set_red (a_val: REAL) + -- Set `red` to `a_val`. do + is_default := False red := a_val ensure + not_default: not is_default red_set: red = a_val end set_green (a_val: REAL) do + is_default := False green := a_val ensure + not_default: not is_default green_set: green = a_val end set_blue (a_val: REAL) do + is_default := False blue := a_val ensure + not_default: not is_default blue_set: blue = a_val end set_alpha (a_val: REAL) do + is_default := False alpha := a_val ensure + not_default: not is_default alpha_set: alpha = a_val end + reset + -- Reset the attributes to default values. + do + is_default := True + red := 0 + green := 0 + blue := 0 + alpha := 0 + end + feature -- Eiffel to JSON to_json: JSON_OBJECT -- Json representation of current object. do - create Result.make_with_capacity (4) - Result.put (create {JSON_NUMBER}.make_real (red), "red") - Result.put (create {JSON_NUMBER}.make_real (green), "green") - Result.put (create {JSON_NUMBER}.make_real (blue), "blue") - Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha") + if is_default then + create Result.make + else + create Result.make_with_capacity (4) + Result.put (create {JSON_NUMBER}.make_real (red), "red") + Result.put (create {JSON_NUMBER}.make_real (green), "green") + Result.put (create {JSON_NUMBER}.make_real (blue), "blue") + Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha") + end end invariant From d6dbed0aed374192bc102920f4157b47f8cf92d0 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 2 Sep 2020 16:01:15 -0300 Subject: [PATCH 2/4] Added Eiffel to JSON mapping to GRID_PROPERTIES SHEET (WIP) SHEET_PROPERTIES SHEET_TYPE --- sheets/src/json/eg_sheets_json.e | 17 +++-- sheets/src/objects/eg_grid_properties.e | 14 ++++ sheets/src/objects/eg_sheet.e | 5 ++ sheets/src/objects/eg_sheet_properties.e | 87 ++++++++++++++++-------- sheets/src/objects/eg_sheet_type.e | 17 ++++- 5 files changed, 106 insertions(+), 34 deletions(-) diff --git a/sheets/src/json/eg_sheets_json.e b/sheets/src/json/eg_sheets_json.e index 6605e81..2ab3b98 100644 --- a/sheets/src/json/eg_sheets_json.e +++ b/sheets/src/json/eg_sheets_json.e @@ -47,7 +47,7 @@ feature -- Post end end -feature -- Get +feature -- Get get_from_id (a_spreadsheet_id: STRING_8; a_params: detachable EG_SPREADSHEET_PARAMETERS): detachable EG_SPREADSHEET note @@ -460,6 +460,9 @@ feature {NONE} -- JSON To Eiffel sheet_properties (a_json: JSON_VALUE): EG_SHEET_PROPERTIES -- Create an object `EG_SHEET_PROPERTIES` from a json representation `a_json`. + local + l_stype: EG_SHEET_TYPE + l_grid_prop: EG_GRID_PROPERTIES do create Result if attached integer_value_from_json (a_json, "sheetId") as l_sheetId then @@ -472,19 +475,23 @@ feature {NONE} -- JSON To Eiffel Result.set_index (l_index) end if attached string_value_from_json (a_json, "sheetType") as l_sheet_type then + create l_stype if l_sheet_type.is_case_insensitive_equal ("GRID") then - Result.sheet_type.set_grid + l_stype.set_grid elseif l_sheet_type.is_case_insensitive_equal ("OBJECT") then - Result.sheet_type.set_grid + l_stype.set_grid end + Result.set_sheet_type (l_stype) end if attached {JSON_OBJECT} json_value (a_json, "gridProperties") as l_grid_properties then + create l_grid_prop if attached integer_value_from_json (l_grid_properties, "rowCount") as l_row_count then - Result.grid_properties.set_row_count (l_row_count) + l_grid_prop.set_row_count (l_row_count) end if attached integer_value_from_json (l_grid_properties, "columnCount") as l_column_count then - Result.grid_properties.set_column_count (l_column_count) + l_grid_prop.set_column_count (l_column_count) end + Result.set_grid_properties (l_grid_prop) end if attached boolean_value_from_json (a_json, "hidden") as l_hidden then Result.set_hidden (l_hidden) diff --git a/sheets/src/objects/eg_grid_properties.e b/sheets/src/objects/eg_grid_properties.e index e76467a..06e30d3 100644 --- a/sheets/src/objects/eg_grid_properties.e +++ b/sheets/src/objects/eg_grid_properties.e @@ -103,4 +103,18 @@ feature -- Element change row_count_assigned: row_count = a_row_count end +feature -- Eiffel to JSON + + to_json: JSON_OBJECT + -- JSon representation of current object. + do + create Result.make_with_capacity (6) + Result.put (create {JSON_NUMBER}.make_integer (row_count), "rowCount") + Result.put (create {JSON_NUMBER}.make_integer (column_count), "columnCount") + Result.put (create {JSON_NUMBER}.make_integer (frozen_row_count), "frozenRowCount") + Result.put (create {JSON_NUMBER}.make_integer (frozen_column_count), "frozenColumnCount") + Result.put (create {JSON_BOOLEAN}.make (hide_grid_lines), "hideGridlines") + Result.put (create {JSON_BOOLEAN}.make (row_group_control_after), "rowGroupControlAfter") + Result.put (create {JSON_BOOLEAN}.make (column_group_control_after), "columnGroupControlAfter") + end end diff --git a/sheets/src/objects/eg_sheet.e b/sheets/src/objects/eg_sheet.e index d0a41c4..2e7cce1 100644 --- a/sheets/src/objects/eg_sheet.e +++ b/sheets/src/objects/eg_sheet.e @@ -378,7 +378,12 @@ feature -- Element Change feature -- Eiffel to JSON to_json: JSON_OBJECT + -- Json representation of current object. do create Result.make_empty + if attached properties as l_properties then + Result.put (l_properties.to_json, "properties") + end + end end diff --git a/sheets/src/objects/eg_sheet_properties.e b/sheets/src/objects/eg_sheet_properties.e index c3ef3ec..ebeb694 100644 --- a/sheets/src/objects/eg_sheet_properties.e +++ b/sheets/src/objects/eg_sheet_properties.e @@ -28,37 +28,13 @@ note class EG_SHEET_PROPERTIES -inherit - - ANY - redefine - default_create - end - -create - default_create - -feature {NONE} -- Initialization - - default_create - do - create title.make_empty - create sheet_type - create grid_properties - ensure then - sheet_id = 0 - not is_sheet_id_set - not is_sheet_type_set - end - - feature -- Access sheet_id: INTEGER -- The ID of the sheet. Must be non-negative. This field cannot be changed once set. -- NATURAL? - title: STRING + title: detachable STRING -- The name of the sheet. index: INTEGER @@ -68,10 +44,10 @@ feature -- Access -- For example, if there were 3 sheets (S1, S2, S3) in order to move S1 ahead of S2 the index would have to be set to 2. -- A sheet index update request is ignored if the requested index is identical to the sheets current index or if the requested new index is equal to the current sheet index + 1. - sheet_type: EG_SHEET_TYPE + sheet_type: detachable EG_SHEET_TYPE -- The type of sheet. Defaults to GRID . This field cannot be changed once set. - grid_properties: EG_GRID_PROPERTIES + grid_properties: detachable EG_GRID_PROPERTIES -- Additional properties of the sheet if this sheet is a grid. -- (If the sheet is an object sheet, containing a chart or image, then this field will be absent.) -- When writing it is an error to set any grid properties on non-grid sheets. @@ -100,6 +76,7 @@ feature -- Status Report feature -- Element Change set_sheet_id (a_id: like sheet_id) + -- Set `sheet_id` with `a_id`. require non_negative: a_id >=0 not_id_set: not is_sheet_id_set @@ -111,7 +88,8 @@ feature -- Element Change is_defined: is_sheet_id_set end - set_title (a_title: STRING) + set_title (a_title: like title) + -- Set `title` with `a_title`. do title := a_title ensure @@ -119,6 +97,7 @@ feature -- Element Change end set_index (a_index: like index) + -- Set `index` with `a_index`. do index := a_index ensure @@ -126,6 +105,7 @@ feature -- Element Change end set_sheet_type (a_type: EG_SHEET_TYPE) + -- Set `sheet_type` with `a_type`. require not_sheet_type: not is_sheet_type_set do @@ -137,6 +117,7 @@ feature -- Element Change end set_grid_properties (a_properties: like grid_properties) + -- Set `grid_properties` with `a_properties`. do grid_properties := a_properties ensure @@ -144,6 +125,7 @@ feature -- Element Change end set_hidden (a_val: BOOLEAN) + -- Set `hidden` with `a_val`. do hidden := a_val ensure @@ -151,6 +133,7 @@ feature -- Element Change end set_tab_color (a_color: like tab_color) + -- Set `tab_color` with `a_color`. do tab_color := a_color ensure @@ -158,6 +141,7 @@ feature -- Element Change end set_tab_color_style (a_color_style: like tab_color_style) + -- Set `tab_color_style` with `a_color_style`. do tab_color_style := a_color_style ensure @@ -165,10 +149,57 @@ feature -- Element Change end set_right_to_left (a_val: BOOLEAN) + -- Set `right_to_left` with `a_val`. do right_to_left := a_val ensure right_to_left_set: right_to_left = a_val end +feature -- Eiffel to JSON + + to_json: JSON_OBJECT +-- { +-- "sheetId": integer, +-- "title": string, +-- "index": integer, +-- "sheetType": enum (SheetType), +-- "gridProperties": { +-- object (GridProperties) +-- }, +-- "hidden": boolean, +-- "tabColor": { +-- object (Color) +-- }, +-- "tabColorStyle": { +-- object (ColorStyle) +-- }, +-- "rightToLeft": boolean +-- } + + do + create Result.make + if is_sheet_id_set then + Result.put (create {JSON_NUMBER}.make_integer (sheet_id), "sheetId") + end + if attached title as l_title then + Result.put (create {JSON_STRING}.make_from_string (l_title), "title") + end + Result.put (create {JSON_NUMBER}.make_integer (index), "index") + if attached sheet_type as l_st then + Result.put (l_st.to_json, "sheetType") + end + if attached grid_properties as l_gp then + Result.put (l_gp.to_json, "gridProperties") + end + Result.put (create {JSON_BOOLEAN}.make (hidden), "hidden") + if attached tab_color as l_tc then + Result.put (l_tc.to_json, "tabColor") + end + if attached tab_color_style as l_tcs then + Result.put (l_tcs.to_json, "tabColorStyle") + end + Result.put (create {JSON_BOOLEAN}.make (right_to_left), "rightToLeft") + end + end diff --git a/sheets/src/objects/eg_sheet_type.e b/sheets/src/objects/eg_sheet_type.e index 7325c12..41351c0 100644 --- a/sheets/src/objects/eg_sheet_type.e +++ b/sheets/src/objects/eg_sheet_type.e @@ -74,7 +74,22 @@ feature -- Status Report do Result := a_value = sheet_type_unspecified or else a_value = grid or else - a_value = object + a_value = object + end + + +feature -- Eiffel to JSON + + to_json: JSON_STRING + -- JSon representation of current object. + do + if is_grid then + Result := "GRID" + elseif is_object then + Result := "OBJECT" + else + Result := "SHEET_TYPE_UNSPECIFIED" + end end end From 022b18e3e6c0a0297cbd816dcade39f5d9ca7e32 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 2 Sep 2020 17:50:21 -0300 Subject: [PATCH 3/4] Added new domain objects EG_CELL_DATA EG_DIMENSION_PROPERTIES EG_ROW_DATA Updated EG_GRID_DATA (Wip, Eiffel to JSON mapping.) --- sheets/src/objects/eg_cell_data.e | 41 +++++++++ sheets/src/objects/eg_dimension_properties.e | 95 ++++++++++++++++++++ sheets/src/objects/eg_grid_data.e | 92 +++++++++++++++++++ sheets/src/objects/eg_row_data.e | 25 ++++++ sheets/src/objects/eg_sheet.e | 11 ++- sheets/src/objects/eg_sheet_properties.e | 19 +--- 6 files changed, 264 insertions(+), 19 deletions(-) create mode 100644 sheets/src/objects/eg_cell_data.e create mode 100644 sheets/src/objects/eg_dimension_properties.e create mode 100644 sheets/src/objects/eg_row_data.e diff --git a/sheets/src/objects/eg_cell_data.e b/sheets/src/objects/eg_cell_data.e new file mode 100644 index 0000000..d766cf9 --- /dev/null +++ b/sheets/src/objects/eg_cell_data.e @@ -0,0 +1,41 @@ +note + description: "[ + Data about a specific cell. + + { + "userEnteredValue": { + object (ExtendedValue) + }, + "effectiveValue": { + object (ExtendedValue) + }, + "formattedValue": string, + "userEnteredFormat": { + object (CellFormat) + }, + "effectiveFormat": { + object (CellFormat) + }, + "hyperlink": string, + "note": string, + "textFormatRuns": [ + { + object (TextFormatRun) + } + ], + "dataValidation": { + object (DataValidationRule) + }, + "pivotTable": { + object (PivotTable) + } + } + ]" + date: "$Date$" + revision: "$Revision$" + EIS: "name=CellData", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellData", "protocol=uri" + +class + EG_CELL_DATA + +end diff --git a/sheets/src/objects/eg_dimension_properties.e b/sheets/src/objects/eg_dimension_properties.e new file mode 100644 index 0000000..32ba855 --- /dev/null +++ b/sheets/src/objects/eg_dimension_properties.e @@ -0,0 +1,95 @@ +note + description: "[ + Properties about a dimension. + + { + "hiddenByFilter": boolean, + "hiddenByUser": boolean, + "pixelSize": integer, + "developerMetadata": [ + { + object (DeveloperMetadata) + } + ] + } + + ]" + date: "$Date$" + revision: "$Revision$" + +class + EG_DIMENSION_PROPERTIES + + +feature -- Access + + hidden_by_filter: BOOLEAN + -- True if this dimension is being filtered. This field is read-only. + + hidden_by_user: BOOLEAN + -- True if this dimension is explicitly hidden. + + pixel_size: INTEGER + -- The height (if a row) or width (if a column) of the dimension in pixels. + + developer_metadata: detachable LIST [EG_DEVELOPER_METADATA] + -- The developer metadata associated with a single row or column. + +feature -- Status Report + + is_hidden_by_filter_set: BOOLEAN + -- Use to set the value once. + +feature -- Element Change + + set_hidden_by_filter (a_val: like hidden_by_filter) + -- Set `hidden_by_filter` with `a_val`. + require + not_set: not is_hidden_by_filter_set + do + is_hidden_by_filter_set := True + hidden_by_filter := a_val + ensure + hidden_by_filter_set: hidden_by_filter = a_val + is_hidden_by_filter_set: is_hidden_by_filter_set + end + + set_hidden_by_user (a_val: like hidden_by_user) + -- Set `hidden_by_user` with `a_val`. + do + hidden_by_user := a_val + ensure + hidden_by_user_set: hidden_by_user = a_val + end + + set_pixel_size (a_size: like pixel_size) + -- Set `pixel_size` with `a_size`. + do + pixel_size := a_size + ensure + pixel_size_set: pixel_size = a_size + end + + force_developer_metadata (a_metadata: EG_DEVELOPER_METADATA) + -- Add an item `a_metadata` to the list `developer_metadata`. + local + l_developer_metadata: like developer_metadata + do + l_developer_metadata := developer_metadata + if l_developer_metadata /= Void then + l_developer_metadata.force (a_metadata) + else + create {ARRAYED_LIST [EG_DEVELOPER_METADATA]}l_developer_metadata.make (5) + l_developer_metadata.force (a_metadata) + end + developer_metadata := l_developer_metadata + end + +feature -- Eiffel to JSON + + to_json: JSON_OBJECT + -- JSon representtion of the current object. + do + create Result.make + end +end diff --git a/sheets/src/objects/eg_grid_data.e b/sheets/src/objects/eg_grid_data.e index 94fb798..56439f9 100644 --- a/sheets/src/objects/eg_grid_data.e +++ b/sheets/src/objects/eg_grid_data.e @@ -28,4 +28,96 @@ note class EG_GRID_DATA +feature -- Access + + start_row: INTEGER + -- The first row this GridData refers to, zero-based. + + start_column: INTEGER + -- The first column this GridData refers to, zero-based. + + row_data: detachable LIST [EG_ROW_DATA] + -- The data in the grid, one entry per row, starting with the row in startRow. + -- The values in RowData will correspond to columns starting at startColumn . + + row_metadata: detachable LIST [EG_DIMENSION_PROPERTIES] + -- Metadata about the requested rows in the grid, starting with the row in startRow + + column_metadata: detachable LIST [EG_DIMENSION_PROPERTIES] + -- Metadata about the requested columns in the grid, starting with the column in startColumn . + +feature -- Element Change + + set_start_row (a_val: like start_row) + -- Set `start_row` with `a_val`. + require + valid_row: a_val >= 0 + do + start_row := a_val + ensure + start_row_set: start_row = a_val + end + + set_start_column (a_val: like start_column) + -- Set `start_column` with `a_val`. + require + valid_column: a_val >= 0 + do + start_column := a_val + ensure + start_column_set: start_column = a_val + end + + force_raw_data (a_data: EG_ROW_DATA) + -- Add an item `a_data` to the list of `row_data` + local + l_row_data: like row_data + do + l_row_data := row_data + if l_row_data /= Void then + l_row_data.force (a_data) + else + create {ARRAYED_LIST [EG_ROW_DATA]} l_row_data.make (5) + l_row_data.force (a_data) + end + row_data := l_row_data + end + + force_row_metadata (a_metadata: EG_DIMENSION_PROPERTIES) + -- Add an item `a_metadata` to the list of `row_metadata` + local + l_row_metadata: like row_metadata + do + l_row_metadata := row_metadata + if l_row_metadata /= Void then + l_row_metadata.force (a_metadata) + else + create {ARRAYED_LIST [EG_DIMENSION_PROPERTIES]} l_row_metadata.make (5) + l_row_metadata.force (a_metadata) + end + row_metadata := l_row_metadata + end + + + force_column_metadata (a_metadata: EG_DIMENSION_PROPERTIES) + -- Add an item `a_metadata` to the list of `column_metadata` + local + l_column_metadata: like row_metadata + do + l_column_metadata := row_metadata + if l_column_metadata /= Void then + l_column_metadata.force (a_metadata) + else + create {ARRAYED_LIST [EG_DIMENSION_PROPERTIES]} l_column_metadata.make (5) + l_column_metadata.force (a_metadata) + end + column_metadata := l_column_metadata + end + +feature -- Eiffel to JSON + + to_json: JSON_OBJECT + do + create Result.make + end end diff --git a/sheets/src/objects/eg_row_data.e b/sheets/src/objects/eg_row_data.e new file mode 100644 index 0000000..77e69be --- /dev/null +++ b/sheets/src/objects/eg_row_data.e @@ -0,0 +1,25 @@ +note + description: "[ + Data about each cell in a row. + { + "values": [ + { + object (CellData) + } + ] + } + ]" + date: "$Date$" + revision: "$Revision$" + EIS: "name=RawData", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#RowData", "protocol=uri" + +class + EG_ROW_DATA + + +feature -- Access + + values: detachable LIST [EG_CELL_DATA] + -- The values in the row, one per column. + +end diff --git a/sheets/src/objects/eg_sheet.e b/sheets/src/objects/eg_sheet.e index 2e7cce1..d629bc1 100644 --- a/sheets/src/objects/eg_sheet.e +++ b/sheets/src/objects/eg_sheet.e @@ -378,12 +378,21 @@ feature -- Element Change feature -- Eiffel to JSON to_json: JSON_OBJECT - -- Json representation of current object. + -- Json representation of current object. + local + j_array: JSON_ARRAY do create Result.make_empty if attached properties as l_properties then Result.put (l_properties.to_json, "properties") end + if attached data as l_data then + create j_array.make (l_data.count) + across l_data as ic loop + j_array.add (ic.item.to_json) + end + Result.put (j_array, "data") + end end end diff --git a/sheets/src/objects/eg_sheet_properties.e b/sheets/src/objects/eg_sheet_properties.e index ebeb694..98541bb 100644 --- a/sheets/src/objects/eg_sheet_properties.e +++ b/sheets/src/objects/eg_sheet_properties.e @@ -159,24 +159,7 @@ feature -- Element Change feature -- Eiffel to JSON to_json: JSON_OBJECT --- { --- "sheetId": integer, --- "title": string, --- "index": integer, --- "sheetType": enum (SheetType), --- "gridProperties": { --- object (GridProperties) --- }, --- "hidden": boolean, --- "tabColor": { --- object (Color) --- }, --- "tabColorStyle": { --- object (ColorStyle) --- }, --- "rightToLeft": boolean --- } - + -- JSON Representation of current object. do create Result.make if is_sheet_id_set then From 29ba448486c3300784500945013bffe882892960 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 7 Sep 2020 17:37:50 -0300 Subject: [PATCH 4/4] Added new classes to represent error values and extended values Updated Eiffel to JSON mapping. --- sheets/src/json/eg_sheets_json.e | 39 ++++++++++- sheets/src/objects/eg_cell_data.e | 14 ++++ sheets/src/objects/eg_error_value.e | 20 ++++++ sheets/src/objects/eg_extended_value.e | 96 ++++++++++++++++++++++++++ sheets/src/objects/eg_grid_data.e | 55 ++++++++++++++- sheets/src/objects/eg_row_data.e | 43 ++++++++++-- sheets/src/objects/eg_sheet.e | 62 +++++++++++++++++ sheets/test/test_sheets_api.e | 18 ++--- 8 files changed, 331 insertions(+), 16 deletions(-) create mode 100644 sheets/src/objects/eg_error_value.e create mode 100644 sheets/src/objects/eg_extended_value.e diff --git a/sheets/src/json/eg_sheets_json.e b/sheets/src/json/eg_sheets_json.e index 2ab3b98..1e70bdf 100644 --- a/sheets/src/json/eg_sheets_json.e +++ b/sheets/src/json/eg_sheets_json.e @@ -406,7 +406,9 @@ feature {NONE} -- JSON To Eiffel Result.set_properties (sheet_properties (l_properties)) end if attached {JSON_ARRAY} json_value (a_json, "data") as l_data then - -- TODO + across l_data as ic loop + Result.force_data (eg_data_grid (ic.item)) + end end if attached {JSON_ARRAY} json_value (a_json, "merges") as l_merges then -- TODO @@ -443,6 +445,41 @@ feature {NONE} -- JSON To Eiffel end end + eg_data_grid (a_json: JSON_VALUE): EG_GRID_DATA + -- Create an object `EG_GRID_DATA` from a json representation. + do + create Result + if attached integer_value_from_json (a_json, "startRow") as l_val then + Result.set_start_row (l_val) + end + if attached integer_value_from_json (a_json, "startColumn") as l_val then + Result.set_start_column (l_val) + end + if attached {JSON_ARRAY} json_value (a_json, "rowData") as l_data then + across l_data as ic loop + Result.force_row_data (eg_row_data (ic.item)) + end + end + end + + eg_row_data (a_json: JSON_VALUE): EG_ROW_DATA + -- Create an object `EG_ROW_DATA` from a json representation. + do + create Result + if attached {JSON_ARRAY} json_value (a_json, "values") as l_data then + across l_data as ic loop + Result.force_value(eg_cell_data (ic.item)) + end + end + end + + eg_cell_data (a_json: JSON_VALUE): EG_CELL_DATA + -- Create an object `EG_CELL_DATA` from a json representation. + do + create Result + + end + eg_named_ranges (a_json: JSON_VALUE): EG_NAMED_RANGE -- Create an object `EG_NAMED_RANGE` from a json representation. do diff --git a/sheets/src/objects/eg_cell_data.e b/sheets/src/objects/eg_cell_data.e index d766cf9..0ca5c18 100644 --- a/sheets/src/objects/eg_cell_data.e +++ b/sheets/src/objects/eg_cell_data.e @@ -38,4 +38,18 @@ note class EG_CELL_DATA +feature -- Access + + user_entered_value: detachable EG_EXTENDED_VALUE + +feature -- Element Change + +feature -- Eiffel to JSON + + to_json: JSON_OBJECT + -- JSON representation of the current object. + do + create Result.make_empty + end + end diff --git a/sheets/src/objects/eg_error_value.e b/sheets/src/objects/eg_error_value.e new file mode 100644 index 0000000..27d46bd --- /dev/null +++ b/sheets/src/objects/eg_error_value.e @@ -0,0 +1,20 @@ +note + description: "[ + An error in a cell. + + JSON representation + + { + "type": enum (ErrorType), + "message": string + } + + ]" + date: "$Date$" + revision: "$Revision$" + EIS: "name= Error Value", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ErrorValue", "protocol=uri" + +class + EG_ERROR_VALUE + +end diff --git a/sheets/src/objects/eg_extended_value.e b/sheets/src/objects/eg_extended_value.e new file mode 100644 index 0000000..64274f1 --- /dev/null +++ b/sheets/src/objects/eg_extended_value.e @@ -0,0 +1,96 @@ +note + description: "[ + + The kinds of value that a cell in a spreadsheet can have. + { + + // Union field value can be only one of the following: + "numberValue": number, + "stringValue": string, + "boolValue": boolean, + "formulaValue": string, + "errorValue": { + object (ErrorValue) + } + // End of list of possible types for union field value. + } + + ]" + date: "$Date$" + revision: "$Revision$" + +class + EG_EXTENDED_VALUE + + +feature -- Access + + number_value: REAL + -- Represents a double value. + -- Note: Dates, Times and DateTimes are represented as doubles in "serial number" format. + + string_value: detachable STRING + -- Represents a string value. Leading single quotes are not included. + -- For example, if the user typed '123 into the UI, this would be represented as a stringValue of "123". + + bool_value: BOOLEAN + -- Represents a boolean value. + + formula_value: detachable STRING + -- Represents a formula. + + error_value: detachable EG_ERROR_VALUE + -- Represents an error. This field is read-only. + +feature -- Status Report + + is_number_value: BOOLEAN + -- Is the current value a number? + + is_string_value: BOOLEAN + -- Is the current value an string? + + is_bool_value: BOOLEAN + -- Is the current value a boolean? + + is_formula_value: BOOLEAN + -- Is the current value a formula? + + is_error_value: BOOLEAN + -- Is the current value an error value? + +feature -- Element Change + + set_number_value (a_value: like number_value) + -- Set `number_value` with `a_vaue`? + do + is_number_value := True + is_string_value := False + is_bool_value := False + is_formula_value:= False + is_error_value := False + + number_value := a_value + ensure + number_value_set: number_value = a_value + union_field_number: is_number_value implies + ( is_string_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False) + end + + set_string_value (a_value: like string_value) + -- Set `string_value` with `a_vaue`? + do + is_number_value := False + is_string_value := True + is_bool_value := False + is_formula_value:= False + is_error_value := False + + string_value := a_value + ensure + string_value_set: string_value = a_value + union_field_string: is_string_value implies + ( is_number_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False) + end + +end diff --git a/sheets/src/objects/eg_grid_data.e b/sheets/src/objects/eg_grid_data.e index 56439f9..559cd60 100644 --- a/sheets/src/objects/eg_grid_data.e +++ b/sheets/src/objects/eg_grid_data.e @@ -68,7 +68,7 @@ feature -- Element Change start_column_set: start_column = a_val end - force_raw_data (a_data: EG_ROW_DATA) + force_row_data (a_data: EG_ROW_DATA) -- Add an item `a_data` to the list of `row_data` local l_row_data: like row_data @@ -83,6 +83,14 @@ feature -- Element Change row_data := l_row_data end + set_row_data (a_data: like row_data) + -- Set `row_data` with `a_data`. + do + row_data := a_data + ensure + row_data_set: row_data = a_data + end + force_row_metadata (a_metadata: EG_DIMENSION_PROPERTIES) -- Add an item `a_metadata` to the list of `row_metadata` local @@ -98,6 +106,14 @@ feature -- Element Change row_metadata := l_row_metadata end + set_row_metadata (a_data: like row_metadata) + -- Set `row_metadata` with `a_data`. + do + row_metadata := a_data + ensure + row_metadata_set: row_metadata = a_data + end + force_column_metadata (a_metadata: EG_DIMENSION_PROPERTIES) -- Add an item `a_metadata` to the list of `column_metadata` @@ -114,10 +130,45 @@ feature -- Element Change column_metadata := l_column_metadata end + set_column_metadata (a_data: like column_metadata) + -- Set `column_metadata` with `a_data`. + do + column_metadata := a_data + ensure + column_metadata_set: column_metadata = a_data + end + feature -- Eiffel to JSON to_json: JSON_OBJECT + --Json representation of the current object. + local + j_array: JSON_ARRAY do - create Result.make + create Result.make_empty + Result.put (create {JSON_NUMBER}.make_integer (start_row), "startRow") + Result.put (create {JSON_NUMBER}.make_integer (start_column), "startColumn") + if attached row_data as l_rd then + create j_array.make (l_rd.count) + across l_rd as ic loop + j_array.add (ic.item.to_json) + end + Result.put (j_array, "rowData") + end + if attached row_metadata as l_rm then + create j_array.make (l_rm.count) + across l_rm as ic loop + j_array.add (ic.item.to_json) + end + Result.put (j_array, "rowMetadata") + end + if attached column_metadata as l_cm then + create j_array.make (l_cm.count) + across l_cm as ic loop + j_array.add (ic.item.to_json) + end + Result.put (j_array, "columnMetadata") + end + end end diff --git a/sheets/src/objects/eg_row_data.e b/sheets/src/objects/eg_row_data.e index 77e69be..3a6221c 100644 --- a/sheets/src/objects/eg_row_data.e +++ b/sheets/src/objects/eg_row_data.e @@ -15,11 +15,46 @@ note class EG_ROW_DATA - - + + feature -- Access - - values: detachable LIST [EG_CELL_DATA] + + values: detachable LIST [EG_CELL_DATA] -- The values in the row, one per column. + +feature -- Element Change + + force_value (a_data: EG_CELL_DATA) + -- Add an item `a_data` to the list of `values`. + local + l_values: like values + do + l_values := values + if l_values /= Void then + l_values.force (a_data) + else + create {ARRAYED_LIST [EG_CELL_DATA]} l_values.make (5) + l_values.force (a_data) + end + values := l_values + end + + +feature -- Eiffel to JSON + + to_json: JSON_OBJECT + -- Json representation of the current object. + local + j_array: JSON_ARRAY + do + create Result.make_empty + if attached values as l_values then + create j_array.make (l_values.count) + across l_values as ic loop + j_array.add (ic.item.to_json) + end + Result.put (j_array, "values") + end + end end diff --git a/sheets/src/objects/eg_sheet.e b/sheets/src/objects/eg_sheet.e index d629bc1..733d649 100644 --- a/sheets/src/objects/eg_sheet.e +++ b/sheets/src/objects/eg_sheet.e @@ -395,4 +395,66 @@ feature -- Eiffel to JSON end end + +-- "data": [ +-- { +-- object (GridData) +-- } +-- ], +-- "merges": [ +-- { +-- object (GridRange) +-- } +-- ], +-- "conditionalFormats": [ +-- { +-- object (ConditionalFormatRule) +-- } +-- ], +-- "filterViews": [ +-- { +-- object (FilterView) +-- } +-- ], +-- "protectedRanges": [ +-- { +-- object (ProtectedRange) +-- } +-- ], +-- "basicFilter": { +-- object (BasicFilter) +-- }, +-- "charts": [ +-- { +-- object (EmbeddedChart) +-- } +-- ], +-- "bandedRanges": [ +-- { +-- object (BandedRange) +-- } +-- ], +-- "developerMetadata": [ +-- { +-- object (DeveloperMetadata) +-- } +-- ], +-- "rowGroups": [ +-- { +-- object (DimensionGroup) +-- } +-- ], +-- "columnGroups": [ +-- { +-- object (DimensionGroup) +-- } +-- ], +-- "slicers": [ +-- { +-- object (Slicer) +-- } +-- ] +-- } + + end diff --git a/sheets/test/test_sheets_api.e b/sheets/test/test_sheets_api.e index 126bddc..9bf3199 100644 --- a/sheets/test/test_sheets_api.e +++ b/sheets/test/test_sheets_api.e @@ -19,16 +19,16 @@ feature -- {NONE} do -- TODO improve this code so we can select which integration test we want to run. logger.write_information ("make-> ======================> Starting application") - set_from_json_credentials_file_path (create {PATH}.make_from_string ("/home/pg/data/solarity/sit-dev/etc/opt/solarity/EGSheets-itadmin-api-project-credentials.json")) + set_from_json_credentials_file_path (create {PATH}.make_from_string (credentials_path)) retrieve_access_token --- test_create_sheet --- test_get_sheet ("1v1N4nRa6mmLcP9rUuyQPiCnLuUcBQFDEC7E0CDg3ASI") - test_append_sheet ("19cKCmQBWJoMePX0Iy6LueHRw0sS2bMcyP1Auzbkvj6M", impl_append_post_data_sample) --pg - --test_append_sheet ("1j5CTkpgOc6Y5qgYdA_klZYjNhmN2KYocoZAdM4Y61tw") --jv + test_create_sheet +---- test_get_sheet ("1v1N4nRa6mmLcP9rUuyQPiCnLuUcBQFDEC7E0CDg3ASI") +-- test_append_sheet ("19cKCmQBWJoMePX0Iy6LueHRw0sS2bMcyP1Auzbkvj6M", impl_append_post_data_sample) --pg +-- --test_append_sheet ("1j5CTkpgOc6Y5qgYdA_klZYjNhmN2KYocoZAdM4Y61tw") --jv --- set_from_json_credentials_file_path (create {PATH}.make_from_string (CREDENTIALS_PATH)) - retrieve_access_token - test_get_sheet ("1v1N4nRa6mmLcP9rUuyQPiCnLuUcBQFDEC7E0CDg3ASI") +---- set_from_json_credentials_file_path (create {PATH}.make_from_string (CREDENTIALS_PATH)) +-- retrieve_access_token +-- test_get_sheet ("1v1N4nRa6mmLcP9rUuyQPiCnLuUcBQFDEC7E0CDg3ASI") end @@ -76,7 +76,7 @@ feature -- Tests l_esapi: EG_SHEETS_API do create l_esapi.make (last_token.token) - if attached l_esapi.get_from_id (a_sheet_id) as l_spreedsheet_get_result then + if attached l_esapi.get_from_id (a_sheet_id, Void) as l_spreedsheet_get_result then if l_esapi.has_error then -- debug ("test_create_sheet") print ("test_create_sheet-> Error %N" )