@Override public void link(IncomeMessage message, String userId, String channel, String target) { UserRequest request; if (message.user() != null && message.user().id().equals(userId)) { request = new UserRequest(userId, channel, target, Destination.channel(channel).to(target)); } else { request = new UserRequest(userId, channel, target, Destination.channel("user").to(userId)); } this.requestManager.create(request, "user.link", "link account to user " + userId); }
private <T> T convert(String string, Class<T> type) { try { return new ParameterBinder<>(type) .context(context -> { OsgiServiceRegistry registry = new OsgiServiceRegistry(); OsgiParameterResolver osgiResolver = new OsgiParameterResolver(registry); context.use(this.incomeMessage) .when(type(IncomeMessage.class)) .use(this.incomeMessage.channel()) .when(type(Channel.class)) .use(this.incomeMessage.sender()) .when(type(Sender.class)) .use(this.incomeMessage.location()) .when(type(MessageLocation.class)) .use(registry) .when(type(ServiceRegistry.class)) // try to lookup implementations by default using the osgi registry .use(osgiResolver) .byDefault(); if (this.incomeMessage.user() != null) { context.use(parameter -> this.incomeMessage.user()) .when(type(User.class)); } }).apply(string); } catch (Exception e) { throw new MessageProcessingException("Invalid command parameters."); } }
}) .on("default", channel -> { User user = message.user(); if (user == null) { throw new MessageProcessingException("You're not registered.");