Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ nbproject
*.log.*
*.log
.sonar-ide.properties
.clover
.clover
.DS_Store

24 changes: 6 additions & 18 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>application-googleapps-api</artifactId>
<version>3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Google Apps Integration (API)</name>
<description>This is the XWiki-API part of the Google Apps which allows to connect Google Apps to XWiki.</description>
Expand All @@ -42,11 +41,6 @@
<artifactId>google-api-client</artifactId>
<version>1.24.1</version>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-people</artifactId>
Expand All @@ -57,17 +51,11 @@
<artifactId>google-api-services-drive</artifactId>
<version>v2-rev358-1.24.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
Comment thread
polx marked this conversation as resolved.
Outdated
<scope>compile</scope>
Comment thread
mflorea marked this conversation as resolved.
Outdated
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>

</project>
156 changes: 156 additions & 0 deletions api/src/main/java/com/xwiki/googleapps/DriveDocMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package com.xwiki.googleapps;

import java.util.LinkedList;
import java.util.List;

import org.xwiki.stability.Unstable;

/**
Expand All @@ -44,4 +47,157 @@ public class DriveDocMetadata
* URL to pull from in order to fetch the document.
*/
public String exportLink;

/**
* URL to use to show an embedded view.
*/
public String embedLink;

/**
* A stringified version number.
*/
public String version;

/**
* The name of the file in case it is an uploaded file.
*/
public String fileName;

/**
* The email-address of the user with which this document's connection was created.
*/
public String user;

/**
* A list of export possibilities.
*/
public List<ExportAlternative> exportLinksAlternatives = new LinkedList<>();
Comment thread
polx marked this conversation as resolved.
Outdated

/**
* @return the internal Google Id of the document.
*/
public String getId()
{
return id;
}

/**
* @return the version number
*/
public String getVersion()
{
return version;
}

/**
* @return the URL to direct the user to for editing.
*/
public String getEditLink()
{
return editLink;
}

/**
* @return the URL to pull from in order to fetch the document.
*/
public String getExportLink()
{
return exportLink;
}

/**
* @return a list of export alternatives.
*/
public List<ExportAlternative> getExportLinksAlternatives()
{
return exportLinksAlternatives;
}

/**
* Insert one of the possible export alternative's info.
*
* @param extension understood the file type.
Comment thread
polx marked this conversation as resolved.
Outdated
* @param newFileName the filename when this file is stored on a desktop with this type
* @param exportUrl the url to pull from.
*/
public void addExportAlternative(String extension, String newFileName, String exportUrl)
{
ExportAlternative ea = new ExportAlternative();
ea.extension = extension;
ea.exportUrl = exportUrl;
ea.newFileName = newFileName;
if (ea.newFileName == null) {
ea.newFileName = "unnamed";
}
exportLinksAlternatives.add(ea);
}

/**
* @return the name of the file in case it is an uploaded file.
*/
public String getFileName()
{
return fileName;
}

/**
* @return the same as {#getFileName}.
*/
public String getTitle()
{
return fileName;
}

/**
* @return a useful string representation
*/
public String toString()
{
return "id " + id + " edit: " + editLink + " export " + exportLink;
}

/**
* A class to denote export possibilities of a drive file.
*/
public static class ExportAlternative
{
/**
* a short nickname of the file type, typically the file-ending.
*/
public String extension;

/**
* the revised filename if exported to this extension.
*/
public String newFileName;

/**
* the URL to pull from.
*/
public String exportUrl;

/**
* @return a short nickname of the file type, typically the file-ending.
*/
public String getExtension()
Comment thread
polx marked this conversation as resolved.
{
return extension;
}

/**
* @return the revised filename if exported to this extension.
*/
public String getNewFileName()
{
return newFileName;
}

/**
* @return the URL to pull from.
*/
public String getExportUrl()
{
return exportUrl;
}
}
}
100 changes: 12 additions & 88 deletions api/src/main/java/com/xwiki/googleapps/GoogleAppsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
*/
package com.xwiki.googleapps;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;

Expand Down Expand Up @@ -64,44 +59,16 @@ public interface GoogleAppsManager
@Unstable
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to the interface.

