@Override public RobotAccountData unregister(ParticipantId robotId) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); AccountData accountData = accountStore.getAccount(robotId); if (accountData == null) { return null; } throwExceptionIfNotRobot(accountData); RobotAccountData robotAccount = accountData.asRobot(); removeRobotAccount(robotAccount); return robotAccount; }
@Override public RobotAccountData registerOrUpdate(ParticipantId robotId, String location) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); Preconditions.checkNotNull(location); Preconditions.checkArgument(!location.isEmpty()); AccountData account = accountStore.getAccount(robotId); if (account != null) { throwExceptionIfNotRobot(account); RobotAccountData robotAccount = account.asRobot(); if (robotAccount.getUrl().equals(location)) { return robotAccount; } else { removeRobotAccount(robotAccount); } } return registerRobot(robotId, location); }
@Override public void putAccount(AccountData account) { DBObject object = getDBObjectForParticipant(account.getId()); if (account.isHuman()) { object.put(ACCOUNT_HUMAN_DATA_FIELD, humanToObject(account.asHuman())); } else if (account.isRobot()) { object.put(ACCOUNT_ROBOT_DATA_FIELD, robotToObject(account.asRobot())); } else { throw new IllegalStateException("Account is neither a human nor a robot"); } getAccountCollection().save(object); }
public void testReRegisterSucceedsOnExistingRobotAccount() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).removeAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); assertTrue(unregisteredAccountData.isRobot()); RobotAccountData robotAccountData = unregisteredAccountData.asRobot(); // Remove the last '/'. assertEquals(OTHER_LOCATION.substring(0, OTHER_LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }
new OAuthConsumer(null, participant.getAddress(), account.asRobot().getConsumerSecret(), oauthServiceProvider); OAuthAccessor accessor = new OAuthAccessor(consumer);
public void testReRegisterSucceedsOnExistingRobotAccount() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).removeAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); assertTrue(unregisteredAccountData.isRobot()); RobotAccountData robotAccountData = unregisteredAccountData.asRobot(); // Remove the last '/'. assertEquals(OTHER_LOCATION.substring(0, OTHER_LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }
/** * Serialize {@link AccountData} into {@link ProtoAccountData}. */ public static ProtoAccountData serialize(AccountData account) { Preconditions.checkNotNull(account, "account is null"); Preconditions.checkArgument(account.isHuman() || account.isRobot(), "account is neither a human or robot account!"); ProtoAccountData.Builder builder = ProtoAccountData.newBuilder(); builder.setAccountId(account.getId().getAddress()); if (account.isHuman()) { builder.setAccountType(AccountDataType.HUMAN_ACCOUNT); builder.setHumanAccountData(serialize(account.asHuman())); } else if (account.isRobot()) { builder.setAccountType(AccountDataType.ROBOT_ACCOUNT); builder.setRobotAccountData(serialize(account.asRobot())); } return builder.build(); }
RobotAccountData robotAccount = account.asRobot(); if (robotAccount.isVerified()) { Robot robot = getOrCreateRobot(robotName, robotAccount);
account = getAccountStore() .getAccount(ParticipantId.ofUnsafe(getRobotId() + "@" + getWaveDomain())).asRobot(); } catch (PersistenceException e) { LOG.log(Level.WARNING, "Cannot fetch account data for robot id: " + getRobotId(), e);
RobotAccountData robotAccountData = account.asRobot(); RobotCapabilities capabilities = robotAccountData.getCapabilities(); if (capabilities != null && capabilitiesHash.equals(capabilities.getCapabilitiesHash())) {