Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java ize2 #39

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Introducing GoogleAppsException and thus removing the API-level depen…
…dency on old-core.

Paul
polx committed Dec 18, 2019

Verified

This commit was signed with the committer’s verified signature.
Cliffzz Kevin Clifford
commit a5a69382ef5d8946f3b83605b3fd82bd967fb5ec
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.apps.googleapps;

import java.io.IOException;

import org.xwiki.stability.Unstable;

import com.xpn.xwiki.XWikiException;

/**
* Generic class to denote an exception condition within the GoogleApps code. Wraps XWikiException and IOException.
*
* @version $Id$
* @since 3.0
*/
public class GoogleAppsException extends RuntimeException
{

private static final long serialVersionUID = 3000;
/**
* @param msg Message to denote the error for programmers.
* @param wrapped Exception that has caused this one.
*
* @since 3.0
*/
public GoogleAppsException(String msg, Exception wrapped)
{
super(msg, wrapped);
}

/**
*
* @param msg Message to denote the error for programmers.
*
* @since 3.0
*/
public GoogleAppsException(String msg)
{
super(msg);
}

/**
*
* @param wrapped Exception that has caused this one.
*
* @since 3.0
*/
public GoogleAppsException(Exception wrapped)
{
super(wrapped);
}

/**
*
* @return true if the wrapped exception of XWiki origin.
* @since 3.0
*/
@Unstable
public boolean isWikiException()
{
return super.getCause() instanceof XWikiException;
}

/**
*
* @return true if the wrapped exception of Google origin (for now: any IO-related exception).
* @since 3.0
*/
@Unstable
public boolean isGoogleCommException()
{
return super.getCause() instanceof IOException;
}
}
63 changes: 31 additions & 32 deletions api/src/main/java/org/xwiki/apps/googleapps/GoogleAppsManager.java
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
*/
package org.xwiki.apps.googleapps;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -30,7 +29,6 @@
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.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;

@@ -46,11 +44,11 @@ public interface GoogleAppsManager
{
/**
* @return if the application is licensed and activated
* @throws XWikiException in case a context cannot be read from thread.
* @throws GoogleAppsException in case a context cannot be read from thread.
* @since 3.0
*/
@Unstable
boolean isActive() throws XWikiException;
boolean isActive() throws GoogleAppsException;

/**
* @return if the app is configured to use the Google Drive integration (default: yes).
@@ -67,36 +65,43 @@ public interface GoogleAppsManager
int getConfigCookiesTTL();

/**
* Reads the manifest to find when the JAR file was assembled by maven.
* 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 XWikiException if the interaction with xwiki failed
* @throws IOException if a communication problem to Google services occured
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Credential authorize() throws XWikiException, IOException;
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
* @throws XWikiException if the interaction with xwiki failed
* @throws IOException if a communication problem to Google services occured
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Credential authorize(boolean redirect) throws XWikiException, IOException;
Credential authorize(boolean redirect) throws GoogleAppsException;

/**
* Performs the necessary communication with Google-Services to fetch identity and update the XWiki-user object or
@@ -112,38 +117,35 @@ public interface GoogleAppsManager
* Get the list of all documents in the user's associated account.
*
* @return A list of max 10 documents.
* @throws XWikiException if an authorization process failed.
* @throws IOException if a communication process to Google services occurred.
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
List<File> getDocumentList() throws XWikiException, IOException;
List<File> getDocumentList() throws GoogleAppsException;

/**
* Fetches a list of Google Drive document matching a substring query in the filename.
*
* @param query the expected query (e.g. fullText contains winter ski)
* @param nbResults max number of results
* @return The list of files at Google Drive.
* @throws XWikiException if an XWiki issue occurs
* @throws IOException if an error interacting with Google services occurred
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
List<File> listDriveDocumentsWithTypes(String query, int nbResults) throws XWikiException, IOException;
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 XWikiException if an XWiki issue occurs
* @throws IOException if an error interacting with Google services occurred
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
FileList listDocuments(String query, int nbResults) throws XWikiException, IOException;
FileList listDocuments(String query, int nbResults) throws GoogleAppsException;

/**
* Fetches the google-drive document's representation and stores it as attachment.
@@ -153,24 +155,23 @@ public interface GoogleAppsManager
* @param id store object attached to this attachment using this id (for later sync)
* @param url fetch from this URL
* @return true if successful
* @throws XWikiException if an issue occurred in XWiki
* @throws IOException if an issue occurred in the communication with teh Google services
* @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 XWikiException, IOException;
boolean retrieveFileFromGoogle(String page, String name, String id, String url) throws GoogleAppsException;

/**
* Extracts metadata about the Google Drive document corresponding to the named attachment.
*
* @param pageName The XWiki page where the attachment is
* @param fileName The filename of the attachment
* @return information about the corresponding Google Drive document
* @throws XWikiException if something happened at XWiki side
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
DriveDocMetadata getGoogleDocument(String pageName, String fileName) throws XWikiException;
DriveDocMetadata getGoogleDocument(String pageName, String fileName) throws GoogleAppsException;

/**
* Reads the extension and document name.
@@ -191,12 +192,11 @@ public interface GoogleAppsManager
* @param obj the XWiki object where this embedding is to be updated (or null if it is to be created)
* @param nb the number of the embedding across all the page's embeddings
* @return the created or actualized document
* @throws IOException If the communication with Google went wrong
* @throws XWikiException If something at the XWiki side went wrong (e.g. saving)
* @throws GoogleAppsException if a communication problem with the other components occured
*/
@Unstable
public BaseObject createOrUpdateEmbedObject(String docId, XWikiDocument doc, BaseObject obj, int nb)
throws IOException, XWikiException;
BaseObject createOrUpdateEmbedObject(String docId, XWikiDocument doc, BaseObject obj, int nb)
throws GoogleAppsException;

/**
* Saves the attachment stored in XWiki to the Google drive of the user attached to the current logged-in user.
@@ -205,12 +205,11 @@ public BaseObject createOrUpdateEmbedObject(String docId, XWikiDocument doc, Bas
* @param name the attachment name
* @return a record with the keys fileName, exportLink, version, editLink, embedLink, and google-user's
* email-address
* @throws XWikiException if something went wrong at the XWiki side
* @throws IOException if something went wrong int he communication with Google drive.
* @throws GoogleAppsException if a communication problem with the other components occured
* @since 3.0
*/
@Unstable
Map<String, Object> saveAttachmentToGoogle(String page, String name) throws XWikiException, IOException;
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.
Loading