I create a telegram bot on SpringWebhookBot(telegram api) on java.
I have a has these methods
private SendMessage getArmours(String chatId, String type) {
method body
return makeMessage(chatId, buttons, text);
}
I need to build an image in SendMessage instance, or send it separately but from this method.
I can't use the execute(Sendphoto sendphoto) method because I don't have a bot instance in this environment.I tried to do it but went into a cyclical dependency
┌─────┐
| bot defined in file [C:\Users\Crank\dev\wow\target\classes\ru\studio\crank\wow\bot\Bot.class]
↑ ↓
| messageHandler defined in file [C:\Users\Crank\dev\wow\target\classes\ru\studio\crank\wow\bot\MessageHandler.class]
↑ ↓
| home defined in file [C:\Users\Crank\dev\wow\target\classes\ru\studio\crank\wow\locations\Home.class]
└─────┘
Please. help. How could I include an image in sendMessage.
Related
I'm attempting to create a Xamarin Binding Library for the Android UseButton library. I created my binding project, included the .aar and set Build Action = LibraryProjectZip. As was expected, a bunch of errors popped up and I've managed to get rid of most using the Metadata.xml file, except for a bunch that follow the same pattern:
Error CS0102 The type 'CrossBridgeCommunicator' already contains a definition for 'WebViewDismiss'
I checked the CrossBridgeCommunicator class, and found it has 2 copies of about 12 events. Here's a snippet of one of these duplicates
#region "Event implementation for Com.Usebutton.Sdk.Internal.Bridge.BridgeMessageParser.IListener"
...
public event EventHandler WebViewDismiss {
add {
global::Java.Interop.EventHelper.AddEventHandler<global::Com.Usebutton.Sdk.Internal.Bridge.BridgeMessageParser.IListener, global::Com.Usebutton.Sdk.Internal.Bridge.BridgeMessageParser.IListenerImplementor>(
ref weak_implementor___SetMainBridge,
__CreateIListenerImplementor,
__v => MainBridge = __v,
__h => __h.OnWebViewDismissHandler += value);
}
...
}
...
public event EventHandler WebViewDismiss {
add {
global::Java.Interop.EventHelper.AddEventHandler<global::Com.Usebutton.Sdk.Internal.Bridge.BridgeMessageParser.IListener, global::Com.Usebutton.Sdk.Internal.Bridge.BridgeMessageParser.IListenerImplementor>(
ref weak_implementor___SetWidgetBridge,
__CreateIListenerImplementor,
__v => WidgetBridge = __v,
__h => __h.OnWebViewDismissHandler += value);
}
...
}
The only difference between them is that they access different attributes in their bodies (the "weak_implementor__"). I checked the original class in a Java decompiler and it doesn't implement any of these events; in fact, it doesn't even implement the interface. What it does have are 2 fields of this interface type. I'm guessing Xamarin creates these methods for some reason, but I don't know why or how. They don't even appear on the api.xml (nor do the fields).
I tried to change the name of the events using the Metadata.xml file, but, since these events don't even exist in the Java class, I don't know how to find them. I even tried to remove the fields using "remove-node", but am getting the warning no nodes matched. Does anyone know how can I change these events' names? Again, they come from the same interface, but are created directly on the class that has 2 fields of the interface type.
Thanks in advance.
I'm wondering about one issue encountered when implementing reactive Mongo repository in a DDD project which I implement using Java and Spring Boot. Suppose we have such package structure:
/app
|
|------/application
| |
| |------/order
| |
| |------OrderApplicationService.java
|
|------/domain
| |
| |------/order
| |
| |------Order.java
| |------OrderRepository.java
|
|------/infrastructure
|
|------/mongo
|
|------MongoOrderRepository.java
I my OrderRepository.java I want to have a method to save my Order:
public interface OrderRepository {
Order save(Order order);
}
And use it in my application service:
#Service
public class OrderApplicationService {
private final OrderRepository orderRepository;
public OrderApplicationService(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
public void createOrder() {
//Dumb order creation
Order createdOrder = clientRepository.save(new Order());
}
}
Next I want to write MongoOrderRepository which implements OrderRepository. Suppose I will use ReactiveMongoTemplate. The problem is that all its methods return Flux or Mono, so I can't implement my method from OrderRepository interface.
Possible solutions I see are:
Make 'save' method in OrderRepository return an Order wrapped by
Mono. This approach will polute the domain layer with Reactor
specific types and break the rule saying that domain layer should be
framework code free.
Develop some sort of wrapping layer, but this will produce some
boilerplate code.
Move OrderService.java to infrastructure layer, but this also breaks some basic DDD concepts.
Does someone see any better solutions?
The repository should be agnostic of framework code, that's true and that's a good practice, but you need to be pragmatic as well, I had repository where I used java lambda, which are language level framework one could argue.
What is the benefit of using Flux or Mono, and what is the benefit of advertising them as part of the interface ? If there is none, you can then keep the implementation detail into the repository implementation and keep the interface free of reactive objects.
However, if this needs to span through the application layer to the port adapters, then I don't see any issues putting them in the interface definition of your repository.
That being said, you might want to check another approach, with CQRS and Hexagonal Architecture, you can have best of both worlds:
Having a clean repository interface for the command (Update and Create part)
Using a Query Service (plain POJO if you are in java, defined in your application package) returning a Mono or Flux for the Query (Read part)
OrderApplicationService.java (here go the Create Update Delete via commands)
OrderQueryService.java (here go the Read part)
Your application service contains a reference to your OrderRepository, the query service does not use the repository as it query more directly the db, via ReactiveMongoTemplate for instance.
In my Query services I used plain JDBC Templates for instance while using Hibernate in the repository implementation.
I am using STS to create a Java webapp.
I have used the following code to set an attribute to an object of the Cat class named myCat.
request.setAttribute("myCat", myCat);
Inside of the Cat class are attributes and the method:
String showAffection(){
return("jumps into your lap and stares at you.");
}
Now, in my .jsp file, I tried to print it with
request.getAttribute("myCat").showAffection();
However, STS is showing me this problem in the .jsp file:
The method showAffection() is undefined for the type Object
What is going wrong? Is this not the correct way to access methods in the object?
I have a set 4 template files, all with the .rythm extension, and all living in the same directory. Let's call them "Main.rythm", "Child1.rythm", "Child2.rythm", and "Helper.rythm". Additionally, I also set the home.template.dir to this directory before rendering Main.
In the Helper template, I just have a bunch of #defs that do some basic common formatting so that I don't have to call back to a my java class or clutter up the actual template with logic that doesn't need to be there.
Main looks something like this:
#args {
String aString,
MyClass bunchOfData,
String anotherString
#//...
}
#import("Helper")
There's some formatting here, using #aString
There's some formatting using an #def in Helper, like #foo(anotherString)
#Child1(bunchOfData)
#Child2(bunchOfData)
And Child1 and Child2 are similar to each other and look something like this:
#args MyClass bunchOfData
#import("Helper")
#{
//Some preformatting stuff here
}
Make a lot of method calls on #bunchOfData, some of which will also use an #def or two in Helper
My problem is that I'm getting an error in Child1 on the #import("Helper") line:
Exception in thread "main" org.rythmengine.exception.CompileException: Syntax error on token "import", delete this token
Template: /path/to/templates/Child1.rythm
I've tried commenting out the #import, but then I can't really call those #defs, and get errors from Rythm that "Helper cannot be resolved" when I use #Helper.foo(bunchOfData.getSomething()).
What is it that I need to do in order to get access to these #defs in Helper from Child1 and Child2?
You shouldn't be using #import, you should be using #include instead. #import is just like the import directive in java, adding a package for this template to refer to. #include is for adding additional templates that you can refer to throughout this template.
SOLVED
I'm using DTO to map my DB to a Java object.
I had an error like this doku.eds2.dto.Transaction.getListedStatus()Ljava/lang/Character;
I have checked my Transaction.java file, it contains the getListedStatus() method.
#Column(name="listed_status", length=1)
public Character getListedStatus() {
return this.listedStatus;
}
public void setListedStatus(Character listedStatus) {
this.listedStatus = listedStatus;
}
and also my table contains this field :
Column | Type | Modifiers
listed_status | character(1) |
How can I fix this error?
Thank in advance.
This sort of error often happens if you have two different versions of a class, one with the method and one without. If the one without the method ends up in the classpath earlier than the one with, then you will get an error like this.
Make sure that your classpath does not contain any other classes of the type "doku.eds2.dto.Transaction". If you're in Eclipse, you can do this by pressing Ctrl-Shift-T and entering the class name into the search. If you get multiple matches, you probably have a class path or dependency problem.