Android Open Source - force_analytics_example File Requests






From Project

Back to project page force_analytics_example.

License

The source code is released under:

Copyright (c) 2011, salesforce.com, inc. All rights reserved. ======================================== Redistribution and use of this software in source and binary forms, with or without modificatio...

If you think the Android project force_analytics_example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2013, salesforce.com, inc.
 * All rights reserved.//w w w .ja v a2  s  .  c  o m
 * Redistribution and use of this software in source and binary forms, with or
 * without modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * - Neither the name of salesforce.com, inc. nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission of salesforce.com, inc.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package com.salesforce.androidsdk.rest.files;

import java.io.*;
import java.util.*;

import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.*;
import org.apache.http.entity.mime.content.*;
import org.apache.http.protocol.HTTP;

import android.text.TextUtils;

import com.google.common.collect.Maps;
import com.salesforce.androidsdk.rest.*;
import com.salesforce.androidsdk.rest.RestRequest.RestMethod;

/**
 * This defines the HTTP requests in the connect API for files functionality.
 * 
 * @author sfell
 */
public class FileRequests extends ApiRequests {

    // files i follow
    static final String CONTENT_DOCUMENT_LINK = ApiVersionStrings.BASE_SOBJECT_PATH + "ContentDocumentLink";

    /**
     * Build a Request that can fetch a page from the files owned by the
     * specified user.
     * 
     * @param userId
     *            if null the context user is used, otherwise it should be an Id
     *            of a user.
     * @param pageNum
     *            if null fetches the first page, otherwise fetches the
     *            specified page.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest ownedFilesList(String userId, Integer pageNum) {
        return make(base("users").appendUserId(userId).appendPath("files").appendPageNum(pageNum));
    }

    /**
     * Build a Request that can fetch a page from the list of files from groups
     * that the user is a member of.
     * 
     * @param userId
     *            if null the context user is used, otherwise it should be an Id
     *            of a user.
     * @param pageNum
     *            if null fetches the first page, otherwise fetches the
     *            specified page.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest filesInUsersGroups(String userId, Integer pageNum) {
        return make(base("users").appendUserId(userId).appendPath("files/filter/groups").appendPageNum(pageNum));
    }

    /**
     * Build a Request that can fetch a page from the list of files that have
     * been shared with the user.
     * 
     * @param userId
     *            if null the context user is used, otherwise it should be an Id
     *            of a user.
     * @param pageNum
     *            if null fetches the first page, otherwise fetches the
     *            specified page.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest filesSharedWithUser(String userId, Integer pageNum) {
        return make(base("users").appendUserId(userId).appendPath("files/filter/sharedwithme").appendPageNum(pageNum));
    }

    /**
     * Build a Request that can fetch the file details of a particular version
     * of a file.
     * 
     * @param sfdcId
     *            The Id of the file
     * @param version
     *            if null fetches the most recent version, otherwise fetches
     *            this specific version.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest fileDetails(String sfdcId, String version) {
        validateSfdcId(sfdcId);
        return make(base("files").appendPath(sfdcId).appendVersionNum(version));
    }

    /**
     * Build a request that can fetch the latest file details of one or more
     * files in a single request.
     * 
     * @param sfdcIds
     *            The list of file Ids to fetch.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest batchFileDetails(List<String> sfdcIds) {
        validateSfdcIds(sfdcIds);
        String ids = TextUtils.join(",", sfdcIds);
        return make(base("files").appendPath("batch").appendPath(ids));
    }

    /**
     * Build a Request that can fetch the a preview/rendition of a particular
     * page of the file (and version)
     * 
     * @param sfdcId
     *            The Id of the file
     * @param version
     *            if null fetches the most recent version, otherwise fetches
     *            this specific version
     * @param renditionType
     *            What format of rendition do you want to get
     * @param pageNum
     *            which page to fetch, pages start at 0.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest fileRendition(String sfdcId, String version, RenditionType renditionType, Integer pageNum) {
        validateSfdcId(sfdcId);
        if (renditionType == null) {
            throw new NullPointerException("rendition type can't be null");
        }
        return make(base("files").appendPath(sfdcId).appendPath("rendition")
                .appendQueryParam("type", renditionType.toString()).appendVersionNum(version).appendPageNum(pageNum));
    }

    /**
     * Builds a request that can fetch the actual binary file contents of this
     * particular file.
     * 
     * @param sfdcId
     *            The Id of the file
     * @param version
     *            The version of the file
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest fileContents(String sfdcId, String version) {
        validateSfdcId(sfdcId);
        return make(base("files").appendPath(sfdcId).appendPath("content").appendVersionNum(version));
    }

    /**
     * Build a Request that can fetch a page from the list of entities that this
     * file is shared to.
     * 
     * @param sfdcId
     *            The Id of the file.
     * @param pageNum
     *            if null fetches the first page, otherwise fetches the
     *            specified page.
     * @return A new RestRequest that can be used to fetch this data
     */
    public static RestRequest fileShares(String sfdcId, Integer pageNum) {
        validateSfdcId(sfdcId);
        return make(base("files").appendPath(sfdcId).appendPath("file-shares").appendPageNum(pageNum));
    }

