Skip to main content

Google GSuite

Google Calendar - adding an event​

Adding an event to Google Calendar.

Syntax:

var calendarEvent = utils.addGoogleCalendarEvent(String title, Date beginDate, Date endDate);

Description:

ArgumentDescription
titleEvent title
beginDatestarting date+time
endDateending date+time

This event is created for the calendar associated to the current logged user.

The resulting javascript object has the following structure:

String id;
String title;
String description;
Date beginDate;
Date endDate;
EventAttendee creator;
List<EventAttendee>attendees;
String location;
String url;

where "attendees" is a list of people invited to the event; each javascript object in this list has the following structure:

String id;
String displayName;
String email;
String comment;
Boolean optional;
Boolean organizer;
Boolean creator;
String response;
Boolean resource;

Google Calendar - adding an event with more customizations​

Adding an event to Google Calendar.

Syntax:

var calendarEvent = utils.addGoogleCalendarEventWithSettings(
String title,
Date beginDate,
Date endDate,
String description,
String location,
String calendarId,
String creatorEmail,
String... attendeeEmails
);

Description:

ArgumentDescription
titleEvent title
beginDatestarting date+time
endDateending date+time
descriptionadditional description to include in the event
locationcan be null; it can be a complete address or a city, a province, etc.
calendarIdcan be null; if not filled, the default calendar for the current logged user will be used; if set, it is the calendar id where creating the event; the current admin user must have grants to save data into that calendar:; in order to retrieve the calendar id, go to Google Calendar, right click on the calendar on the list on the left and choose "Settings and sharing"; finally, search for "Calendar ID".
creatorEmailcan be null; if not filled, the current logged user email will be used; if set, this will be the owner of the event (if the specified email address in owner of the specified calendar)
attendesEmailsa Javascript array containing a list of email addresses, representing people invited to the event

This event is created for the calendar associated to the specified user/calendar.

The resulting javascript object has the following structure:

String id;
String title;
String description;
Date beginDate;
Date endDate;
EventAttendee creator;
List<EventAttendee>attendees;
String location;
String url;

where "attendees" is a list of people invited to the event; each javascript object in this list has the following structure:

String id;
String displayName;
String email;
String comment;
Boolean optional;
Boolean organizer;
Boolean creator;
String response;
Boolean resource;

Google Calendar - adding an event with conference​

Adding an event to Google Calendar with a conference linked to it. A conference can be:

Syntax:

var calendarEvent = utils.addGoogleCalendarEventWithConference(
String title,
Date beginDate,
Date endDate,
String description,
String location,
String calendarId,
String type,
String creatorEmail,
String... attendeeEmails
);

Description:

ArgumentDescription
titleEvent title
beginDatestarting date+time
endDateending date+time
descriptionadditional description to include in the event
locationcan be null; it can be a complete address or a city, a province, etc.
calendarIdcan be null; if not filled, the default calendar for the current logged user will be used; if set, it is the calendar id where creating the event; the current admin user must have grants to save data into that calendar:; in order to retrieve the calendar id, go to Google Calendar, right click on the calendar on the list on the left and choose "Settings and sharing"; finally, search for "Calendar ID".
type

link to the event a conference; allowed values are:

creatorEmailcan be null; if not filled, the current logged user email will be used; if set, this will be the owner of the event (if the specified email address in owner of the specified calendar)
attendesEmailsa Javascript array containing a list of email addresses, representing people invited to the event

This event is created for the calendar associated to the specified user/calendar.

The resulting javascript object has the following structure:

String id;
String title;
String description;
Date beginDate;
Date endDate;
EventAttendee creator;
List<EventAttendee>attendees;
String location;
String url;
String hangoutLink;

where "attendees" is a list of people invited to the event; each javascript object in this list has the following structure:

String id;
String displayName;
String email;
String comment;
Boolean optional;
Boolean organizer;
Boolean creator;
String response;
Boolean resource;

Google Calendar - modifying an event​

Change the event title or timing for a Google Calendar event.

Syntax:

var calendarEvent = utils.modifyGoogleCalendarEvent(String calendarEventId, String title, Date beginDate, Date endDate);

Description:

ArgumentDescription
calendarEventIdthe event id, which is defined when an event is created the first time and available in the "calendar event" js object returned by the previous method.
titleevent title
beginDatestarting date+time
endDateending date+time

This event is changed in the calendar associated to the current logged user.

Google Calendar - deleting an event​

Delete and already existing event in the Google Calendar.

Syntax:

utils.deleteGoogleCalendarEvent(String calendarEventId);

Description:

ArgumentDescription
calendarEventIdthe event id, which is defined when an event is created the first time and available in the "calendar event" js object returned by the previous method.

This event is removed from the calendar associated to the current logged user.

Google Drive - create a folder​

Syntax:

var file = utils.createGoogleDriveFolder(userId, folderName, parents, description);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
folderNamefolder name
parentslist of folder parents: the list of folders from the root must be specified
descriptionoptional folder description

The method returns a javascript object having the following structure:

