diff --git a/v6/adobesign/api/rest/sample/GetStatusOfAgreements.java b/v6/adobesign/api/rest/sample/GetStatusOfAgreements.java index 1f57fcf..46f03b9 100644 --- a/v6/adobesign/api/rest/sample/GetStatusOfAgreements.java +++ b/v6/adobesign/api/rest/sample/GetStatusOfAgreements.java @@ -61,6 +61,7 @@ private void run() throws Exception { System.out.println("AgreementName: " + agreement.get("name")); System.out.println("AgreementID: " + agreement.get("id")); System.out.println("AgreementStatus: " + agreement.get("status")); + System.out.println("GroupID: " + agreement.get("groupId")); System.out.println(); } } diff --git a/v6/adobesign/api/rest/sample/SendAgreementUsingLibraryDocument.java b/v6/adobesign/api/rest/sample/SendAgreementUsingLibraryDocument.java index 3d9702c..42ef990 100755 --- a/v6/adobesign/api/rest/sample/SendAgreementUsingLibraryDocument.java +++ b/v6/adobesign/api/rest/sample/SendAgreementUsingLibraryDocument.java @@ -14,6 +14,7 @@ import adobesign.api.rest.sample.util.RestApiAgreements; import adobesign.api.rest.sample.util.RestApiLibraryDocuments; import adobesign.api.rest.sample.util.RestApiOAuthTokens; +import adobesign.api.rest.sample.util.RestApiUserGroups; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -58,14 +59,37 @@ private void run() throws Exception { // Fetch oauth access token to make further API calls. String accessToken = RestApiOAuthTokens.getOauthAccessToken(authRequestJSONFileName); + // get all active groups of the user + JSONObject userGroups = RestApiUserGroups.getUserGroups(accessToken); + JSONArray userGroupsList = (JSONArray) userGroups.get("groupInfoList"); + + // select the first group the user can send from + String groupId = null; + for (Object eachUserGroup : userGroupsList) { + JSONObject userGroup = (JSONObject) eachUserGroup; + String groupStatus = (String) userGroup.get("status"); + JSONObject groupSettings = (JSONObject) userGroup.get("settings"); + JSONObject userCanSend = (JSONObject) groupSettings.get("userCanSend"); + Boolean userCanSendValue = (Boolean) userCanSend.get("value"); + if (groupStatus.equals("ACTIVE") && userCanSendValue) { + groupId = userGroup.get("id").toString(); + break; + } + } + + // no group with send permissions was found + if (groupId == null){ + System.err.println("No Group the user can send from"); + return; + } + // Fetch library documents of the user using access token from above. - JSONObject libraryDocumentsResponse = RestApiLibraryDocuments.getLibraryDocuments(accessToken); + JSONObject libraryDocumentsResponse = RestApiLibraryDocuments.getLibraryDocuments(accessToken, groupId); // Retrieve library documents list for the user and fetch the ID of first library document. JSONArray libraryDocumentList = (JSONArray) libraryDocumentsResponse.get("libraryDocumentList"); - + String libraryDocumentId = null; - // Fetch the first personal or shared library document of the user. for (Object eachLibraryDocument : libraryDocumentList) { JSONObject libraryDocument = (JSONObject) eachLibraryDocument; @@ -77,7 +101,7 @@ private void run() throws Exception { if (libraryDocumentId != null && !libraryDocumentId.isEmpty()) { // Send agreement using this library document ID retrieved from above. - JSONObject sendAgreementResponse = RestApiAgreements.sendAgreement(accessToken, sendAgreementJSONFileName, libraryDocumentId, + JSONObject sendAgreementResponse = RestApiAgreements.sendAgreement(accessToken, sendAgreementJSONFileName, libraryDocumentId, groupId, RestApiAgreements.DocumentIdentifierName.LIBRARY_DOCUMENT_ID); // Parse and read response. diff --git a/v6/adobesign/api/rest/sample/SendAgreementUsingTransientDocument.java b/v6/adobesign/api/rest/sample/SendAgreementUsingTransientDocument.java index 35b5a2e..b2cf4bb 100755 --- a/v6/adobesign/api/rest/sample/SendAgreementUsingTransientDocument.java +++ b/v6/adobesign/api/rest/sample/SendAgreementUsingTransientDocument.java @@ -11,6 +11,8 @@ package adobesign.api.rest.sample; +import adobesign.api.rest.sample.util.RestApiUserGroups; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import adobesign.api.rest.sample.util.RestApiAgreements; @@ -79,13 +81,37 @@ private void run() throws Exception { // Fetch oauth access token to make further API calls. String accessToken = RestApiOAuthTokens.getOauthAccessToken(authRequestJSONFileName); + // get all active groups of the user + JSONObject userGroups = RestApiUserGroups.getUserGroups(accessToken); + JSONArray userGroupsList = (JSONArray) userGroups.get("groupInfoList"); + + // select the first group the user can send from + String groupId = null; + for (Object eachUserGroup : userGroupsList) { + JSONObject userGroup = (JSONObject) eachUserGroup; + String groupStatus = (String) userGroup.get("status"); + JSONObject groupSettings = (JSONObject) userGroup.get("settings"); + JSONObject userCanSend = (JSONObject) groupSettings.get("userCanSend"); + Boolean userCanSendValue = (Boolean) userCanSend.get("value"); + if (groupStatus.equals("ACTIVE") && userCanSendValue) { + groupId = userGroup.get("id").toString(); + break; + } + } + + // no group with send permissions was found + if (groupId == null){ + System.err.println("No Group the user can send from"); + return; + } + // Upload a transient document and retrieve transient document ID from the response. JSONObject uploadDocumentResponse = RestApiAgreements.postTransientDocument(accessToken, mimeType, fileToBeUploaded, uploadedFileName); String transientDocumentId = (String) uploadDocumentResponse.get("transientDocumentId"); // Send an agreement using the transient document ID derived from above. DocumentIdentifierName idName = DocumentIdentifierName.TRANSIENT_DOCUMENT_ID; - JSONObject sendAgreementResponse = RestApiAgreements.sendAgreement(accessToken, sendAgreementJSONFileName, transientDocumentId, idName); + JSONObject sendAgreementResponse = RestApiAgreements.sendAgreement(accessToken, sendAgreementJSONFileName, transientDocumentId, groupId, idName); // Parse and read response. System.out.println("Agreement Sent. Agreement ID = " + sendAgreementResponse.get("id")); diff --git a/v6/adobesign/api/rest/sample/util/RestApiAgreements.java b/v6/adobesign/api/rest/sample/util/RestApiAgreements.java index 563fa1c..578014f 100755 --- a/v6/adobesign/api/rest/sample/util/RestApiAgreements.java +++ b/v6/adobesign/api/rest/sample/util/RestApiAgreements.java @@ -34,7 +34,7 @@ public class RestApiAgreements { private static final String TRANSIENT_DOCUMENTS_ENDPOINT = "/transientDocuments"; private static final String FILEINFOS = "fileInfos"; - + private static final String GROUPID = "groupId"; /** * Represents the various ways that a set of documents can be identified, depending on the context. */ @@ -100,6 +100,7 @@ public static JSONObject postTransientDocument(String accessToken, String mimeTy * @param requestJsonFile Name of the file containing the JSON structure used as the input for this API call. * @param documentId Document ID of the document to be associated with the agreement. It can refer to a transient document or a library * document. + * @param groupId The group used to send the agreement. * @param idName Name by which to refer to a list containing document IDs when adding it to the input JSON structure. Must be one of *