Skip to content

Create environment

Step1 Create entity

Create entity extends BaseEntity

Example
@Entity
@Getter
@Setter
@NoArgsConstructor
public class MyEntity extends BaseEntity {

}

Step 2 Create DTO

Create DTO extends DataResponseDTO

Example
@Getter
@Setter
@NoArgsConstructor
public class MyExampleDTO extends DataResponseDTO {

    public MyExampleDTO(MyEntity entity) {
        this.id = entity.getId().toString();
    }
}

Step3 Create MetaBuilder

Create MetaBuilder extends FieldMetaBuilder

Example
@Service
public class MyExampleMeta extends FieldMetaBuilder<MyExampleDTO> {
// --8<-- [start:buildRowDependentMeta]
    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
                                      Long id, Long parentId) {
    }
   // --8<-- [end:buildRowDependentMeta]

   // --8<-- [start:buildIndependentMeta]
  @Override
    public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription, Long parentId) {
    }

}

Step4 Create Service

Create Service extends VersionAwareResponseService

Example
@Service
public class MyExampleService extends VersionAwareResponseService<MyExampleDTO, MyEntity> {

    private final MyEntityRepository repository;

    public MyExampleService(MyEntityRepository repository) {
        super(MyExampleDTO.class, MyEntity.class, null, MyExampleMeta.class);
        this.repository = repository;
    }

    @Override
    protected CreateResult<MyExampleDTO> doCreateEntity(MyEntity entity, BusinessComponent bc) {
        repository.save(entity);
        return new CreateResult<>(entityToDto(bc, entity));
    }

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntity entity, MyExampleDTO data, BusinessComponent bc) {

        return new ActionResultDTO<>(entityToDto(bc, entity));
    }

     // --8<-- [start:getActions]
    @Override
    public Actions<MyExampleDTO> getActions() {
        return Actions.<MyExampleDTO>builder()
                .action(act -> act
                        .action("save", "save")
                )
                .build();
    }
     // --8<-- [end:getActions]  
}

Step5 Create Controller

Create Controller implements EnumBcIdentifier

Example
@Getter
public enum PlatformMyExampleController implements EnumBcIdentifier {


    myExampleBc(MyExampleService.class);



    public static final EnumBcIdentifier.Holder<PlatformMyExampleController> Holder = new Holder<>(
            PlatformMyExampleController.class);

    private final BcDescription bcDescription;

    PlatformMyExampleController(String parentName, Class<?> serviceClass, boolean refresh) {
        this.bcDescription = buildDescription(parentName, serviceClass, refresh);
    }

    PlatformMyExampleController(String parentName, Class<?> serviceClass) {
        this(parentName, serviceClass, false);
    }

    PlatformMyExampleController(BcIdentifier parent, Class<?> serviceClass, boolean refresh) {
        this(parent == null ? null : parent.getName(), serviceClass, refresh);
    }

    PlatformMyExampleController(BcIdentifier parent, Class<?> serviceClass) {
        this(parent, serviceClass, false);
    }

    PlatformMyExampleController(Class<?> serviceClass, boolean refresh) {
        this((String) null, serviceClass, refresh);
    }

    PlatformMyExampleController(Class<?> serviceClass) {
        this((String) null, serviceClass, false);
    }

    @Component
    public static class BcSupplier extends AbstractEnumBcSupplier<PlatformMyExampleController> {

        public BcSupplier() {
            super(PlatformMyExampleController.Holder);
        }

    }

}