int getConfigCookiesTTL();

/**
* Finds when the JAR file was assembled by maven.
*
* @return the build date.
* @since 3.0
*/
@Unstable
Date getBuildTime();

/**
* Finds the version of the JAR file.
*
* @return the build version.
* @since 3.0
*/
@Unstable
String getBuildVersion();

/**
* Inspects the stored information to see if an authorization or a redirect needs to be pronounced.
*
* @return found credential
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Credential authorize() throws GoogleAppsException;

/**
* Inspects the stored information to see if an authorization or a redirect needs to be pronounced.
*
* @param redirect If a redirect can be done
* @return found credential
* @return if found a credential
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Credential authorize(boolean redirect) throws GoogleAppsException;
boolean authorize(boolean redirect) throws GoogleAppsException;

/**
* Performs the necessary communication with Google-Services to fetch identity and update the XWiki-user object or
Expand All @@ -113,16 +80,6 @@ public interface GoogleAppsManager
@Unstable
String updateUser();

/**
* Get the list of all documents in the user's associated account.
*
* @return A list of max 10 documents.
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
List<File> getDocumentList() throws GoogleAppsException;

/**
* Fetches a list of Google Drive document matching a substring query in the filename.
*
Expand All @@ -133,33 +90,21 @@ public interface GoogleAppsManager
* @since 3.0
*/
@Unstable
List<File> listDriveDocumentsWithTypes(String query, int nbResults) throws GoogleAppsException;

/**
* Fetches a list of Google Drive document matching a given query.
*
* @param query the expected filename substring
* @param nbResults max number of results
* @return The list of files at Google Drive.
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
FileList listDocuments(String query, int nbResults) throws GoogleAppsException;
List<DriveDocMetadata> listDriveDocuments(String query, int nbResults) throws GoogleAppsException;

/**
* Fetches the google-drive document's representation and stores it as attachment.
*
* @param page attach to this page
* @param name attach using this file name
* @param id store object attached to this attachment using this id (for later sync)
* @param url fetch from this URL
* @return true if successful
* @param page attach to this page
* @param name attach using this file name
* @param id store object attached to this attachment using this id (for later sync)
* @param mediaType content-type of the file to be fetched (or "unknown"; in this case the mediaType is read from
* Tika.
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
boolean retrieveFileFromGoogle(String page, String name, String id, String url) throws GoogleAppsException;
void retrieveFileFromGoogle(String page, String name, String id, String mediaType) throws GoogleAppsException;

/**
* Extracts metadata about the Google Drive document corresponding to the named attachment.
Expand All @@ -171,18 +116,8 @@ public interface GoogleAppsManager
* @since 3.0
*/
@Unstable
DriveDocMetadata getGoogleDocument(String pageName, String fileName) throws GoogleAppsException;
DriveDocMetadata getSyncDocMetadata(String pageName, String fileName) throws GoogleAppsException;

/**
* Reads the extension and document name.
*
* @param docName the raw docName
* @param elink the link where to read the extension name
* @return an array with extension and simplified document name
* @since 3.0
*/
@Unstable
String[] getExportLink(String docName, String elink);

/**
* Inserts the current information on the document to be embedded.
Expand All @@ -204,21 +139,10 @@ BaseObject createOrUpdateEmbedObject(String docId, XWikiDocument doc, BaseObject
*
* @param page the XWiki page name
* @param name the attachment name
* @return a record with the keys fileName, exportLink, version, editLink, embedLink, and google-user's
* email-address
* @return a metadata about the file
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Map<String, Object> saveAttachmentToGoogle(String page, String name) throws GoogleAppsException;

/**
* Reads the google user-info attached to the current user as stored in the request.
*
* @return the google user-info with keys displayName, emails (array of type,value pairs), etag, id, image (map with
* keys isDefault and url), kind, language, name (map with keys familyName and givenName).
* @since 3.0
*/
@Unstable
Map<String, Object> getGoogleUser();
DriveDocMetadata saveAttachmentToGoogle(String page, String name) throws GoogleAppsException;
}
Loading