com.google.api.services.sheets.v4.model.UpdateSpreadsheetPropertiesRequest Java Examples
The following examples show how to use
com.google.api.services.sheets.v4.model.UpdateSpreadsheetPropertiesRequest.
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("/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 #2
Source File: GoogleSheetsUpdateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("title", "SyndesisTest"); options.put("timeZone", "America/New_York"); options.put("locale", "en"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("batchUpdate", ConnectorOptions.extractOption(options, "methodName")); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateSpreadsheetPropertiesRequest updateSpreadsheetPropertiesRequest = batchUpdateRequest.getRequests().get(0).getUpdateSpreadsheetProperties(); Assert.assertEquals("title,timeZone,locale", updateSpreadsheetPropertiesRequest.getFields()); Assert.assertEquals("SyndesisTest", updateSpreadsheetPropertiesRequest.getProperties().getTitle()); Assert.assertEquals("America/New_York", updateSpreadsheetPropertiesRequest.getProperties().getTimeZone()); Assert.assertEquals("en", updateSpreadsheetPropertiesRequest.getProperties().getLocale()); }
Example #3
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 #4
Source File: GoogleSheetsUpdateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testBeforeProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GoogleSpreadsheet model = new GoogleSpreadsheet(); model.setSpreadsheetId(getSpreadsheetId()); model.setTitle("SyndesisTest"); model.setTimeZone("America/New_York"); model.setLocale("en"); GoogleSheet sheet1 = new GoogleSheet(); sheet1.setTitle("Sheet1"); sheet1.setSheetId(1); sheet1.setIndex(1); GoogleSheet sheet2 = new GoogleSheet(); sheet2.setTitle("Sheet2"); sheet2.setSheetId(2); model.setSheets(Arrays.asList(sheet1, sheet2)); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(3, batchUpdateRequest.getRequests().size()); UpdateSpreadsheetPropertiesRequest updateSpreadsheetPropertiesRequest = batchUpdateRequest.getRequests().get(0).getUpdateSpreadsheetProperties(); Assert.assertEquals("title,timeZone,locale", updateSpreadsheetPropertiesRequest.getFields()); Assert.assertEquals("SyndesisTest", updateSpreadsheetPropertiesRequest.getProperties().getTitle()); Assert.assertEquals("America/New_York", updateSpreadsheetPropertiesRequest.getProperties().getTimeZone()); Assert.assertEquals("en", updateSpreadsheetPropertiesRequest.getProperties().getLocale()); UpdateSheetPropertiesRequest updateSheetPropertiesRequest = batchUpdateRequest.getRequests().get(1).getUpdateSheetProperties(); Assert.assertEquals("title", updateSheetPropertiesRequest.getFields()); Assert.assertEquals(Integer.valueOf(1), updateSheetPropertiesRequest.getProperties().getIndex()); Assert.assertEquals(Integer.valueOf(1), updateSheetPropertiesRequest.getProperties().getSheetId()); Assert.assertEquals("Sheet1", updateSheetPropertiesRequest.getProperties().getTitle()); updateSheetPropertiesRequest = batchUpdateRequest.getRequests().get(2).getUpdateSheetProperties(); Assert.assertEquals("title", updateSheetPropertiesRequest.getFields()); Assert.assertNull(updateSheetPropertiesRequest.getProperties().getIndex()); Assert.assertEquals(Integer.valueOf(2), updateSheetPropertiesRequest.getProperties().getSheetId()); Assert.assertEquals("Sheet2", updateSheetPropertiesRequest.getProperties().getTitle()); }
Example #5
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(); }