Package com.google.api.services.drive.model

Examples of com.google.api.services.drive.model.File


        }       
    }

    @Test
    public void testGet() throws Exception {
        File testFile = uploadTestFile();
        String fileId = testFile.getId();
       
        // using String message body for single parameter "fileId"
        final File result = requestBody("direct://GET", fileId);

        assertNotNull("get result", result);
        LOG.debug("get: " + result);
    }
View Full Code Here


        LOG.debug("get: " + result);
    }

    @Test
    public void testInsert() throws Exception {
        File file = new File();       
        file.setTitle(UPLOAD_FILE.getName());
        // using com.google.api.services.drive.model.File message body for single parameter "content"
        File result = requestBody("direct://INSERT", file);
        assertNotNull("insert result", result);
        LOG.debug("insert: " + result);
    }
View Full Code Here

        LOG.debug("insert: " + result);
    }

    @Test
    public void testInsert1() throws Exception {       
        File result = uploadTestFile();

        assertNotNull("insert result", result);
        LOG.debug("insert: " + result);
    }
View Full Code Here

    }

    @Test
    public void testList() throws Exception {
        // upload a test file
        File theTestFile = uploadTestFile();
       
        final FileList result = requestBody("direct://LIST", null);
        assertNotNull("list result", result);
        LOG.debug("list: " + result);
    }
View Full Code Here

        LOG.debug("patch: " + result);
    }

    @Test
    public void testTouch() throws Exception {
        File theTestFile = uploadTestFile();
        DateTime createdDate = theTestFile.getModifiedDate();
        // using String message body for single parameter "fileId"
        File result = requestBody("direct://TOUCH", theTestFile.getId());

        assertNotNull("touch result", result);
        assertTrue(result.getModifiedDate().getValue() > createdDate.getValue());
    }
View Full Code Here

        assertTrue(result.getModifiedDate().getValue() > createdDate.getValue());
    }

    @Test
    public void testTrash() throws Exception {
        File testFile = uploadTestFile();
        String fileId = testFile.getId();      

        assertNotNull("trash result", requestBody("direct://TRASH", fileId));
        assertNotNull("untrash result", requestBody("direct://UNTRASH", fileId));

    }  
View Full Code Here

    }  

    @Test
    public void testUpdate() throws Exception {
        File theTestFile = uploadTestFile();
       
        final Map<String, Object> headers = new HashMap<String, Object>();
        // parameter type is String
        headers.put("CamelGoogleDrive.fileId", theTestFile.getId());
        // parameter type is com.google.api.services.drive.model.File
        headers.put("CamelGoogleDrive.content", theTestFile);

        File result = requestBodyAndHeaders("direct://UPDATE", null, headers);

        assertNotNull("update result", result);
        LOG.debug("update: " + result);
    }
View Full Code Here

    @Test
    public void testUpdate1() throws Exception {      
       
        // First retrieve the file from the API.
        File testFile = uploadTestFile();
        String fileId = testFile.getId();
       
        // using String message body for single parameter "fileId"
        final File file = requestBody("direct://GET", fileId);

        // File's new metadata.
        file.setTitle("camel.png");

        // File's new content.
        java.io.File fileContent = new java.io.File(TEST_UPLOAD_IMG);
        FileContent mediaContent = new FileContent(null, fileContent);

        // Send the request to the API.
       
        final Map<String, Object> headers = new HashMap<String, Object>();
        // parameter type is String
        headers.put("CamelGoogleDrive.fileId", fileId);
        // parameter type is com.google.api.services.drive.model.File
        headers.put("CamelGoogleDrive.content", file);
        // parameter type is com.google.api.client.http.AbstractInputStreamContent
        headers.put("CamelGoogleDrive.mediaContent", mediaContent);

        File result = requestBodyAndHeaders("direct://UPDATE_1", null, headers);

        assertNotNull("update result", result);
        LOG.debug("update: " + result);
    }
View Full Code Here

    private static final Logger LOG = LoggerFactory.getLogger(DriveChildrenIntegrationTest.class);
    private static final String PATH_PREFIX = GoogleDriveApiCollection.getCollection().getApiName(DriveChildrenApiMethod.class).getName();

    @Test
    public void testUploadFileToFolder() throws Exception {
        File folder = uploadTestFolder();       
        File file = uploadTestFile();
       
        final Map<String, Object> headers = new HashMap<String, Object>();
        // parameter type is String
        headers.put("CamelGoogleDrive.folderId", folder.getId());
       
        com.google.api.services.drive.model.ChildReference child = new com.google.api.services.drive.model.ChildReference();
        child.setId(file.getId());
        // parameter type is com.google.api.services.drive.model.ChildReference
        headers.put("CamelGoogleDrive.content", child);

        requestBodyAndHeaders("direct://INSERT", null, headers);
View Full Code Here

  public void upload(final Handler handler, final Item item) throws CloudsyncException, NoSuchFileException {

    initService(handler);

    String title = handler.getLocalEncryptedTitle(item);
    File parentDriveItem = null;
    File driveItem;
    int retryCount = 0;
    do {
      try {
        refreshCredential();
        parentDriveItem = _getDriveItem(item.getParent());
        final ParentReference parentReference = new ParentReference();
        parentReference.setId(parentDriveItem.getId());
        driveItem = new File();
        driveItem.setTitle(title);
        driveItem.setParents(Arrays.asList(parentReference));
        final byte[] data = _prepareDriveItem(driveItem, item, handler, true);
        if (data == null) {
          driveItem = service.files().insert(driveItem).execute();
        } else {
          final InputStreamContent params = new InputStreamContent(FILE, new ByteArrayInputStream(data));
          params.setLength(data.length);
          Insert inserter = service.files().insert(driveItem, params);
          MediaHttpUploader uploader = inserter.getMediaHttpUploader();
          prepareUploader(uploader, data);
          driveItem = inserter.execute();
        }
        if (driveItem == null) {
          throw new CloudsyncException("Could not create item '" + item.getPath() + "'");
        }
        _addToCache(driveItem, null);
        item.setRemoteIdentifier(driveItem.getId());
        return;
      } catch (final NoSuchFileException e) {
        throw e;
      } catch (final IOException e) {
        if (parentDriveItem != null) {
          for (int i = 0; i < MIN_SEARCH_RETRIES; i++) {
            driveItem = _searchDriveItem(item.getParent(), title);
            if (driveItem != null) {

              LOGGER.log(Level.WARNING, getExceptionMessage(e) + "found uploaded item - try to update");

              item.setRemoteIdentifier(driveItem.getId());
              update(handler, item, true);
              return;
            }
            LOGGER.log(Level.WARNING, getExceptionMessage(e) + "item not uploaded - retry " + (i + 1) + "/" + MIN_SEARCH_RETRIES + " - wait " + MIN_SEARCH_BREAK + " ms");
            sleep(MIN_SEARCH_BREAK);
View Full Code Here

TOP

Related Classes of com.google.api.services.drive.model.File

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.