vert-x3 / vertx-service-proxy

EventBus Proxy generation
Apache License 2.0
67 stars 58 forks source link

UUID incoming/return parameters + Collection/List/Set/Stream<MyType> support ?? #63

Closed blandger closed 6 years ago

blandger commented 6 years ago

Hi vertx folks, I would like to ask question related to Service Proxy java code generation. Gradle 4.3.1 is used.

1. How can I use UUID as part of ServiceProxy generation? (we use java UUID and Cassandra datastax driver time-based UUID classes) 2. Are Collection/List/Set/Stream with custom type supported as incoming and return parameters?

I'm trying to use example from here as reference: https://github.com/advantageous/vertx-node-ec2-eventbus-example/wiki/Step-5-Using-Vertx-Service-Proxies

e.g. I have DTO as:

@DataObject
public class MyEntityDTO {
  private UUID myEntityId;
....
  public MyEntityDTO(JsonObject data) {....}
}

Service Proxy Interface like:

@ProxyGen
@VertxGen
public interface MyEntityServiceAsynch {
void save(MyEntityDTO entity, Handler<AsyncResult<UUID>> resultHandler);
void retrieveByExample(MyEntityDTO entityQueryByExample, Handler<AsyncResult<List<MyEntityDTO>>> resultHandler);
....}

I have 'package-info.java' files in folders, but don't understand how can I generate UUIDs as part of Service contract ? Can someone give a hint?


Could not generate model for .....service.MyEntityServiceAsynch#save(.....dto.MyEntityDTO,io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.UUID>>): type io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.UUID>> is not legal for use for a parameter in code generation
  void save(MyEntityDTO entity, final Handler<AsyncResult<UUID>> resultHandler);
       ^
warning: The following options were not recognized by any processor: '[outputDirectory]'

I'm appreciate for any hint.

blandger commented 6 years ago

After temporal replacing UUID to String type and tweaking other issues, I still have problem with code generation by Gradle.

@ProxyGen
@VertxGen
public interface MyEntityServiceAsynch {
void save(MyEntityDTO entity, Handler<AsyncResult<String>> resultHandler);
void retrieveByExample(MyEntityDTO entityQueryByExample, Handler<AsyncResult<List<MyEntityDTO>>> resultHandler);
....}

The gradle config example from : vertx-codegen/README.md produces the same error about 'incorrect outputDirectory'. Something has changed in gradle 4.3.1 probably...

service/MyEntityServiceAsynch.java:25: error: Could not generate model for ....service.MyEntityServiceAsynch: Overloaded method create must have the same return type .....service.MyEntityServiceAsynch != void
public interface MyEntityServiceAsynch {
       ^
warning: The following options were not recognized by any processor: '[outputDirectory]'
1 error

Could not generate model for ....service.MyEntityServiceAsynch: Overloaded methods are not allowed in ProxyGen interfaces create
io.vertx.codegen.GenException: Overloaded methods are not allowed in ProxyGen interfaces create
        at io.vertx.codegen.ProxyModel.checkMethod(ProxyModel.java:111)
        at io.vertx.codegen.ClassModel.addMethod(ClassModel.java:826)
........
blandger commented 6 years ago

Removing method: void retrieveByExample(MyEntityDTO entityQueryByExample, Handler<AsyncResult<List<MyEntityDTO>>> resultHandler);

resolves problem, because it clashes with first method:

void save(MyEntityDTO entity, Handler<AsyncResult<String>> resultHandler);

tsegismont commented 6 years ago

The service interface constraints are listed here: https://github.com/vert-x3/vertx-service-proxy/blob/master/src/main/asciidoc/java/index.adoc#restrictions-for-service-interface

It's not possible to use UUID or a list/set of dataobjects. For UUID, going through String representation is a good idea. For dataobjects collections, you could create your own annotated with @Dataobject