/** * */ package com.braango.virtualdealer; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import com.braango.client.ApiCallback; import com.braango.client.ApiClient; import com.braango.client.ApiException; import com.braango.client.braangoapi.PersonnelsApi; import com.braango.client.braangomodel.HeaderResponse; import com.braango.client.braangomodel.PersonnelOutputWrapper; import com.braango.client.braangomodel.PersonnelRequest; import com.braango.client.braangomodel.PersonnelRequestInput; import com.braango.client.braangomodel.RequestHeader; import com.braango.client.braangomodel.SubDealerBody; import com.braango.client.braangomodel.SubDealerRequestInput; /** * @author braango * * Sample code showing how to create subDealer * */ public class CreatePersonnel { static String basePath = "https://testapi2.braango.com/v2/braango"; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApiClient braangoApiClient = new ApiClient(); String authToken = "ISNWF0P30WM0CMK"; // TEST auth token. Please contact // sales@braango.com to have one // created for you braangoApiClient.setBasePath(basePath); // Set the auth_token for api client to // interact with Braango system braangoApiClient.setApiKey(authToken); // Api key is authorization to to access // resources within braango system // // This key is different than auth_token // that is used to validate the master account String apiKey = "ISNfTMNOumV3xYNDd2g"; // Create personnel api. Personnel is hosted by subDealer PersonnelsApi personnelsApi = new PersonnelsApi(braangoApiClient); ApiCallback callBack = new ApiCallback() { @Override public void onUploadProgress(long bytesWritten, long contentLength, boolean done) { System.out .println("Place holder for tracking request progress"); } @Override public void onSuccess(PersonnelOutputWrapper result, int statusCode, Map> responseHeaders) { UUID salesPersonId = result.getBody().getData().getSalesPersonId(); System.out.println("SUCCESS : SalespersonID = " + salesPersonId.toString()); } @Override public void onFailure(ApiException e, int statusCode, Map> responseHeaders) { System.out.println("Error is " + statusCode + " " + e.getResponseBody()); } @Override public void onDownloadProgress(long bytesRead, long contentLength, boolean done) { } }; // PersonnelRequestInput wraps RequestHeader and personnelRequestBody PersonnelRequestInput personnelRequestInput = new PersonnelRequestInput(); /* * { "api_key": "ISNGvAzwuy4X7vAqrtV", "id": "any value", * "account_type": "partner" } */ RequestHeader hdr = new RequestHeader(); // Set the account type to partner for // virtual dealer and partner hosted // accounts hdr.setAccountType("partner"); // dealer_api_key returned // when partner_dealer was created hdr.setApiKey(apiKey); // ID that will be reflected back hdr.setId("create-personnel-s1002r3"); personnelRequestInput.setHeader(hdr); PersonnelRequest body = new PersonnelRequest(); // REQUIRED FIELDS // Required field . Used for // SMS login in to the UI // For Braango Enterprise, this is don't care // unless partner implements UI with SMS login body.setSmsLogin(false); body.setPersonnelName("personnel rep3"); /* * This is a user name created while signing this personnel up. * Typically this user name can be used to log into the braango UI. * However for whitelabel product, it is expected that this will be used * for single signon with respect to dealer account on partner system. * i.e. it is expected that partner will pass on the same user name that * dealer has on its system to give seamless integration experience. */ body.setUserName("subdealers1002r3"); /* * Password will be encrypted with SHA-25 and base64 encoded and stored * internally within the braango system. pattern: * ^(?=^.{6,10}$)(?=.*\d)( * ?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{" * ;:;'?/>.<,])(?!.*\s).*$ * * Used for single sign on. needs to 6-10 characters with one capital, * one numberal and one special character */ body.setPassword("test1T$"); // OPTIONAL FIELDS // List of banners. Braango will // randomly choose one when sending // message to dealer via SMS // List dealerBanners = new ArrayList(); dealerBanners.add("s1002r3db1"); body.setDealerBanners(dealerBanners); // List of client banners. Braango // will randomly choose one when // sending dealer messages to client List clientBanners = new ArrayList(); clientBanners.add("s1002r3cb1"); body.setClientBanners(clientBanners); // List of supervisor banners. Braango // will randomly choose one when // sending messages to supervisor List supervisorBanners = new ArrayList(); supervisorBanners.add("s1002r3sb1"); body.setSupervisorBanners(supervisorBanners); // List of dealer footers. Braango will // randomly choose one when sending // message to dealer via SMS // List dealerFooters = new ArrayList(); dealerFooters.add("s1002r3df1"); body.setDealerFooters(dealerFooters); // List of client footers. Braango // will randomly choose one when // sending dealer messages to client List clientFooters = new ArrayList(); clientFooters.add("s1002r3cf1"); body.setClientFooters(clientFooters); // List of supervisor footers. Braango // will randomly choose one when // sending messages to supervisor List supervisorFooters = new ArrayList(); supervisorBanners.add("s1002r3sf1"); body.setSupervisorFooters(supervisorFooters); String email = "s1002r3@subdealer1002.com"; body.setEmail(email); // If email specified is that for // CRM email (ADF XML compliant) Boolean typeAdfCRMEmail = false; body.setTypeAdfCrm(typeAdfCRMEmail); /* * Number where personnel can be reached via SMS * for leads * * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$ */ String smsNumber = "4089763435"; body.setSmsNumber(smsNumber); /* * Number where personnel can be reached via voice * for leads * * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$ * */ String phoneNumber = "4089763435"; body.setPhoneNumber(phoneNumber); //Subscribe to the group String group = "s1002grp"; body.setGroup(group); personnelRequestInput.setBody(body); try { String subDealerId = "subdealers1002"; personnelsApi.createPersonnelAsync(subDealerId,personnelRequestInput, callBack); } catch (ApiException e1) { e1.printStackTrace(); } } }