use of com.salesforce.androidsdk.rest.RestRequest in project SalesforceMobileSDK-Android by forcedotcom.
the class ContentSoqlSyncDownTarget method buildSoapRequest.
/**
* @param sessionId
* @param body
* @return request for soap call
* @throws UnsupportedEncodingException
*/
private RestRequest buildSoapRequest(String sessionId, String body) throws UnsupportedEncodingException {
Map<String, String> customHeaders = new HashMap<String, String>();
customHeaders.put("SOAPAction", "\"\"");
RequestBody requestBody = RequestBody.create(MEDIA_TYPE_XML, String.format(REQUEST_TEMPLATE, sessionId, body));
String version = ApiVersionStrings.getVersionNumber(SalesforceSDKManager.getInstance().getAppContext()).substring(1);
/* no v */
;
return new RestRequest(RestRequest.RestMethod.POST, "/services/Soap/u/" + version, requestBody, customHeaders);
}
use of com.salesforce.androidsdk.rest.RestRequest in project SalesforceMobileSDK-Android by forcedotcom.
the class ParentChildrenSyncTestCase method createAccountsAndContactsOnServer.
protected void createAccountsAndContactsOnServer(int numberAccounts, int numberContactsPerAccount) throws Exception {
accountIdToFields = new HashMap<>();
accountIdContactIdToFields = new HashMap<>();
Map<String, Map<String, Object>> refIdToFields = new HashMap<>();
List<RestRequest.SObjectTree> accountTrees = new ArrayList<>();
List<Map<String, Object>> listAccountFields = buildFieldsMapForRecords(numberAccounts, Constants.ACCOUNT, null);
for (int i = 0; i < listAccountFields.size(); i++) {
List<Map<String, Object>> listContactFields = buildFieldsMapForRecords(numberContactsPerAccount, Constants.CONTACT, null);
String refIdAccount = "refAccount_" + i;
Map<String, Object> accountFields = listAccountFields.get(i);
refIdToFields.put(refIdAccount, accountFields);
List<RestRequest.SObjectTree> contactTrees = new ArrayList<>();
for (int j = 0; j < listContactFields.size(); j++) {
String refIdContact = refIdAccount + ":refContact_" + j;
Map<String, Object> contactFields = listContactFields.get(j);
refIdToFields.put(refIdContact, contactFields);
contactTrees.add(new RestRequest.SObjectTree(Constants.CONTACT, Constants.CONTACTS, refIdContact, contactFields, null));
}
accountTrees.add(new RestRequest.SObjectTree(Constants.ACCOUNT, null, refIdAccount, accountFields, contactTrees));
}
RestRequest request = RestRequest.getRequestForSObjectTree(apiVersion, Constants.ACCOUNT, accountTrees);
// Send request
RestResponse response = restClient.sendSync(request);
// Parse response
Map<String, String> refIdToId = new HashMap<>();
JSONArray results = response.asJSONObject().getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject result = results.getJSONObject(i);
String refId = result.getString(RestRequest.REFERENCE_ID);
String id = result.getString(Constants.LID);
refIdToId.put(refId, id);
}
// Populate accountIdToFields and accountIdContactIdToFields
for (String refId : refIdToId.keySet()) {
Map<String, Object> fields = refIdToFields.get(refId);
String[] parts = refId.split(":");
String accountId = refIdToId.get(parts[0]);
String contactId = parts.length > 1 ? refIdToId.get(refId) : null;
if (contactId == null) {
accountIdToFields.put(accountId, fields);
} else {
if (!accountIdContactIdToFields.containsKey(accountId))
accountIdContactIdToFields.put(accountId, new HashMap<String, Map<String, Object>>());
accountIdContactIdToFields.get(accountId).put(contactId, fields);
}
}
}
use of com.salesforce.androidsdk.rest.RestRequest in project SalesforceMobileSDK-Android by forcedotcom.
the class SyncManagerTestCase method checkServerDeleted.
/**
* Check that records were deleted from server
* @param ids
* @param sObjectType
* @throws IOException
*/
protected void checkServerDeleted(String[] ids, String sObjectType) throws IOException, JSONException {
String soql = String.format("SELECT %s FROM %s WHERE %s IN %s", Constants.ID, sObjectType, Constants.ID, makeInClause(ids));
RestRequest request = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(targetContext), soql);
RestResponse response = restClient.sendSync(request);
JSONArray records = response.asJSONObject().getJSONArray(RECORDS);
Assert.assertEquals("No accounts should have been returned from server", 0, records.length());
}
use of com.salesforce.androidsdk.rest.RestRequest in project SalesforceMobileSDK-Android by forcedotcom.
the class FileRequests method uploadFile.
/**
* 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 of this file.
* @param title The 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.
*/
public static RestRequest uploadFile(File theFile, String name, String title, String description, String mimeType) {
MediaType mediaType = MediaType.parse(mimeType);
MultipartBody.Builder builder = new MultipartBody.Builder();
if (title != null)
builder.addFormDataPart("title", title);
if (description != null)
builder.addFormDataPart("desc", description);
builder.addFormDataPart("fileData", name, RequestBody.create(mediaType, theFile));
return new RestRequest(RestMethod.POST, base("connect/files/users").appendPath("me").toString(), builder.build(), HTTP_HEADERS);
}
use of com.salesforce.androidsdk.rest.RestRequest in project SalesforceMobileSDK-Android by forcedotcom.
the class ExplorerActivity method onAddFileShareClick.
/**
* Called when the "add file share" button is clicked.
*
* @param v View that was clicked.
*/
public void onAddFileShareClick(View v) {
final String documentId = ((EditText) findViewById(R.id.add_file_share_document_id_text)).getText().toString();
final String entityId = ((EditText) findViewById(R.id.add_file_share_entity_id_text)).getText().toString();
final String shareType = ((EditText) findViewById(R.id.add_file_share_share_type_text)).getText().toString();
RestRequest request = FileRequests.addFileShare(documentId, entityId, shareType);
sendRequest(request);
}
Aggregations