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

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


    return change.getId();
  }

  @Override
  public GFile getGFile() {
    File file = change.getFile();
    return new GFileBuilder(exec, file).build();
  }
View Full Code Here


  private final List<String> parents = newArrayList();

  @Override
  public File build() {
    File file = new File();

    if (title != null) {
      file.setTitle(title);
    }

    if (mimeType != null) {
      mimeType.set(file);
    }

    if (!parents.isEmpty()) {
      List<ParentReference> _parents = transform(parents, ToParentReference.INSTANCE);
      List<ParentReference> parents = ImmutableList.copyOf(_parents);
      file.setParents(parents);
    }

    return file;
  }
View Full Code Here

      this.directoryId = directoryId;
    }

    @Override
    public boolean apply(Change input) {
      File file = input.getFile();

      boolean res = false;

      if (file != null) {
        List<ParentReference> parents;
        parents = file.getParents();

        List<String> _ids;
        _ids = transform(parents, ParentReferenceToId.INSTANCE);

        Set<String> ids;
View Full Code Here

    this.exec = exec;
  }

  @Override
  public GDirectory root() {
    File file = exec.directoryOf("root");
    return new GDirectoryFolder(exec, file);
  }
View Full Code Here

    return new GDirectoryFolder(exec, file);
  }

  @Override
  public GDirectory chdir(String directoryId) {
    File file = exec.directoryOf(directoryId);
    return new GDirectoryFolder(exec, file);
  }
View Full Code Here

    this.mimeType = mimeType;
  }

  @Override
  File execute(Drive drive, String id) throws IOException {
    File body = new FileBuilder()
        .title(title)
        .mimeType(mimeType)
        .parent(id)
        .build();
View Full Code Here

  }

  @Override
  public void write(InputStream inputStream) throws IOException {
    LOGGER.info("Getting AW Reports Drive output folder");
    File outputFolder;
    // Get or create an AW Reports folder
    File reportsFolder = googleDriveService.getReportsFolder(mccAccountId);
    outputFolder = reportsFolder;
   
    if( folderPerAccount ) {
      File accountFolder = googleDriveService.getAccountFolder(reportsFolder, String.valueOf(accountId));
      outputFolder = accountFolder;
    }

    // Create a Google Drive PDF file
    File reportFile = new File();
    reportFile.setFileExtension(reportFileType.name());

    String fileNameWithOutExt = FilenameUtils.removeExtension((templateName));
    String reportFileName = fileNameWithOutExt + "_" + accountId + "_" + dateStart + "_"
        + dateEnd + "." + reportFileType.toString().toLowerCase();
   
    reportFile.setDescription("AdWords Report " + fileNameWithOutExt + " for account "
        + accountId + "for dates between" + dateStart + " and " + dateEnd);

    reportFile.setTitle(reportFileName);

    // Place the file in the correct Drive folder
    reportFile.setParents(Arrays.asList(new ParentReference().setId(outputFolder.getId())));

    // Write the PDF file to Drive.
    if (reportFileType.equals(ReportFileType.PDF)) {
      reportFile.setMimeType(PDF_MIME_TYPE);
      AbstractInputStreamContent aisc = new InputStreamContent(PDF_MIME_TYPE, inputStream);
      googleDriveService.getDriveService().files().insert(reportFile, aisc).execute();
    }

    // Write the HTML file to Drive.
    if (reportFileType.equals(ReportFileType.HTML)) {
      reportFile.setMimeType(HTML_MIME_TYPE);
      AbstractInputStreamContent aisc = new InputStreamContent(HTML_MIME_TYPE, inputStream);
      googleDriveService.getDriveService().files().insert(reportFile, aisc).execute();
    }
   
    // Convert the HTML file to a Drive Doc and write to Drive.
    if (reportFileType.equals(ReportFileType.DRIVE_DOC)) {
      reportFile.setMimeType(DOC_MIME_TYPE);
      AbstractInputStreamContent aisc = new InputStreamContent(HTML_MIME_TYPE, inputStream);
      googleDriveService.getDriveService().files().insert(reportFile, aisc).setConvert(true).execute();
    }
    inputStream.close();
  }
View Full Code Here

      return results.get(0);

    } else {
      // Folder does not exist. Create it.
      LOGGER.info("Creating folder");
      File reportsFolder = new File();
      reportsFolder.setTitle(reportFolderName);
      reportsFolder.setMimeType(FOLDER_MIME_TYPE);
      reportsFolder.setDescription("Contains AdWords Reports generated by AwReporting");

      LOGGER.info("Executing create folder");
      return service.files().insert(reportsFolder).execute();
    }
  }
View Full Code Here

    ChildList files = request.execute();
    LOGGER.info("Number of results from query: " + files.size());
    results.addAll(files.getItems());

    if(!results.isEmpty()) {
      return new File().setId(results.get(0).getId());

    } else {
      // Folder does not exist. Create it.
      LOGGER.info("Creating sub-folder");
      File accountFolder = new File();
      accountFolder.setTitle(accountFolderName);
      accountFolder.setMimeType(FOLDER_MIME_TYPE);
      accountFolder.setDescription("AdWords Reports generated by AwReporting for account# " + accountId);
      accountFolder.setParents(Arrays.asList(new ParentReference().setId(mccDriveDirectory.getId())));

      LOGGER.info("Executing create folder");
      return service.files().insert(accountFolder).execute();
    }
  }
View Full Code Here

   * Currently used as a workaround for Drive bug (https://code.google.com/p/google-apps-script-issues/issues/detail?id=3713)
   * @param mccAccountId
   * @throws IOException
   */
  public synchronized File getFileById(String fileId) throws IOException {
    File file = service.files().get(fileId).execute();
    return file;
  }
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.