String id;
String title;
String description;
Long size;
String mimeType;
String path;
String pathType;
String iconPath;
String iconPathType;
Boolean folder;
String owner;
String md5hash;
Map<String,String> additionalAttributes = new HashMap<String,String>();

The "id" value represents a unique identifier for the folder and can be used later to manage it (rename, delete, etc.)

Google Drive - delete a file or folder​

Syntax:

var file = utils.deleteGoogleDriveFile(userId, fileId, skipTrash);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfolder identifier (it is the "id" attribute of the js object returned by the previous method)
skipTrashboolean flag used to define how a folder deletion will be managed: true to permanently delete the folder; false to mark the folder as deleted and moved to the special "trash" folder (in such a case, it can be restored).

Google Drive - add permissions to folder​

Syntax:

var file = utils.addPermissionsToGoogleDriveFolder(
userId,
folderId,
type, value, fileRole, folderRole,
additionalRoles,
updateBaseFolder,
recursive,
sendNotifications,
message
);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
folderIdfolder id; permissions will be set for this folder and maybe to subfolders as well, according to the "recursive" boolean flag
typethe type of sharing, one between “user”, “group”, “domain” or “default”
valuethe email of the user/group or the domain name
fileRolethe role for files, one of “reader”, “writer” or “owner”
folderRolethe role for folders, one of “reader”, “writer” or “owner
additionalRoleslist of additional roles; optional string, for example [“commenter”]
updateBaseFolderboolean flag; if true applies permissions to the base folder identified by folderId
recursiveboolean flag: if set to true, apply the specified permissions to all subfolders as well
sendNotificationsboolean flag; if set to true, an email message will be sent to all destinations; the email message is defined through the next argument
messageemail notification message

Google Drive - set permissions to file​

Syntax:

var file = utils.setGoogleDriveFilePermissions(
userId,
fileId,
type,
value,
role,
additionalRoles,
sendNotifications,
message
);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile id
typethe type of sharing, one between “user”, “group”, “domain” or “default”
valuethe email of the user/group or the domain name
rolethe role for files, one of “reader”, “writer” or “owner”
additionalRoleslist of additional roles; optional string, for example [“commenter”]
updateBaseFolderboolean flag; if true applies permissions to the base folder identified by folderId
sendNotificationsboolean flag; if set to true, an email message will be sent to all destinations; the email message is defined through the next argument
messageemail notification message

Google Drive - set property to a file​

Syntax:

var file = utils.addGoogleDriveFileProperty(userId, fileId, key, value, visibility);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier
keyproperty identifier
valueproperty value
visibilityallowed values: "PRIVATE" or "PUBLIC"

Google Drive - remove a property from a file​

Syntax:

var file = utils.deleteGoogleDriveFileProperty(userId, fileId, key);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier
keyproperty identifier

Google Drive - get folder/file information​

Syntax:

var fileInfo = utils.getGoogleDriveFileInfo(userId, fileId);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier

The method returns a javascript object having the following structure:

String id;
String title;
String description;
Long size;
String mimeType;
String path;
String pathType;
String iconPath;
String iconPathType;
Boolean folder;
String owner;
String md5hash;
Map<String,String> additionalAttributes = new HashMap<String,String>();

Google Drive - set file attributes​

Change the default file attributes, like trashed, restricted, viewed, etc.

Syntax:

var fileInfo = utils.setGoogleDriveFileAttributes(userId, fileId, fileAttributes)

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier
fileAttributesa javascript object containing the file attributes to set

The "fileAttributes" javascript object must have the following structure:

Boolean starred;
Boolean trashed;
Boolean restricted;
Boolean viewed;
Boolean writersCanShare;

Google Drive - get file revisions​

It is possible to upload the same file multiple times; each time the new version will replace the previous one. However, the older versions are still available; this method allows to access to the previous versions of the file.

Syntax:

var revisions = utils.getGoogleDriveFileRevisions(userId, fileId);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier

The method returns a list of javascript objects, where each object (related to a revision) has the following structure:

String version;
String id;
String date;
String owner;
Date modifyDate;

Google Drive - get folder content​

Retrieve the folder content, in terms of files or subfolders.

Syntax:

var files = utils.getGoogleDriveFolderContents(userId, folderId, query, trashed);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
folderIdfolder identifier
queryoptional query used to filter the folder content; see https://developers.google.com/drive/web/search-parameters for additional details
trashedboolean flag; true to fetch also deleted (trashed) files and folders.

The method returns a Java List containing Java objects, where each object (related to a file/folder) has the following structure:

String id;
String title;
String description;
Date beginDate;
Date endDate;
EventAttendee creator;
List<EventAttendee>attendees;
String location;
String url;

Example:

var files = ...
for(var i=0;i<files.size();i++) \{
var file = files.get(i);
var id = file.id;
//...
\}

Google Drive - get folder content (ids)​

Retrieve the folder content, in terms of files or subfolders, each expressed only through its id.

Syntax:

var fileIds = utils.getGoogleDriveFolderContentsIds(userId, folderId, query, trashed);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
folderIdfolder identifier
queryoptional query used to filter the folder content; see https://developers.google.com/drive/web/search-parameters for additional details
trashedboolean flag; true to fetch also deleted (trashed) files and folders.

