简体   繁体   English

如何在种子堆栈中指定默认汇编程序?

[英]How to specify a default assembler in seedstack?

I'm using the 19.11 version of seedstack , and I want to use the FluentAssembler assembler to convert an aggregate List into a DTO List.我使用的是 19.11 版本的seedstack ,我想使用FluentAssembler汇编程序将聚合列表转换为 DTO 列表。

I'm getting the following error when I call the fluentAssembler.assemble method :当我调用 fluentAssembler.assemble 方法时出现以下错误:

org.seedstack.business.internal.BusinessException: [BUSINESS] Unable to find assembler

Description
-----------
No assembler was found to assemble 'com.inetpsa.svr.domain.model.customer.Customer(Customer.java:1)' to
'com.inetpsa.svr.interfaces.rest.customer.CustomerRepresentation(CustomerRepresentation.java:1)'.

Fix
---
Make sure that an assembler without qualifier exists. If you want to use a qualified assembler (like a default
assembler), specify its qualifier.

I don't know howto specify the qualifier, I'd like to use a default model mapper...我不知道如何指定限定符,我想使用默认模型映射器...

Here is The Resource code :这是资源代码:

@Path("customers")
public class CustomerResource {

    @Inject
    private FluentAssembler fluentAssembler;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<CustomerRepresentation> listAllCustomers() {
        List<Customer> customerList = fetchAllCustomers();
        return fluentAssembler.assemble(customerList).toListOf(CustomerRepresentation.class);
    }

    /**
     * Test method - Should be replaced by a repository
     * @return List<Customer> all customers
     */
    private List<Customer> fetchAllCustomers(){
        List<Customer> customerList = new ArrayList<>();
        customerList.add(buildCustomer("005","Edward Teach","edward.teach@pirates.org"));
        customerList.add(buildCustomer("006","Olivier Levasseur","olivier.levasseur@pirates.org"));
        customerList.add(buildCustomer("007","James Bond","james.bond@mi6.uk"));
        return customerList;
    }

    private Customer buildCustomer(String id, String name, String mail){
        Customer result = new Customer(id);
        result.updateNameAndMail(name, mail);
        return result;
    }
}

The aggregate :总量:

public class Customer extends BaseAggregateRoot<String> {

    @Identity
    private String identifier;
    private String name;
    private String mail;

    public Customer(String identifier){
        this.identifier=identifier;
    }

    public void updateNameAndMail(String name, String mail){
        if(StringUtils.isBlank(name)){
            throw new IllegalArgumentException("Name can't be blank");
        }
        if(StringUtils.isBlank(mail)){
            throw new IllegalArgumentException("Mail can't be blank");
        }
        this.name=name;
        this.mail=mail;
    }

    public String getIdentifier() {
        return identifier;
    }

    public String getName() {
        return name;
    }

    public String getMail() {
        return mail;
    }
}

And the DTO :和 DTO :

@DtoOf(Customer.class)
public class CustomerRepresentation {
    private String identifier;
    private String name;
    private String mail;

    /**
     * Required public no parameters constructor
     */
    public CustomerRepresentation(){}

    public CustomerRepresentation(String identifier, String name, String mail){

    }
    @AggregateId
    public String getIdentifier() {
        return identifier;
    }

    public String getMail() {
        return mail;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }
}

FluentAssembler only takes care of matching a Dto with an Assembler, but does not provide a default implementation of an Assembler by itself. FluentAssembler 只负责将 Dto 与 Assembler 进行匹配,但本身不提供 Assembler 的默认实现。

You have 2 Options to provide a Default Assembler.您有 2 个选项来提供默认汇编程序。

  • Build a class that implements Asselmber构建一个实现 Asselmber 的类
  • Include an addon that provides that Default Assember for you (As stated on the docs )包括一个为您提供默认汇编程序的插件(如文档中所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM