AdapterAgent extends ScheduleAgent implements AdapterAgentInterface { public Object updateAdapter(@Name("accoutId") String accountId, @Name("adapterId") String adapterId, @Name("adapter") Adapter adapter) throws Exception { RestResponse adapterResponse = getAdapter(accountId, adapterId); AdapterConfig config = null; if(adapterResponse.getCode() == javax.ws.rs.core.Response.Status.OK.getStatusCode()) { config = adapterResponse.getResult(AdapterConfig.class); } if (config != null) { if (adapter.getInitialAgentURL() != null) { config.setInitialAgentURL(adapter.getInitialAgentURL()); } if (adapter.isAnonymous() != null) { config.setAnonymous(adapter.isAnonymous()); } if (adapter.getStatus() != null) { log.warning(String.format(" *** Updating status of adapter: %s with id: %s from: %s to: %s ***", config.getMyAddress(), config.getConfigId(), config.getStatus(), adapter.getStatus())); config.setStatus(Status.fromJson(adapter.getStatus())); } if (adapter.getDialogId() != null) { if(accountId.equals(config.getOwner())) { config.setDialogId(adapter.getDialogId()); } else { throw new Exception(String.format("Account: %s does not own adapter: %s with address: %s", accountId, config.getConfigId(), config.getAddress())); } } if (adapter.getAccountType() != null) { config.setAccountType(adapter.getAccountType()); } if(adapter.isPrivate()) { config.markAsPrivate(); } if (config.getAdapterType() != null) { AdapterType adapterType = AdapterType.fromJson(config.getAdapterType()); switch (adapterType) { case EMAIL: case PUSH: case USSD: if (adapter.getMyAddress() != null) { config.setMyAddress(adapter.getMyAddress()); } break; case SMS: if (adapter.getKeyword() != null) { config.setKeyword(adapter.getKeyword()); } if (adapter.getMyAddress() != null && accountId.equalsIgnoreCase(config.getOwner())) { config.setMyAddress(adapter.getMyAddress()); } break; default: } } config.update(); return config; } else { throw new Exception(String.format("Adapter: %s with address:%s probably does not belong to account: %s", adapter, adapter.getMyAddress(), accountId)); } }  void startAllInboundSceduler(); void stopAllInboundSceduler(); String startEmailInboundSceduler(); ScheduledTask getEmailInboundScedulerDetails(); String stopEmailInboundSceduler(); String startTwitterInboundSceduler(); String stopTwitterInboundSceduler(); ScheduledTask getTwitterInboundScedulerDetails(); void checkInBoundEmails(); void checkInBoundTwitterPosts(); RestResponse createComsysAdapter(@Name("address") String address,
        @Name("username") @Optional String username,@Name("password") @Optional String password, 
        @Name("preferredLanguage") @Optional String preferredLanguage,
        @Name("accountId") @Optional String accountId, @Name("anonymous") boolean anonymous,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); RestResponse createBroadSoftAdapter(@Name("username") @Optional String username,
        @Name("password") @Optional String password, @Name("preferredLanguage") @Optional String preferredLanguage,
        @Name("accountId") @Optional String accountId, @Name("anonymous") boolean anonymous,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); Map<String, String> createMultipleTwilioAdapters(@Name("accountSid") String accountSid,
        @Name("authToken") String authToken, @Name("count") Integer count, @Name("countryCode") String countryCode,
        @Name("contains") @Optional String contains, @Name("preferredLanguage") @Optional String preferredLanguage,
        @Name("accountId") @Optional String accountId, @Name("anonymous") @Optional Boolean anonymous,
        @Name("isPrivate") @Optional Boolean isPrivate); String createTwilioAdapter(@Name("address") String address, @Name("accountSid") String accountSid,
        @Name("authToken") String authToken, @Name("preferredLanguage") @Optional String preferredLanguage,
        @Name("accountId") @Optional String accountId, @Name("anonymous") @Optional Boolean anonymous,
        @Name("isPrivate") @Optional Boolean isPrivate); ArrayNode moveTwilioAdaptersToSubAccount(@Name("accountId") String accountId, @Name("accountSid") String accountSid,
                                                   @Name("authToken") String authToken); String moveTwilioAdapterToSubAccount(@Name("adapterId") String adapterId, @Name("accountSid") String accountSid,
        @Name("authToken") String authToken); String moveTwilioAdapterToMainAccount(@Name("adapterId") String adapterId, @Name("accountSid") String accountSid,
                                                @Name("authToken") String authToken); String createThinkingPhonesAdapter(@Name("address") String address, 
                                              @Name("tenantKey") String tenantKey, @Name("token") String token, 
                                              @Name("preferredLanguage") @Optional String preferredLanguage, 
                                              @Name("accountId") @Optional String accountId,
                                              @Name("isPrivate") @Optional Boolean isPrivate); String createEmailAdapter(@Name("emailAddress") String emailAddress, @Name("password") String password,
        @Name("name") @Optional String name, @Name("preferredLanguage") @Optional String preferredLanguage,
        @Name("sendingProtocol") @Optional String sendingProtocol, @Name("sendingHost") @Optional String sendingHost,
        @Name("sendingPort") @Optional String sendingPort,
        @Name("receivingProtocol") @Optional String receivingProtocol,
        @Name("receivingHost") @Optional String receivingHost, @Name("accountId") @Optional String accountId,
        @Name("initialAgentURL") @Optional String initialAgentURL, @Name("accountType") @Optional String accountType,
        @Name("isPrivate") @Optional Boolean isPrivate); String createXMPPAdapter(@Name("xmppAddress") String xmppAddress, @Name("password") String password,
                                    @Name("name") @Optional String name,
                                    @Name("preferredLanguage") @Optional String preferredLanguage,
                                    @Name("host") @Optional String host, @Name("port") @Optional String port,
                                    @Name("service") @Optional String service,
                                    @Name("accountId") @Optional String accountId,
                                    @Name("initialAgentURL") @Optional String initialAgentURL,
                                    @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); String createUSSDAdapter(@Name("address") String address, @Name("keyword") @Optional String keyword,
        @Name("username") String username, @Name("password") String password,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); String createPushAdapter(@Name("address") String address, @Name("keyword") @Optional String keyword,
        @Name("username") String username, @Name("password") String password,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); String registerASKFastXMPPAdapter(@Name("xmppAddress") String xmppAddress,
        @Name("password") String password, @Name("name") @Optional String name, @Name("email") @Optional String email,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("initialAgentURL") @Optional String initialAgentURL, @Name("accountType") @Optional String accountType,
        @Name("isPrivate") @Optional Boolean isPrivate); String deregisterASKFastXMPPAdapter(@Name("xmppAddress") @Optional String xmppAddress,
        @Name("accountId") String accountId, @Name("adapterId") @Optional String adapterId); String createMBAdapter(@Name("address") String address, @Name("keyword") @Optional String keyword,
        @Name("username") String username, @Name("password") String password,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); String createGenericSMSAdapter(@Name("address") String address,
        @Name("provider") @Optional AdapterProviders provider, @Name("keyword") @Optional String keyword,
        @Name("username") String username, @Name("password") String password,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("accountType") @Optional String accountType, @Name("isPrivate") @Optional Boolean isPrivate); String createNexmoAdapter(@Name("address") String address, @Name("keyword") @Optional String keyword,
        @Name("username") String username, @Name("password") String password,
        @Name("preferredLanguage") @Optional String preferredLanguage, @Name("accountId") @Optional String accountId,
        @Name("isPrivate") @Optional Boolean isPrivate); String attachTwitterAdapterToUser( @Name( "adapterID" ) @Optional String adapterID,
        @Name( "twitterUserName" ) @Optional String twitterUserName, @Name( "accountId" ) String accountId ); String createFacebookAdapter(); void setOwner(@Name("adapterId") String adapterId, @Name("accountId") String accountId); void addAccount(@Name("adapterId") String adapterId, @Name("accountId") String accountId); RestResponse getAdapter(@Name("accoutId") String accountId, @Name("adapterId") String adapterId); Object updateAdapter(@Name("accoutId") String accountId, @Name("adapterId") String adapterId,
                                @Name("adapter") Adapter adapter); void setAllAdapterAccountType(@Name("accountId") String accountId, @Name("accountType") AccountType type); void removeAdapter(@Name("adapterId") String adapterId, @Name("accountId") String accountId); ArrayNode getAdapters(@Name("accoutId") String accountId, @Name("adapterType") @Optional String adapterType,
        @Name("address") @Optional String address); ArrayNode getOwnedAdapters( @Name( "accoutId" ) String accountId, @Name( "adapterType" ) @Optional String adapterType, 
                                       @Name( "address" ) @Optional String address ); ArrayNode findAdapters(@Name("adapterType") @Optional String type,
        @Name("address") @Optional String address, @Name("keyword") @Optional String keyword); Object setProviderForAdapters(@Name("adapterId") String adapterId,
        @Name("provider") AdapterProviders provider); Object removeProviderForAdapters(@Name("adapterId") String adapterId); ArrayNode findFreeAdapters(@Name("adapterType") @Optional String adapterType,
        @Name("address") @Optional String address); HashMap<String, String> updateAllAdaptersWithProviders(); AdapterConfig setDialogToAdapter(@Name("accountId") String accountId, @Name("adapterId") String adapterId,
        @Name("dialogId") String dialogId); String getApplicationId(@Name("accountSID") String accountSid, @Name("authToken") String authToken); String getVersion(); static final int EMAIL_SCHEDULER_INTERVAL; static final int TWITTER_SCHEDULER_INTERVAL; static final String ADAPTER_TYPE_CALL; static final String ADAPTER_TYPE_SMS; static final String ADAPTER_TYPE_FACEBOOK; static final String ADAPTER_TYPE_EMAIL; static final String ADAPTER_TYPE_XMPP; static final String ADAPTER_TYPE_TWITTER; static final String ADAPTER_TYPE_USSD; static final String ADAPTER_TYPE_PUSH; }
@Test public void updatingEmptyDialogURLTest() throws Exception { updatingDialogIdInAdapterTest(); ArrayList<AdapterConfig> adapterConfigs = AdapterConfig.findAdapterByAccount(TEST_PRIVATE_KEY); assertThat(adapterConfigs.size(), Matchers.is(1)); AdapterConfig config = adapterConfigs.iterator().next(); Adapter adapter = new Adapter(); adapter.setDialogId(""); new AdapterAgent().updateAdapter(TEST_PRIVATE_KEY, config.getConfigId(), adapter); AdapterConfig refetchedConfig = AdapterConfig.getAdapterConfig(config.getConfigId()); assertThat(refetchedConfig.getInitialAgentURL(), Matchers.is(config.getInitialAgentURL())); assertThat(refetchedConfig.getURLForInboundScenario(null), Matchers.is(config.getInitialAgentURL())); assertThat(refetchedConfig.getURLForInboundScenario(null), Matchers.is(refetchedConfig.getInitialAgentURL())); assertThat(refetchedConfig.getProperties().get(AdapterConfig.DIALOG_ID_KEY), Matchers.nullValue()); assertThat(refetchedConfig.getDialog(), Matchers.nullValue()); }