Как указать ассемблер по умолчанию в seedstack? - PullRequest
1 голос
/ 07 февраля 2020

Я использую 19.11 версию seedstack и хочу использовать ассемблер FluentAssembler для преобразования сводного списка в список DTO.

I я получаю следующую ошибку при вызове метода 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.

Я не знаю, как указать квалификатор, я хотел бы использовать сопоставитель моделей по умолчанию ...

Вот код ресурса:

@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;
    }
}

Совокупность:

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;
    }
}

И 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;
    }
}

1 Ответ

2 голосов
/ 10 февраля 2020

FluentAssembler заботится только о сопоставлении Dto с Ассемблером, но не предоставляет реализацию Ассемблера по умолчанию.

У вас есть 2 варианта для предоставления Ассемблера по умолчанию.

  • Создайте класс, который реализует Asselmber
  • Включите дополнение, которое предоставляет этот сборщик по умолчанию для вас (как указано в документах )
...