The method returns a list of file/folder ids.

Google Drive - duplicate a file​

Starting from an already existing document in Drive, duplicate it with another name in the specified destination folder..

Syntax:

var paginatedList = utils.duplicateGoogleDriveFile(
String userId,
String sourceFileId,
String destinationFolderId,
String newFileName,
Boolean copyPermissions
)

Description:

ArgumentDescription
userIdemail for the user used to create the file
sourceFileIddocument id related to the already existing file in Drive to duplicate
destinationFolderIdfolder id where copying the file
newFileNamethe new file name to assign to the duplicated document
copyPermissionsboolean flag used to inherit permissions assigned to the source document

The method returns a Java object, having the following structure:

String id;
String title;
String description;
Date beginDate;
Date endDate;
EventAttendee creator;
List<EventAttendee>attendees;
String location;
String url;

Google Drive - get folder content, one page a time​

Retrieve the folder content, in terms of files or subfolders, one page a time. It is possible to scroll along the whole content, by working through "maxPageResults" and "pages". This method can be helpful within a javascript business component for list, in case you want to show in a paginated grid the folder content and navigate through it, one page a time.

Syntax:

var paginatedList = utils.searchInGoogleDrive(maxPageResults, pages, String nextPageToken, folderId, query, trashed);

Description:

ArgumentDescription
maxPageResultsmax number of files/subfolders to get back, that will fill in the page
pagespage to read
nextPageTokentoken to pass forward to the next invocation of this method, in order to get the next page of results
folderIdfolder identifier to use when retrieving the content
queryoptional query to use to filter folder content
trashedboolean flag; true to fetch also deleted (trashed) files and folders.

This method returns a javascript object containing the following structure:

List<T> list;
String nextPageToken;

Google Drive - move file/folder​

Move the specified folder, by specifying new parent folders.

Syntax:

var file = utils.modifyGoogleDriveFileParents(userId, fileId, parentsToAdd, parentsToRemove);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfolder identifier
parentsToAdda comma separated list of folder ids that will be added as parents of the file/folder. Can be empty
parentsToRemovea comma separated list of folder ids that will be removed as parents of the file/folder. Can be empty

Google Drive - move file​

Move the specified folder, by specifying new parent folders.

Syntax:

var file = utils.moveGoogleDriveFile(userId, fileId, newParents);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier
newParentsa comma separated list of folder ids that will be added as parents of the file/folder. Can be empty

Google Drive - upload a file from the server file system​

Upload into Drive the specified file stored in the server file system.

Syntax:

var file = utils.uploadAndRenameGoogleDriveFileInNamedFolderFromFS(userId, fsPath, baseFolderId,
folderName, createFolderIfNotExists, fileName, deleteFsFile);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fsPaththe full path of the file to upload. This path is in the server where 4WS.Platform is installed
baseFolderIdthe id of the Drive folder where the named folder must be created
folderNamea name of the folder where the file must be uploaded to. This folder must be in the base folder
createFolderIfNotExiststrue or false. Whether or not to create the folderName folder if not exists in the base folder
fileNamethe new name of the uploaded file. If null the original file name is used
deleteJsFiletrue or false. Specifies if the file on file system must be deleted or not after upload to Drive

Google Drive - replace an already existing Drive file from the server file system​

Upload the specified file stored in the server file system.

Syntax:

var file = utils.updateGoogleDriveFileFromFS(userId, fileId, fsPath, deleteFsFile, newRevision)

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier, related to the already existing file in Drive
fsPaththe full path of the file to upload. This path is in the server where 4WS.Platform is installed
deleteFsFiletrue or false. Specifies if the file on file system must be deleted or not after upload to Drive
newRevisiontrue/false. If true the file will be new version of a possible homonymous file in the destination folder. If false two files with the same name will be present in the destination folder

Google Drive - download a file from Drive​

Download a file from Drive and save it on the server file system.

Syntax:

utils.downloadFileFromGoogleDrive(userId, fileId, localPath, fileName);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier, related to the already existing file in Drive
localPaththe full path on the server file syste, where saving the file
fileNamefileName to use when saving the file on the specified "localPath"

Google Drive - get an URL to download a file from Drive web page​

Get an URL related to the Drive file to download.

Syntax:

var url = utils.getGoogleDriveFileDownloadURL(fileId);

Description:

ArgumentDescription
fileIdfile identifier, related to the already existing file in Drive

Google Drive - get an URL to open a file from GDrive web page​

Returns the URL to open a file from Google Drive. This URL shoud be opened in a browser and must be used for files in Google format (documents, spreadsheets, presentations, forms and so on).

Syntax:

var url = utils.getGoogleDriveFileOpenURL(userId, fileId);

Description:

ArgumentDescription
userIdoptional username; if not specified, the userEmail value set as application property for Google service account will be used as owner for this folder. If this argument is defined, the folder owner will be this user.
fileIdfile identifier, related to the already existing file in Drive