Skip to content

Commit 4bc3b37

Browse files
authored
Merge pull request #74 from cloudsufi/patch/nullable-fields
Make fields nullable
2 parents 66c341f + 2ee4d80 commit 4bc3b37

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/main/java/io/cdap/plugin/google/common/GoogleAuthBaseConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public ValidationResult getValidationResult(FailureCollector collector) {
177177
}
178178
if (propertiesAreValid) {
179179
try {
180-
GoogleDriveClient client = new GoogleDriveClient(this);
180+
GoogleDriveClient<GoogleAuthBaseConfig> client = new GoogleDriveClient<>(this);
181181

182182
// check directory or file access
183183
if (isDirectoryOrFileAccessible(collector, client)) {
@@ -243,7 +243,8 @@ private boolean validateServiceAccount(FailureCollector collector) {
243243
return collector.getValidationFailures().isEmpty();
244244
}
245245

246-
private boolean isDirectoryOrFileAccessible(FailureCollector collector, GoogleDriveClient driveClient)
246+
private boolean isDirectoryOrFileAccessible(FailureCollector collector,
247+
GoogleDriveClient<GoogleAuthBaseConfig> driveClient)
247248
throws IOException {
248249
if (containsMacro(FILE_IDENTIFIER) || containsMacro(DIRECTORY_IDENTIFIER)) {
249250
return false;

src/main/java/io/cdap/plugin/google/drive/source/GoogleDriveSourceConfig.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public class GoogleDriveSourceConfig extends GoogleFilteringSourceConfig {
5050
public static final String DRAWINGS_EXPORTING_FORMAT = "drawingsExportingFormat";
5151
public static final String PRESENTATIONS_EXPORTING_FORMAT = "presentationsExportingFormat";
5252

53+
public static final String DEFAULT_BODY_FORMAT = "bytes";
54+
public static final long DEFAULT_MAX_PARTITION_SIZE = 0;
55+
public static final String DEFAULT_DOCS_EXPORTING_FORMAT = "text/plain";
56+
public static final String DEFAULT_SHEETS_EXPORTING_FORMAT = "text/csv";
57+
public static final String DEFAULT_DRAWINGS_EXPORTING_FORMAT = "image/svg+xml";
58+
public static final String DEFAULT_PRESENTATIONS_EXPORTING_FORMAT = "text/plain";
59+
5360
public static final String FILE_METADATA_PROPERTIES_LABEL = "File properties";
5461
public static final String FILE_TYPES_TO_PULL_LABEL = "File types to pull";
5562
public static final String BODY_FORMAT_LABEL = "Body output format";
@@ -66,37 +73,44 @@ public class GoogleDriveSourceConfig extends GoogleFilteringSourceConfig {
6673
"The following values are supported: binary (all non-Google Drive formats), Google Documents, " +
6774
"Google Spreadsheets, Google Drawings, Google Presentations and Google Apps Scripts. \n" +
6875
"For Google Drive formats user should specify exporting format in **Exporting** section.")
76+
@Nullable
6977
@Macro
7078
protected String fileTypesToPull;
7179

7280
@Name(MAX_PARTITION_SIZE)
7381
@Description("Maximum body size for each structured record specified in bytes. \n" +
7482
"Default 0 value means unlimited. Is not applicable for files in Google formats.")
83+
@Nullable
7584
@Macro
7685
protected String maxPartitionSize;
7786

7887
@Name(BODY_FORMAT)
7988
@Description("Output format for body of file. \"Bytes\" and \"String\" values are available.")
89+
@Nullable
8090
@Macro
8191
protected String bodyFormat;
8292

8393
@Name(DOCS_EXPORTING_FORMAT)
8494
@Description("MIME type which is used for Google Documents when converted to structured records.")
95+
@Nullable
8596
@Macro
8697
protected String docsExportingFormat;
8798

8899
@Name(SHEETS_EXPORTING_FORMAT)
89100
@Description("MIME type which is used for Google Spreadsheets when converted to structured records.")
101+
@Nullable
90102
@Macro
91103
protected String sheetsExportingFormat;
92104

93105
@Name(DRAWINGS_EXPORTING_FORMAT)
94106
@Description("MIME type which is used for Google Drawings when converted to structured records.")
107+
@Nullable
95108
@Macro
96109
protected String drawingsExportingFormat;
97110

98111
@Name(PRESENTATIONS_EXPORTING_FORMAT)
99112
@Description("MIME type which is used for Google Presentations when converted to structured records.")
113+
@Nullable
100114
@Macro
101115
protected String presentationsExportingFormat;
102116
private transient Schema schema = null;
@@ -202,27 +216,28 @@ public List<ExportedType> getFileTypesToPull() {
202216
}
203217

204218
public BodyFormat getBodyFormat() {
205-
return BodyFormat.fromValue(bodyFormat);
219+
return bodyFormat == null ? BodyFormat.fromValue(DEFAULT_BODY_FORMAT) : BodyFormat.fromValue(bodyFormat);
206220
}
207221

208222
public Long getMaxPartitionSize() {
209-
return Long.parseLong(maxPartitionSize);
223+
return Strings.isNullOrEmpty(maxPartitionSize) ? DEFAULT_MAX_PARTITION_SIZE : Long.parseLong(maxPartitionSize);
210224
}
211225

212226
public String getDocsExportingFormat() {
213-
return docsExportingFormat;
227+
return Strings.isNullOrEmpty(docsExportingFormat) ? DEFAULT_DOCS_EXPORTING_FORMAT : docsExportingFormat;
214228
}
215229

216230
public String getSheetsExportingFormat() {
217-
return sheetsExportingFormat;
231+
return Strings.isNullOrEmpty(sheetsExportingFormat) ? DEFAULT_SHEETS_EXPORTING_FORMAT : sheetsExportingFormat;
218232
}
219233

220234
public String getDrawingsExportingFormat() {
221-
return drawingsExportingFormat;
235+
return Strings.isNullOrEmpty(drawingsExportingFormat) ? DEFAULT_DRAWINGS_EXPORTING_FORMAT : drawingsExportingFormat;
222236
}
223237

224238
public String getPresentationsExportingFormat() {
225-
return presentationsExportingFormat;
239+
return Strings.isNullOrEmpty(presentationsExportingFormat) ? DEFAULT_PRESENTATIONS_EXPORTING_FORMAT
240+
: presentationsExportingFormat;
226241
}
227242

228243
public GoogleDriveSourceConfig(String referenceName) {

0 commit comments

Comments
 (0)