@Test public void generateSearchQueryTest() { String result = driveHelper.generateSearchQuery(null, null, null); assertNull(result); result = driveHelper.generateSearchQuery("sample-folder", null, null); assertEquals("name = 'sample-folder' and trashed = false", result); result = driveHelper.generateSearchQuery(null, "some-parent-id", null); assertEquals("'some-parent-id' in parents and trashed = false", result); result = driveHelper.generateSearchQuery(null, null, "xml-mime-type"); assertEquals("mimeType = 'xml-mime-type' and trashed = false", result); result = driveHelper.generateSearchQuery("sample-folder", null, "xml-mime-type"); assertEquals("name = 'sample-folder' and mimeType = 'xml-mime-type' and trashed = false", result); result = driveHelper.generateSearchQuery("sample-folder", "some-parent-id", "xml-mime-type"); assertEquals("name = 'sample-folder' and 'some-parent-id' in parents and mimeType = 'xml-mime-type' and trashed = false", result); }
@Nullable public String generateSearchQuery(@Nullable String folderName, @Nullable String parentId, @Nullable String mimeType) { List<String> queryList = new ArrayList<>(); if (folderName != null) { queryList.add(String.format("name = '%s'", folderName)); } if (parentId != null) { queryList.add(String.format("'%s' in parents", parentId)); } if (mimeType != null) { queryList.add(String.format("mimeType = '%s'", mimeType)); } if (queryList.isEmpty()) { return null; } queryList.add("trashed = false"); StringBuilder query = new StringBuilder(queryList.get(0)); for (int i = 1; i < queryList.size(); i++) { query.append(" and ").append(queryList.get(i)); } return query.toString(); }
DriveHelper { @Nullable public String generateSearchQuery(@Nullable String folderName, @Nullable String parentId, @Nullable String mimeType) { List<String> queryList = new ArrayList<>(); if (folderName != null) { queryList.add(String.format("name = '%s'", folderName)); } if (parentId != null) { queryList.add(String.format("'%s' in parents", parentId)); } if (mimeType != null) { queryList.add(String.format("mimeType = '%s'", mimeType)); } if (queryList.isEmpty()) { return null; } queryList.add("trashed = false"); StringBuilder query = new StringBuilder(queryList.get(0)); for (int i = 1; i < queryList.size(); i++) { query.append(" and ").append(queryList.get(i)); } return query.toString(); } }
DriveHelper { @Nullable public String generateSearchQuery(@Nullable String folderName, @Nullable String parentId, @Nullable String mimeType) { List<String> queryList = new ArrayList<>(); if (folderName != null) { queryList.add(String.format("name = '%s'", folderName)); } if (parentId != null) { queryList.add(String.format("'%s' in parents", parentId)); } if (mimeType != null) { queryList.add(String.format("mimeType = '%s'", mimeType)); } if (queryList.isEmpty()) { return null; } queryList.add("trashed = false"); StringBuilder query = new StringBuilder(queryList.get(0)); for (int i = 1; i < queryList.size(); i++) { query.append(" and ").append(queryList.get(i)); } return query.toString(); } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); }
DriveHelper { @Nullable public String generateSearchQuery(@Nullable String folderName, @Nullable String parentId, @Nullable String mimeType) { List<String> queryList = new ArrayList<>(); if (folderName != null) { queryList.add(String.format("name = '%s'", folderName)); } if (parentId != null) { queryList.add(String.format("'%s' in parents", parentId)); } if (mimeType != null) { queryList.add(String.format("mimeType = '%s'", mimeType)); } if (queryList.isEmpty()) { return null; } queryList.add("trashed = false"); StringBuilder query = new StringBuilder(queryList.get(0)); for (int i = 1; i < queryList.size(); i++) { query.append(" and ").append(queryList.get(i)); } return query.toString(); } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); String getRootFolderId(); @Nullable Drive.Files.List buildRequest(String query, String fields); void downloadFile(@NonNull String fileId, @NonNull File file); String createOrGetIDOfSubmissionsFolder(); @Nullable String getIDOfFolderWithName(@NonNull String name, @Nullable String inFolder, boolean shouldCreateIfNotFound); String uploadFileToDrive(String mediaName, String destinationFolderID, File toUpload); String createFolderInDrive(@NonNull String folderName,
                                      @Nullable String parentId); com.google.api.services.drive.model.File createNewFile(@NonNull String name,
                                                                  @Nullable String mimeType,
                                                                  @Nullable String parentId); List<com.google.api.services.drive.model.File> getFilesFromDrive(
            @Nullable String folderName,
            @Nullable String parentId); @Nullable String generateSearchQuery(@Nullable String folderName,
                                      @Nullable String parentId,
                                      @Nullable String mimeType); void fetchFilesForCurrentPage(Drive.Files.List request, List<com.google.api.services.drive.model.File> files); }
DriveHelper { @Nullable public String generateSearchQuery(@Nullable String folderName, @Nullable String parentId, @Nullable String mimeType) { List<String> queryList = new ArrayList<>(); if (folderName != null) { queryList.add(String.format("name = '%s'", folderName)); } if (parentId != null) { queryList.add(String.format("'%s' in parents", parentId)); } if (mimeType != null) { queryList.add(String.format("mimeType = '%s'", mimeType)); } if (queryList.isEmpty()) { return null; } queryList.add("trashed = false"); StringBuilder query = new StringBuilder(queryList.get(0)); for (int i = 1; i < queryList.size(); i++) { query.append(" and ").append(queryList.get(i)); } return query.toString(); } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); String getRootFolderId(); @Nullable Drive.Files.List buildRequest(String query, String fields); void downloadFile(@NonNull String fileId, @NonNull File file); String createOrGetIDOfSubmissionsFolder(); @Nullable String getIDOfFolderWithName(@NonNull String name, @Nullable String inFolder, boolean shouldCreateIfNotFound); String uploadFileToDrive(String mediaName, String destinationFolderID, File toUpload); String createFolderInDrive(@NonNull String folderName,
                                      @Nullable String parentId); com.google.api.services.drive.model.File createNewFile(@NonNull String name,
                                                                  @Nullable String mimeType,
                                                                  @Nullable String parentId); List<com.google.api.services.drive.model.File> getFilesFromDrive(
            @Nullable String folderName,
            @Nullable String parentId); @Nullable String generateSearchQuery(@Nullable String folderName,
                                      @Nullable String parentId,
                                      @Nullable String mimeType); void fetchFilesForCurrentPage(Drive.Files.List request, List<com.google.api.services.drive.model.File> files); static final String ODK_GOOGLE_DRIVE_ROOT_FOLDER_NAME; static final String ODK_GOOGLE_DRIVE_SUBMISSION_FOLDER_NAME; static final String FOLDER_MIME_TYPE; }