    /**
     * Build a request that will add a file share for the specified fileId to
     * the specified entityId
     * 
     * @param fileId
     *            the Id of the file being shared.
     * @param entityId
     *            the Id of the entity to share the file to (e.g. a user or a
     *            group)
     * @param shareType
     *            the type of share (V - View, C - Collaboration)
     * 
     * @return A new RestRequest that be used to create this share.
     */
    public static RestRequest addFileShare(String fileId, String entityId, String shareType) {
        validateSfdcIds(fileId, entityId);
        return new RestRequest(RestMethod.POST, CONTENT_DOCUMENT_LINK, makeFileShare(fileId, entityId, shareType));
    }

    /**
     * Build a request that will delete the specified file share.
     * 
     * @param shareId
     *            The Id of the file share record (aka ContentDocumentLink)
     * 
     * @return
     */
    public static RestRequest deleteFileShare(String shareId) {
        validateSfdcId(shareId);
        return new RestRequest(RestMethod.DELETE, CONTENT_DOCUMENT_LINK + "/" + shareId, null);
    }

    private static HttpEntity makeFileShare(String fileId, String entityId, String shareType) {
        Map<String, String> share = Maps.newHashMap();
        share.put("ContentDocumentId", fileId);
        share.put("LinkedEntityId", entityId);
        share.put("ShareType", shareType);
        try {
            String json = null; // FIXME ConnectParser.toJson(share);
            StringEntity e = new StringEntity(json, HTTP.UTF_8);
            e.setContentType("application/json");
            return e;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Build a request that can upload a new file to the server, this will
     * create a new file at version 1.
     * 
     * @param theFile
     *            The path of the local file to upload to the server.
     * @param name
     *            The name/title of this file.
     * @param description
     *            A description of the file.
     * @param mimeType
     *            The mime-type of the file, if known.
     * @return A RestRequest that can perform this upload.
     * 
     * @throws UnsupportedEncodingException
     */
    public static RestRequest uploadFile(File theFile, String name, String description, String mimeType) throws UnsupportedEncodingException {
        MultipartEntity mpe = new MultipartEntity(HttpMultipartMode.STRICT);
        FileBody bin = mimeType == null ? new FileBody(theFile) : new FileBody(theFile, mimeType);
        if (name != null)
            mpe.addPart("title", new StringBody(name));
        if (description != null)
            mpe.addPart("desc", new StringBody(description));
        mpe.addPart("fileData", bin);
        return new RestRequest(RestMethod.POST, base("users").appendPath("me/files").toString(), mpe, HTTP_HEADERS);
    }
}




Java Source Code List

com.salesforce.androidsdk.accounts.UserAccountManagerWithSmartStore.java
com.salesforce.androidsdk.accounts.UserAccountManager.java
com.salesforce.androidsdk.accounts.UserAccount.java
com.salesforce.androidsdk.app.SalesforceSDKManager.java
com.salesforce.androidsdk.app.UUIDManager.java
com.salesforce.androidsdk.app.UpgradeManager.java
com.salesforce.androidsdk.auth.AccountWatcher.java
com.salesforce.androidsdk.auth.AuthenticatorService.java
com.salesforce.androidsdk.auth.HttpAccess.java
com.salesforce.androidsdk.auth.LoginServerManager.java
com.salesforce.androidsdk.auth.OAuth2.java
com.salesforce.androidsdk.phonegap.ForcePlugin.java
com.salesforce.androidsdk.phonegap.JavaScriptPluginVersion.java
com.salesforce.androidsdk.phonegap.SDKInfoPlugin.java
com.salesforce.androidsdk.phonegap.SFAccountManagerPlugin.java
com.salesforce.androidsdk.phonegap.SalesforceOAuthPlugin.java
com.salesforce.androidsdk.phonegap.TestRunnerPlugin.java
com.salesforce.androidsdk.push.PushBroadcastReceiver.java
com.salesforce.androidsdk.push.PushMessaging.java
com.salesforce.androidsdk.push.PushNotificationInterface.java
com.salesforce.androidsdk.push.PushService.java
com.salesforce.androidsdk.rest.AdminPrefsManager.java
com.salesforce.androidsdk.rest.ApiVersionStrings.java
com.salesforce.androidsdk.rest.BootConfig.java
com.salesforce.androidsdk.rest.ClientManager.java
com.salesforce.androidsdk.rest.RestClient.java
com.salesforce.androidsdk.rest.RestRequest.java
com.salesforce.androidsdk.rest.RestResponse.java
com.salesforce.androidsdk.rest.files.ApiRequests.java
com.salesforce.androidsdk.rest.files.ConnectUriBuilder.java
com.salesforce.androidsdk.rest.files.FileRequests.java
com.salesforce.androidsdk.rest.files.RenditionType.java
com.salesforce.androidsdk.security.Encryptor.java
com.salesforce.androidsdk.security.PRNGFixes.java
com.salesforce.androidsdk.security.PasscodeManager.java
com.salesforce.androidsdk.smartstore.app.SalesforceSDKManagerWithSmartStore.java
com.salesforce.androidsdk.smartstore.app.UpgradeManagerWithSmartStore.java
com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.java
com.salesforce.androidsdk.smartstore.phonegap.StoreCursor.java
com.salesforce.androidsdk.smartstore.store.DBHelper.java
com.salesforce.androidsdk.smartstore.store.DBOpenHelper.java
com.salesforce.androidsdk.smartstore.store.IndexSpec.java
com.salesforce.androidsdk.smartstore.store.QuerySpec.java
com.salesforce.androidsdk.smartstore.store.SmartSqlHelper.java
com.salesforce.androidsdk.smartstore.store.SmartStore.java
com.salesforce.androidsdk.ui.AccountSwitcherActivity.java
com.salesforce.androidsdk.ui.CustomServerUrlEditor.java
com.salesforce.androidsdk.ui.LoginActivity.java
com.salesforce.androidsdk.ui.ManageSpaceActivity.java
com.salesforce.androidsdk.ui.OAuthWebviewHelper.java
com.salesforce.androidsdk.ui.PasscodeActivity.java
com.salesforce.androidsdk.ui.SalesforceAccountRadioButton.java
com.salesforce.androidsdk.ui.SalesforceR.java
com.salesforce.androidsdk.ui.SalesforceServerRadioButton.java
com.salesforce.androidsdk.ui.ServerPickerActivity.java
com.salesforce.androidsdk.ui.sfhybrid.SalesforceDroidGapActivity.java
com.salesforce.androidsdk.ui.sfhybrid.SalesforceGapViewClient.java
com.salesforce.androidsdk.ui.sfnative.SalesforceActivity.java
com.salesforce.androidsdk.ui.sfnative.SalesforceExpandableListActivity.java
com.salesforce.androidsdk.ui.sfnative.SalesforceListActivity.java
com.salesforce.androidsdk.util.EventsListenerQueue.java
com.salesforce.androidsdk.util.EventsObservable.java
com.salesforce.androidsdk.util.EventsObserver.java
com.salesforce.androidsdk.util.ForceAppInstrumentationTestCase.java
com.salesforce.androidsdk.util.HybridInstrumentationTestCase.java
com.salesforce.androidsdk.util.JSTestCase.java
com.salesforce.androidsdk.util.JUnitReportTestRunner.java
com.salesforce.androidsdk.util.LogUtil.java
com.salesforce.androidsdk.util.NativeInstrumentationTestCase.java
com.salesforce.androidsdk.util.TimeLimitedTestRunner.java
com.salesforce.androidsdk.util.TokenRevocationReceiver.java
com.salesforce.androidsdk.util.UriFragmentParser.java
com.salesforce.androidsdk.util.UserSwitchReceiver.java
com.salesforce.samples.accounteditor.AccountEditorApp.java
com.salesforce.samples.accounteditor.KeyImpl.java
com.salesforce.samples.analyticsapp.AnalyticsApp.java
com.salesforce.samples.analyticsapp.GraphActivity.java
com.salesforce.samples.analyticsapp.KeyImpl.java
com.salesforce.samples.analyticsapp.MainActivity.java
com.salesforce.samples.analyticsapp.PieChart.java
com.salesforce.samples.contactexplorer.ContactExplorerApp.java
com.salesforce.samples.contactexplorer.KeyImpl.java
com.salesforce.samples.hybridfileexplorer.HybridFileExplorerApp.java
com.salesforce.samples.hybridfileexplorer.KeyImpl.java
com.salesforce.samples.smartstoreexplorer.KeyImpl.java
com.salesforce.samples.smartstoreexplorer.SmartStoreExplorerApp.java
com.salesforce.samples.vfconnector.KeyImpl.java
com.salesforce.samples.vfconnector.VFConnectorApp.java