com.google.api.services.sheets.v4.model.SpreadsheetProperties Java Examples
The following examples show how to use
com.google.api.services.sheets.v4.model.SpreadsheetProperties.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleSheetsResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Path("/create") @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response createSheet(String title) throws Exception { SpreadsheetProperties sheetProperties = new SpreadsheetProperties(); sheetProperties.setTitle(title); Spreadsheet sheet = new Spreadsheet(); sheet.setProperties(sheetProperties); Spreadsheet response = producerTemplate.requestBody("google-sheets://spreadsheets/create?inBody=content", sheet, Spreadsheet.class); return Response .created(new URI("https://camel.apache.org/")) .entity(response.getSpreadsheetId()) .build(); }
Example #2
Source File: GoogleSheetsResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Path("/update") @PATCH @Consumes(MediaType.TEXT_PLAIN) public Response updateSheet(@QueryParam("spreadsheetId") String spreadsheetId, String title) { BatchUpdateSpreadsheetRequest request = new BatchUpdateSpreadsheetRequest() .setIncludeSpreadsheetInResponse(true) .setRequests(Collections .singletonList(new Request().setUpdateSpreadsheetProperties(new UpdateSpreadsheetPropertiesRequest() .setProperties(new SpreadsheetProperties().setTitle(title)) .setFields("title")))); final Map<String, Object> headers = new HashMap<>(); headers.put("CamelGoogleSheets.spreadsheetId", spreadsheetId); headers.put("CamelGoogleSheets.batchUpdateSpreadsheetRequest", request); producerTemplate.requestBodyAndHeaders("google-sheets://spreadsheets/batchUpdate", null, headers); return Response.ok().build(); }
Example #3
Source File: GoogleSheetsUpdateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
private SpreadsheetProperties getSpreadsheetProperties(List<String> fields) { SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); if (ObjectHelper.isNotEmpty(title)) { spreadsheetProperties.setTitle(title); fields.add("title"); } if (ObjectHelper.isNotEmpty(timeZone)) { spreadsheetProperties.setTimeZone(timeZone); fields.add("timeZone"); } if (ObjectHelper.isNotEmpty(locale)) { spreadsheetProperties.setLocale(locale); fields.add("locale"); } return spreadsheetProperties; }
Example #4
Source File: GoogleSheetsCreateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 5 votes |
private static void afterProducer(Exchange exchange) { final Message in = exchange.getIn(); final Spreadsheet spreadsheet = in.getBody(Spreadsheet.class); GoogleSpreadsheet model = new GoogleSpreadsheet(); if (ObjectHelper.isNotEmpty(spreadsheet)) { model.setSpreadsheetId(spreadsheet.getSpreadsheetId()); SpreadsheetProperties spreadsheetProperties = spreadsheet.getProperties(); if (ObjectHelper.isNotEmpty(spreadsheetProperties)) { model.setTitle(spreadsheetProperties.getTitle()); model.setUrl(spreadsheet.getSpreadsheetUrl()); model.setTimeZone(spreadsheetProperties.getTimeZone()); model.setLocale(spreadsheetProperties.getLocale()); } List<GoogleSheet> sheets = new ArrayList<>(); if (ObjectHelper.isNotEmpty(spreadsheet.getSheets())) { spreadsheet.getSheets().stream() .map(Sheet::getProperties) .forEach(props -> { GoogleSheet sheet = new GoogleSheet(); sheet.setSheetId(props.getSheetId()); sheet.setIndex(props.getIndex()); sheet.setTitle(props.getTitle()); sheets.add(sheet); }); } model.setSheets(sheets); } in.setBody(model); }
Example #5
Source File: GoogleSheetsGetSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 5 votes |
private static void beforeConsumer(Exchange exchange) { final Message in = exchange.getIn(); final Spreadsheet spreadsheet = exchange.getIn().getBody(Spreadsheet.class); GoogleSpreadsheet model = new GoogleSpreadsheet(); if (ObjectHelper.isNotEmpty(spreadsheet)) { model.setSpreadsheetId(spreadsheet.getSpreadsheetId()); SpreadsheetProperties spreadsheetProperties = spreadsheet.getProperties(); if (ObjectHelper.isNotEmpty(spreadsheetProperties)) { model.setTitle(spreadsheetProperties.getTitle()); model.setUrl(spreadsheet.getSpreadsheetUrl()); model.setTimeZone(spreadsheetProperties.getTimeZone()); model.setLocale(spreadsheetProperties.getLocale()); } List<GoogleSheet> sheets = new ArrayList<>(); if (ObjectHelper.isNotEmpty(spreadsheet.getSheets())) { spreadsheet.getSheets().stream() .map(Sheet::getProperties) .forEach(props -> { GoogleSheet sheet = new GoogleSheet(); sheet.setSheetId(props.getSheetId()); sheet.setIndex(props.getIndex()); sheet.setTitle(props.getTitle()); sheets.add(sheet); }); } model.setSheets(sheets); } in.setBody(model); }
Example #6
Source File: GoogleSheetsUpdateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 5 votes |
private static void afterProducer(Exchange exchange) { final Message in = exchange.getIn(); final BatchUpdateSpreadsheetResponse batchUpdateResponse = in.getBody(BatchUpdateSpreadsheetResponse.class); GoogleSpreadsheet model = new GoogleSpreadsheet(); model.setSpreadsheetId(batchUpdateResponse.getSpreadsheetId()); if (ObjectHelper.isNotEmpty(batchUpdateResponse.getUpdatedSpreadsheet())) { SpreadsheetProperties spreadsheetProperties = batchUpdateResponse.getUpdatedSpreadsheet().getProperties(); if (ObjectHelper.isNotEmpty(spreadsheetProperties)) { model.setTitle(spreadsheetProperties.getTitle()); model.setUrl(batchUpdateResponse.getUpdatedSpreadsheet().getSpreadsheetUrl()); model.setTimeZone(spreadsheetProperties.getTimeZone()); model.setLocale(spreadsheetProperties.getLocale()); } List<GoogleSheet> sheets = new ArrayList<>(); if (ObjectHelper.isNotEmpty(batchUpdateResponse.getUpdatedSpreadsheet().getSheets())) { batchUpdateResponse.getUpdatedSpreadsheet().getSheets().stream() .map(Sheet::getProperties) .forEach(props -> { GoogleSheet sheet = new GoogleSheet(); sheet.setSheetId(props.getSheetId()); sheet.setIndex(props.getIndex()); sheet.setTitle(props.getTitle()); sheets.add(sheet); }); } model.setSheets(sheets); } in.setBody(model); }
Example #7
Source File: GoogleSheetsCreateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testAfterProducer() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); Spreadsheet spreadsheet = new Spreadsheet(); spreadsheet.setSpreadsheetId(getSpreadsheetId()); SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); spreadsheetProperties.setTitle("SyndesisTest"); spreadsheetProperties.setTimeZone("America/New_York"); spreadsheetProperties.setLocale("en"); spreadsheet.setProperties(spreadsheetProperties); Sheet sheet = new Sheet(); SheetProperties sheetProperties = new SheetProperties(); sheetProperties.setTitle("Sheet1"); sheetProperties.setSheetId(1); sheetProperties.setIndex(1); sheet.setProperties(sheetProperties); spreadsheet.setSheets(Collections.singletonList(sheet)); inbound.getIn().setBody(spreadsheet); getComponent().getAfterProducer().process(inbound); GoogleSpreadsheet model = (GoogleSpreadsheet) inbound.getIn().getBody(); Assert.assertEquals(getSpreadsheetId(), model.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", model.getTitle()); Assert.assertEquals("America/New_York", model.getTimeZone()); Assert.assertEquals("en", model.getLocale()); Assert.assertEquals(1, model.getSheets().size()); Assert.assertEquals("Sheet1", model.getSheets().get(0).getTitle()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getSheetId()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getIndex()); }
Example #8
Source File: BaseTest.java From java-samples with Apache License 2.0 | 5 votes |
protected String createTestSpreadsheet() throws IOException { Spreadsheet spreadsheet = new Spreadsheet() .setProperties(new SpreadsheetProperties() .setTitle("Test Spreadsheet")); spreadsheet = service.spreadsheets().create(spreadsheet) .setFields("spreadsheetId") .execute(); return spreadsheet.getSpreadsheetId(); }
Example #9
Source File: GoogleSheetsLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenCreateSpreadSheet_thenIdOk() throws IOException { Spreadsheet spreadSheet = new Spreadsheet().setProperties(new SpreadsheetProperties().setTitle("My Spreadsheet")); Spreadsheet result = sheetsService.spreadsheets().create(spreadSheet).execute(); assertThat(result.getSpreadsheetId()).isNotNull(); }
Example #10
Source File: GoogleSheetsCreateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final GoogleSpreadsheet model = exchange.getIn().getBody(GoogleSpreadsheet.class); if (model != null) { if (ObjectHelper.isNotEmpty(model.getTitle())) { title = model.getTitle(); } if (ObjectHelper.isNotEmpty(model.getTimeZone())) { timeZone = model.getTimeZone(); } if (ObjectHelper.isNotEmpty(model.getLocale())) { locale = model.getLocale(); } } Spreadsheet spreadsheet = new Spreadsheet(); SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); spreadsheetProperties.setTitle(title); spreadsheetProperties.setTimeZone(timeZone); spreadsheetProperties.setLocale(locale); spreadsheet.setProperties(spreadsheetProperties); if (model != null && ObjectHelper.isNotEmpty(model.getSheets())) { List<Sheet> sheets = new ArrayList<>(); for (GoogleSheet sheetModel : model.getSheets()) { Sheet sheet = new Sheet(); SheetProperties sheetProperties = new SheetProperties(); sheetProperties.setSheetId(sheetModel.getSheetId()); sheetProperties.setIndex(sheetModel.getIndex()); sheetProperties.setTitle(sheetModel.getTitle()); sheet.setProperties(sheetProperties); sheets.add(sheet); } spreadsheet.setSheets(sheets); } in.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "content", spreadsheet); }
Example #11
Source File: GoogleSheetsUpdateSpreadsheetCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final GoogleSpreadsheet model = exchange.getIn().getBody(GoogleSpreadsheet.class); if (model != null) { if (ObjectHelper.isNotEmpty(model.getSpreadsheetId())) { spreadsheetId = model.getSpreadsheetId(); } if (ObjectHelper.isNotEmpty(model.getTitle())) { title = model.getTitle(); } if (ObjectHelper.isNotEmpty(model.getTimeZone())) { timeZone = model.getTimeZone(); } if (ObjectHelper.isNotEmpty(model.getLocale())) { locale = model.getLocale(); } } BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest(); batchUpdateRequest.setIncludeSpreadsheetInResponse(true); batchUpdateRequest.setRequests(new ArrayList<>()); List<String> fields = new ArrayList<>(); SpreadsheetProperties spreadsheetProperties = getSpreadsheetProperties(fields); if (ObjectHelper.isNotEmpty(fields)) { UpdateSpreadsheetPropertiesRequest updatePropertiesRequest = new UpdateSpreadsheetPropertiesRequest(); updatePropertiesRequest.setProperties(spreadsheetProperties); updatePropertiesRequest.setFields(String.join(",", fields)); batchUpdateRequest.getRequests().add(new Request().setUpdateSpreadsheetProperties(updatePropertiesRequest)); } if (model != null && ObjectHelper.isNotEmpty(model.getSheets())) { for (GoogleSheet sheet : model.getSheets()) { UpdateSheetPropertiesRequest updateSheetPropertiesRequest = new UpdateSheetPropertiesRequest(); SheetProperties properties = new SheetProperties(); properties.setSheetId(sheet.getSheetId()); properties.setIndex(sheet.getIndex()); properties.setTitle(sheet.getTitle()); updateSheetPropertiesRequest.setProperties(properties); updateSheetPropertiesRequest.setFields("title"); batchUpdateRequest.getRequests().add(new Request().setUpdateSheetProperties(updateSheetPropertiesRequest)); } } in.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, spreadsheetId); in.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest", batchUpdateRequest); }
Example #12
Source File: GoogleSheetsUpdateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testAfterProducer() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); BatchUpdateSpreadsheetResponse batchUpdateResponse = new BatchUpdateSpreadsheetResponse(); batchUpdateResponse.setSpreadsheetId(getSpreadsheetId()); Spreadsheet spreadsheet = new Spreadsheet(); spreadsheet.setSpreadsheetId(getSpreadsheetId()); SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); spreadsheetProperties.setTitle("SyndesisTest"); spreadsheetProperties.setTimeZone("America/New_York"); spreadsheetProperties.setLocale("en"); spreadsheet.setProperties(spreadsheetProperties); Sheet sheet = new Sheet(); SheetProperties sheetProperties = new SheetProperties(); sheetProperties.setTitle("Sheet1"); sheetProperties.setSheetId(1); sheetProperties.setIndex(1); sheet.setProperties(sheetProperties); spreadsheet.setSheets(Collections.singletonList(sheet)); batchUpdateResponse.setUpdatedSpreadsheet(spreadsheet); inbound.getIn().setBody(batchUpdateResponse); getComponent().getAfterProducer().process(inbound); GoogleSpreadsheet model = (GoogleSpreadsheet) inbound.getIn().getBody(); Assert.assertEquals(getSpreadsheetId(), model.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", model.getTitle()); Assert.assertEquals("America/New_York", model.getTimeZone()); Assert.assertEquals("en", model.getLocale()); Assert.assertEquals(1, model.getSheets().size()); Assert.assertEquals("Sheet1", model.getSheets().get(0).getTitle()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getSheetId()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getIndex()); }
Example #13
Source File: GoogleSheetsGetSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testBeforeConsumer() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); Spreadsheet spreadsheet = new Spreadsheet(); spreadsheet.setSpreadsheetId(getSpreadsheetId()); SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); spreadsheetProperties.setTitle("SyndesisTest"); spreadsheetProperties.setTimeZone("America/New_York"); spreadsheetProperties.setLocale("en"); spreadsheet.setProperties(spreadsheetProperties); Sheet sheet = new Sheet(); SheetProperties sheetProperties = new SheetProperties(); sheetProperties.setTitle("Sheet1"); sheetProperties.setSheetId(1); sheetProperties.setIndex(1); sheet.setProperties(sheetProperties); spreadsheet.setSheets(Collections.singletonList(sheet)); inbound.getIn().setBody(spreadsheet); getComponent().getBeforeConsumer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("get", ConnectorOptions.extractOption(options, "methodName")); GoogleSpreadsheet model = (GoogleSpreadsheet) inbound.getIn().getBody(); Assert.assertEquals(getSpreadsheetId(), model.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", model.getTitle()); Assert.assertEquals("America/New_York", model.getTimeZone()); Assert.assertEquals("en", model.getLocale()); Assert.assertEquals(1, model.getSheets().size()); Assert.assertEquals("Sheet1", model.getSheets().get(0).getTitle()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getSheetId()); Assert.assertEquals(Integer.valueOf(1), model.getSheets().get(0).getIndex()); }
Example #14
Source File: GoogleSheetsLiveTest.java From tutorials with MIT License | 4 votes |
@Test public void whenUpdateSpreadSheetTitle_thenOk() throws IOException { UpdateSpreadsheetPropertiesRequest updateRequest = new UpdateSpreadsheetPropertiesRequest().setFields("*").setProperties(new SpreadsheetProperties().setTitle("Expenses")); CopyPasteRequest copyRequest = new CopyPasteRequest().setSource(new GridRange().setSheetId(0).setStartColumnIndex(0).setEndColumnIndex(2).setStartRowIndex(0).setEndRowIndex(1)) .setDestination(new GridRange().setSheetId(1).setStartColumnIndex(0).setEndColumnIndex(2).setStartRowIndex(0).setEndRowIndex(1)).setPasteType("PASTE_VALUES"); List<Request> requests = new ArrayList<>(); requests.add(new Request().setCopyPaste(copyRequest)); requests.add(new Request().setUpdateSpreadsheetProperties(updateRequest)); BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests); sheetsService.spreadsheets().batchUpdate(SPREADSHEET_ID, body).execute(); }