Java Code Examples for com.google.api.services.sheets.v4.model.Spreadsheet#setProperties()

The following examples show how to use com.google.api.services.sheets.v4.model.Spreadsheet#setProperties() . 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 vote down vote up
@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: GoogleSheetsCreateSpreadsheetCustomizerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: GoogleSheetsCreateSpreadsheetCustomizer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
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 4
Source File: GoogleSheetsUpdateSpreadsheetCustomizerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 5
Source File: GoogleSheetsGetSpreadsheetCustomizerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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());
}