use of com.google.api.services.drive.model.Permission in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method createSpreadsheetFromFile.
public boolean createSpreadsheetFromFile(String idParentFolder, String emailUserOwner, String extensionFile, String nameFile, java.io.File fileOrigin, String mimeType) {
boolean result = true;
Permission newPermission = createPermission();
File body = new File();
body.setTitle(nameFile);
body.setMimeType("application/vnd.google-apps.spreadsheet");
body.setEditable(true);
body.setShared(true);
body.setPermissions(Arrays.asList(newPermission));
body.setUserPermission(newPermission);
body.setWritersCanShare(true);
body.setFileExtension(extensionFile);
User user = new User();
user.setEmailAddress(emailUserOwner);
user.setIsAuthenticatedUser(true);
List<User> list = new ArrayList<User>();
list.add(user);
body.setOwners(list);
body.setParents(Arrays.asList(new ParentReference().setId(idParentFolder)));
FileContent mediaContent = new FileContent(mimeType, fileOrigin);
String fileId = "";
try {
File file = service.files().insert(body, mediaContent).execute();
fileId = file.getId();
insertPermission(newPermission, fileId);
} catch (IOException e) {
log.error("Error create spreadsheet from file ", e);
result = false;
}
log.info("create Spreadsheet in google Drive from " + nameFile);
return result;
}
use of com.google.api.services.drive.model.Permission in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method createFolder.
public boolean createFolder(String nameFolder, String emailUserOwner) {
log.info("init createFolder");
boolean resultado = true;
Permission newPermission = createPermission();
File body = new File();
body.setTitle(nameFolder);
body.setMimeType("application/vnd.google-apps.folder");
body.setEditable(true);
body.setShared(true);
List<Permission> listPermisions = new ArrayList<Permission>();
listPermisions.add(newPermission);
body.setPermissions(listPermisions);
body.setUserPermission(newPermission);
body.setWritersCanShare(true);
User user = new User();
user.setEmailAddress(emailUserOwner);
user.setIsAuthenticatedUser(true);
List<User> list = new ArrayList<User>();
list.add(user);
body.setOwners(list);
File file;
String fileId = null;
try {
file = service.files().insert(body).execute();
fileId = file.getId();
log.info("File ID: " + file.getId());
insertPermission(newPermission, fileId);
} catch (IOException e) {
log.error("Error create folder", e);
resultado = false;
}
log.info("end createFolder");
return resultado;
}
use of com.google.api.services.drive.model.Permission in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method createSpreadsheetFromFile.
/**
* Method to create a google spreadsheet from a file
*
* @param idParentFolder
* String to identify the parent folder
* @param emailUserOwner
* String to identify email user owner
* @param extensionFile
* String with extension file
* @param nameFile
* String with name google spreadsheet
* @param fileOrigin
* File with content file origin
* @param mimeType
* String with mime type file origin
*
* @return True if create is ok, False otherwise
*/
public boolean createSpreadsheetFromFile(String idParentFolder, String emailUserOwner, String extensionFile, String nameFile, java.io.File fileOrigin, String mimeType) {
boolean result = true;
Permission newPermission = createPermission();
File body = new File();
body.setTitle(nameFile);
body.setMimeType("application/vnd.google-apps.spreadsheet");
body.setEditable(true);
body.setShared(true);
body.setPermissions(Arrays.asList(newPermission));
body.setUserPermission(newPermission);
body.setWritersCanShare(true);
body.setFileExtension(extensionFile);
User user = new User();
user.setEmailAddress(emailUserOwner);
user.setIsAuthenticatedUser(true);
List<User> list = new ArrayList<User>();
list.add(user);
body.setOwners(list);
body.setParents(Arrays.asList(new ParentReference().setId(idParentFolder)));
FileContent mediaContent = new FileContent(mimeType, fileOrigin);
String fileId = "";
try {
File file = drive.files().insert(body, mediaContent).execute();
fileId = file.getId();
insertPermission(newPermission, fileId);
} catch (Exception e) {
log.error("Error create spreadsheet from file ", e);
result = false;
}
log.info("create Spreadsheet in google Drive from " + nameFile);
return result;
}
use of com.google.api.services.drive.model.Permission in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method createPermission.
/**
* Method to create permission by create a file or folder
*
* @return Permission created
*/
private Permission createPermission() {
Permission newPermission = new Permission();
/* Domain drive for example localidata.com */
newPermission.setDomain(Prop.domainPermission);
newPermission.setValue(Prop.domainPermission);
/* Acceptable types are: anyone, domain, group, user */
newPermission.setType("domain");
/* Acceptable roles are: owner, reader, writer */
newPermission.setRole("writer");
return newPermission;
}
use of com.google.api.services.drive.model.Permission in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method createFolder.
/**
* Metodo para crear una carpeta
*
* @param nameFolder
* String name folder
* @param emailUserOwner
* String email user owner
* @return True if create is ok, false otherwise
*/
public boolean createFolder(String nameFolder, String emailUserOwner) {
log.debug("init createFolder");
boolean resultado = true;
Permission newPermission = createPermission();
File body = new File();
body.setTitle(nameFolder);
body.setMimeType("application/vnd.google-apps.folder");
body.setEditable(true);
body.setShared(true);
List<Permission> listPermisions = new ArrayList<Permission>();
listPermisions.add(newPermission);
body.setPermissions(listPermisions);
body.setUserPermission(newPermission);
body.setWritersCanShare(true);
User user = new User();
user.setEmailAddress(emailUserOwner);
user.setIsAuthenticatedUser(true);
List<User> list = new ArrayList<User>();
list.add(user);
body.setOwners(list);
File file;
String fileId = null;
try {
file = drive.files().insert(body).execute();
fileId = file.getId();
log.info("File ID: " + file.getId());
insertPermission(newPermission, fileId);
} catch (Exception e) {
log.error("Error create folder", e);
resultado = false;
}
log.debug("end createFolder");
return resultado;
}
Aggregations