/** * Constructs a new Robot which is characterized by its {@link RobotName}. * * @param robotName the name of the {@link Robot}. * @param account the {@link RobotAccountData} belonging to this * {@link Robot}. * @param gateway the gateway this robot belongs to. * @param connector the {@link RobotConnector} to make connections to * {@link Robot}s. * @param converterManager used to convert to Robot API objects. * @param waveletProvider used to access wavelets and submit deltas. * @param eventGenerator used to generate events * @param operationApplicator used to apply the robot operations returned by a * robot. */ Robot(RobotName robotName, RobotAccountData account, RobotsGateway gateway, RobotConnector connector, EventDataConverterManager converterManager, WaveletProvider waveletProvider, EventGenerator eventGenerator, RobotOperationApplicator operationApplicator) { Preconditions.checkArgument(account.isVerified(), "Account must be verified"); this.robotName = robotName; this.gateway = gateway; this.connector = connector; this.converterManager = converterManager; this.eventGenerator = eventGenerator; this.operationApplicator = operationApplicator; setAccount(account); }
private DBObject robotToObject(RobotAccountData account) { return new BasicDBObject() .append(ROBOT_URL_FIELD, account.getUrl()) .append(ROBOT_SECRET_FIELD, account.getConsumerSecret()) .append(ROBOT_CAPABILITIES_FIELD, capabilitiesToObject(account.getCapabilities())) .append(ROBOT_VERIFIED_FIELD, account.isVerified()); }
private static ProtoRobotAccountData serialize(RobotAccountData account) { Preconditions.checkNotNull(account, "account is null"); ProtoRobotAccountData.Builder builder = ProtoRobotAccountData.newBuilder(); builder.setUrl(account.getUrl()); builder.setConsumerSecret(account.getConsumerSecret()); builder.setIsVerified(account.isVerified()); if (account.getCapabilities() != null) { builder.setRobotCapabilities(serialize(account.getCapabilities())); } return builder.build(); }
if (robotAccount.isVerified()) { Robot robot = getOrCreateRobot(robotName, robotAccount); updateRobot(robot, wavelet, deltas);
/** * Returns a new {@link RobotAccountData} updated with the new capabilities * using the given {@link RobotAccountData}. * * @param account The {@link RobotAccountData} to update the capabilities for. * @param activeApiUrl the url of the Active Robot API. * @throws CapabilityFetchException if the capabilities couldn't be retrieved * or parsed. */ public RobotAccountData fetchCapabilities(RobotAccountData account, String activeApiUrl) throws CapabilityFetchException { RobotCapabilitiesParser parser = new RobotCapabilitiesParser( account.getUrl() + Robot.CAPABILITIES_URL, connection, activeApiUrl); RobotCapabilities capabilities = new RobotCapabilities( parser.getCapabilities(), parser.getCapabilitiesHash(), parser.getProtocolVersion()); return new RobotAccountDataImpl(account.getId(), account.getUrl(), account.getConsumerSecret(), capabilities, account.isVerified()); } }