com.google.api.services.sheets.v4.model.Spreadsheet Java Examples
The following examples show how to use
com.google.api.services.sheets.v4.model.Spreadsheet.
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("/read") @GET @Produces(MediaType.TEXT_PLAIN) public Response readSheet(@QueryParam("spreadsheetId") String spreadsheetId) { try { Spreadsheet response = producerTemplate.requestBody("google-sheets://spreadsheets/get?inBody=spreadsheetId", spreadsheetId, Spreadsheet.class); if (response != null) { return Response.ok(response.getProperties().getTitle()).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } catch (CamelExecutionException e) { Exception exchangeException = e.getExchange().getException(); if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) { GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause(); return Response.status(originalException.getStatusCode()).build(); } throw e; } }
Example #3
Source File: GoogleSheetsCreateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); 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("create", ConnectorOptions.extractOption(options, "methodName")); Spreadsheet spreadsheet = (Spreadsheet) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "content"); Assert.assertNull(spreadsheet.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", spreadsheet.getProperties().getTitle()); Assert.assertEquals("America/New_York", spreadsheet.getProperties().getTimeZone()); Assert.assertEquals("en", spreadsheet.getProperties().getLocale()); Assert.assertNull(spreadsheet.getSheets()); }
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: GoogleSheetsCreateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GoogleSpreadsheet model = new GoogleSpreadsheet(); model.setTitle("SyndesisTest"); model.setTimeZone("America/New_York"); model.setLocale("en"); GoogleSheet sheetModel = new GoogleSheet(); sheetModel.setTitle("Sheet1"); sheetModel.setSheetId(1); sheetModel.setIndex(1); model.setSheets(Collections.singletonList(sheetModel)); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Spreadsheet spreadsheet = (Spreadsheet) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "content"); Assert.assertNull(spreadsheet.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", spreadsheet.getProperties().getTitle()); Assert.assertEquals("America/New_York", spreadsheet.getProperties().getTimeZone()); Assert.assertEquals("en", spreadsheet.getProperties().getLocale()); Assert.assertNotNull(spreadsheet.getSheets()); Assert.assertEquals(1, spreadsheet.getSheets().size()); Assert.assertEquals("Sheet1", spreadsheet.getSheets().get(0).getProperties().getTitle()); }
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: 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 #12
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()); }