Skip to content

Commit

Permalink
Merge pull request #74 from secondsun/master
Browse files Browse the repository at this point in the history
Fixing compile errors
  • Loading branch information
mlaccetti committed Aug 31, 2015
2 parents 390a194 + 5d1b432 commit 9916c30
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@

/**
* Interface defining operations for integrating with Google Calendar.
* <p>See the reference documentation at
*
* See the reference documentation at
* <a href="http://developers.google.com/google-apps/calendar/v3/reference/">
* http://developers.google.com/google-apps/calendar/v3/reference/</a>.</p>
* <p>Requires one of the following OAuth scope(s):
* <ul>
* <li>https://www.googleapis.com/auth/calendar.readonly</li>
* <li>https://www.googleapis.com/auth/calendar</li>
* </ul>
* http://developers.google.com/google-apps/calendar/v3/reference/</a>.
* <br>
* Requires one of the following OAuth scope(s):
* <ul>
* <li>https://www.googleapis.com/auth/calendar.readonly</li>
* <li>https://www.googleapis.com/auth/calendar</li>
* </ul>
* See
* <a href="http://developers.google.com/google-apps/calendar/auth">
* http://developers.google.com/google-apps/calendar/auth</a>
* for details about the different scopes.</p>
* <a href="http://developers.google.com/google-apps/calendar/auth">http://developers.google.com/google-apps/calendar/auth</a>
* for details about the different scopes.
*
*
* @author Martin Wink
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public TimeZone getTimeZone() {
/**
* Set the time zone in which the time is specified (e.g. "Europe/Zurich").
* The time zone is required for recurring events.
* @param date the new value or {@code null} if none.
* @param timeZone the new value or {@code null} if none.
* @return this {@link DateTimeTimezone}, for chaining.
*/
public DateTimeTimezone setTimeZone(TimeZone timeZone) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,128 +1,136 @@
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.google.api.query.impl;

import static org.springframework.util.StringUtils.hasText;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.social.google.api.query.QueryBuilder;

