@Override public void putAccount(AccountData account) { accounts.put(account.getId(), account); }
@Override public void putAccount(AccountData account) { accountStore.put(account.getId(), account); }
@Override public void putAccount(AccountData account) throws PersistenceException { synchronized (accounts) { Preconditions.checkNotNull(account); writeAccount(account); accounts.put(account.getId(), account); } }
private void writeAccount(AccountData account) throws PersistenceException { File accountFile = new File(participantIdToFileName(account.getId())); OutputStream file = null; try { file = new FileOutputStream(accountFile); ProtoAccountData data = ProtoAccountDataSerializer.serialize(account); file.write(data.toByteArray()); file.flush(); } catch (IOException e) { LOG.severe("Failed to write account data to file: " + accountFile.getAbsolutePath(), e); throw new PersistenceException(e); } finally { FileUtils.closeAndIgnoreException(file, accountFile, LOG); } } }
/** * Ensures that the account belongs to a robot. * * @param existingAccount the account to check. * @throws RobotRegistrationException if the account is not robot. */ private void throwExceptionIfNotRobot(AccountData existingAccount) throws RobotRegistrationException { if (!existingAccount.isRobot()) { throw new RobotRegistrationException(existingAccount.getId().getAddress() + " is not a robot account!"); } }
public void testRegisterExistingUserThrowsError() throws Exception { attemptToRegister(req, resp, "frodo@example.com", "asdf", false); verify(resp).setStatus(HttpServletResponse.SC_FORBIDDEN); // ... and it should have left the account store unchanged. assertSame(account, store.getAccount(account.getId())); }
public void testRegisterExistingUserThrowsError() throws Exception { attemptToRegister(req, resp, "frodo@example.com", "asdf", false); verify(resp).setStatus(HttpServletResponse.SC_FORBIDDEN); // ... and it should have left the account store unchanged. assertSame(account, store.getAccount(account.getId())); }
@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); }
/** * 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 = connector.fetchCapabilities(robotAccountData, ""); } catch (CapabilityFetchException e) { LOG.fine("Unable to retrieve capabilities for " + account.getId(), e); context.constructErrorResponse(operation, "Unable to retrieve new capabilities"); return;