Create environment
Step1 Create entity
Create entity extends BaseEntity
Step 2 Create DTO
Create DTO extends DataResponseDTO
Example
Step3 Create MetaBuilder
Create MetaBuilder extends FieldMetaBuilder
Example
@SuppressWarnings("EmptyMethod")
@Service
public class MyExampleMeta extends FieldMetaBuilder<MyExampleDTO> {
@Override
public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
Long id, Long parentId) {
}
@Override
public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription, Long parentId) {
}
}
Step4 Create Service
Create Service extends VersionAwareResponseService
Example
@SuppressWarnings("java:S")
@RequiredArgsConstructor
@Service
public class MyExampleService extends VersionAwareResponseService<MyExampleDTO, MyEntity> {
private final MyEntityRepository repository;
@Getter(onMethod_ = @Override)
private final Class<MyExampleMeta> meta = MyExampleMeta.class;
@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));
}
@Override
public Actions<MyExampleDTO> getActions() {
return Actions.<MyExampleDTO>builder()
.action(act -> act
.action("save", "save")
)
.build();
}
}
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);
}
}
}