} else if (!account.isHuman()) {
/** * 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(); }
@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); }