/**
* Abstract superclass for {@link QueryBuilder} implementations.
* @author Gabriel Axel
* @param <Q> {@link QueryBuilder} type
* @param <T> Model type
*/
public abstract class QueryBuilderImpl<Q extends QueryBuilder<?, T>, T> implements QueryBuilder<Q, T> {

private static final Format dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

protected String feedUrl;
private Map<String, String> params = new HashMap<String, String>();

protected static String encode(String text) {
try {
return URLEncoder.encode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

protected QueryBuilderImpl() {
}

protected QueryBuilderImpl(String feedUrl) {
this.feedUrl = feedUrl;
}

@SuppressWarnings("unchecked")
protected Q castThis() {
return (Q)this;
}

@Override
public Q maxResultsNumber(int maxResults) {
appendQueryParam("maxResults", maxResults);
return castThis();
}

protected Q appendQueryParam(String name, Date value) {
if(value != null) {
appendQueryParam(name, dateFormatter.format(value));
}
return castThis();
}

protected Q appendQueryParam(String name, int value) {
if(value > 0) {
appendQueryParam(name, String.valueOf(value));
}
return castThis();
}

protected Q appendQueryParam(String name, boolean value) {
if(value) {
appendQueryParam(name, "true");
}
return castThis();
}

protected Q appendQueryParam(String name, Object value) {
if(value != null) {
appendQueryParam(name, value.toString());
}
return castThis();
}

protected Q appendQueryParam(StringBuilder sb, String name, Enum<?> value) {
if(value != null) {
appendQueryParam(name, value.name().toLowerCase());
}
return castThis();
}

protected Q appendQueryParam(String name, String value) {
if(hasText(value)) {
params.put(name, value);
}
return castThis();
}

protected String build() {

StringBuilder sb = new StringBuilder(feedUrl);
if(!params.isEmpty() && feedUrl.indexOf('?') < 0) {
sb.append('?');
}

for(Entry<String, String> param : params.entrySet()) {
if(sb.charAt(sb.length() - 1) != '?') {
sb.append('&');
}
sb.append(param.getKey()).append('=').append(param.getValue());
}

return sb.toString();
}
}
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.google.api.query.impl;

import static org.springframework.util.StringUtils.hasText;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;

import org.springframework.social.google.api.query.QueryBuilder;

/**
* Abstract superclass for {@link QueryBuilder} implementations.
* @author Gabriel Axel
* @param <Q> {@link QueryBuilder} type
* @param <T> Model type
*/
public abstract class QueryBuilderImpl<Q extends QueryBuilder<?, T>, T> implements QueryBuilder<Q, T> {

private static final Format dateFormatter;

static {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
dateFormatter = simpleDateFormat;
}

protected String feedUrl;
private Map<String, String> params = new LinkedHashMap<String, String>();

protected static String encode(String text) {
try {
return URLEncoder.encode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

protected QueryBuilderImpl() {
}

protected QueryBuilderImpl(String feedUrl) {
this.feedUrl = feedUrl;
}

@SuppressWarnings("unchecked")
protected Q castThis() {
return (Q)this;
}

@Override
public Q maxResultsNumber(int maxResults) {
appendQueryParam("maxResults", maxResults);
return castThis();
}

protected Q appendQueryParam(String name, Date value) {
if(value != null) {
appendQueryParam(name, dateFormatter.format(value));
}
return castThis();
}

protected Q appendQueryParam(String name, int value) {
if(value > 0) {
appendQueryParam(name, String.valueOf(value));
}
return castThis();
}

protected Q appendQueryParam(String name, boolean value) {
if(value) {
appendQueryParam(name, "true");
}
return castThis();
}

protected Q appendQueryParam(String name, Object value) {
if(value != null) {
appendQueryParam(name, value.toString());
}
return castThis();
}

protected Q appendQueryParam(StringBuilder sb, String name, Enum<?> value) {
if(value != null) {
appendQueryParam(name, value.name().toLowerCase());
}
return castThis();
}

protected Q appendQueryParam(String name, String value) {
if(hasText(value)) {
params.put(name, value);
}
return castThis();
}

protected String build() {

StringBuilder sb = new StringBuilder(feedUrl);
if(!params.isEmpty() && feedUrl.indexOf('?') < 0) {
sb.append('?');
}

for(Entry<String, String> param : params.entrySet()) {
if(sb.charAt(sb.length() - 1) != '?') {
sb.append('&');
}
sb.append(param.getKey()).append('=').append(param.getValue());
}

return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void getCalendar_escaped() {
.andRespond(
withSuccess(jsonResource("mock_get_calendar_primary"), APPLICATION_JSON));

Calendar cal = google.calendarOperations().getCalendar("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?");
Calendar cal = google.calendarOperations().getCalendar("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?");

assertNotNull(cal);
// NB queried for "primary" but actually get back the real ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void listEvents_primary_fromPage_escaping() {

EventPage eventPage = google.calendarOperations()
.eventListQuery(CalendarOperations.PRIMARY_CALENDAR_ID)
.fromPage("abc123_¬!£$%^&*()_+-=[]{};'#:@~,./<>?")
.fromPage("abc123_¬!£$%^&*()_+-=[]{};'#:@~,./<>?")
.getPage();

assertNotNull(eventPage);
Expand Down Expand Up @@ -436,18 +436,18 @@ public void listEvents_primary_combined_options() {

EventPage eventPage = google.calendarOperations()
.eventListQuery(CalendarOperations.PRIMARY_CALENDAR_ID)
.fromPage("pretendPageToken")
.alwaysIncludeEmail(true)
.iCalUID("test-iCalUID")
.maxAttendees(9)
.maxResultsNumber(50)
.orderBy(OrderBy.START_TIME)
.alwaysIncludeEmail(true)
.orderBy(OrderBy.START_TIME)
.timeZone(TEST_TIMEZONE)
.fromPage("pretendPageToken")
.singleEvents(true)
.showHiddenInvitations(true)
.maxResultsNumber(50)
.maxAttendees(9)
.timeMin(TEST_TIME_MIN)
.iCalUID("test-iCalUID")
.showDeleted(true)
.showHiddenInvitations(true)
.singleEvents(true)
.timeMax(TEST_TIME_MAX)
.timeMin(TEST_TIME_MIN)
.timeZone(TEST_TIMEZONE)
.timeMax(TEST_TIME_MAX)
.updatedMin(TEST_UPDATED_MIN)
.getPage();

Expand All @@ -464,7 +464,7 @@ public void listEvents_escape_calendarId() {
withSuccess(jsonResource("mock_get_event"), APPLICATION_JSON));

EventPage eventPage = google.calendarOperations()
.eventListQuery("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.eventListQuery("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.getPage();

assertNotNull(eventPage);
Expand All @@ -480,8 +480,8 @@ public void listEvents_escape_pageToken() {
withSuccess(jsonResource("mock_list_events_empty"), APPLICATION_JSON));

EventPage eventPage = google.calendarOperations()
.eventListQuery("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.fromPage("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.eventListQuery("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.fromPage("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?")
.getPage();

assertNotNull(eventPage);
Expand Down Expand Up @@ -512,7 +512,7 @@ public void getEvent_escape_calendarId() {
.andRespond(
withSuccess(jsonResource("mock_get_event"), APPLICATION_JSON));

Event event = google.calendarOperations().getEvent("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?", "abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?");
Event event = google.calendarOperations().getEvent("abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?", "abc123!\"£$%^&*()_+-=[]{};'#:@~,./<>?");

assertNotNull(event);
}
Expand Down

0 comments on commit 9916c30

Please sign in to comment.