Request Processor

Regular Functionality

<D> D process(Object source, Class<D> destination)

Take DTO object, validate, and then copy to some other Class such as entity.

Example

process(dtoObject, Person.class);


<D> D process(Object source, D destination)

Take DTO object, validate, and then copy to some other object such as entity. which could be prepopulate.

Example

process(dtoObject, person);


<D> D process(RequestData<?> requestData, D destination)

Take RequestData DTO object, validate, and then copy to some other object such as entity. which could be prepopulate.

Example

    public MessageResponse create(RequestData<PersonDetailDTO> data) {
        Person person = ..
        Person entity = requestProcessor().process(data, person);
        personRepository.save(entity);
        return responseProcessor().response("Created");
    }


<D> D process(RequestData<?> requestData, Class<D> destination)

Take RequestData DTO object, validate, and then copy to some other entity class.

Example

    public MessageResponse create(RequestData<PersonDetailDTO> data) {
        Person entity = requestProcessor().process(data, Person.class);
        personRepository.save(entity);
        return responseProcessor().response("Created");
    }


<D, E> BulkErrorValidEntities<D, E> process(RequestBulkData<D> requestData, Class<E> destination)

Take RequestData DTO list of object, validate, and then copy to some other entity class.

Example

    public BulkResponse<PersonDetailDTO> bulkCreate(RequestBulkData<PersonDetailDTO> data) {
        BulkErrorValidEntities<PersonDetailDTO, Person> bulkData = requestProcessor().process(data, Person.class);
        if (bulkData.isValidEntities()) {
            personRepository.saveAll(bulkData.getEntities());
        }
        return responseProcessor().response(bulkData, PersonDetailDTO.class);
    }


<O> Long validateId(RequestData<O> data, String message)

Take RequestData DTO and find the id field and it value, if field or value not available then will throw the provided message.


<O> Long validateId(Long id, String message)

Take Long field and check value not available then will throw the provided message.


Boolean dataValidate(Object source)

Take DTO object if there is validation annotation then validate the object and throw exception if any error there, otherwise it will return true.


<D> void dataValidate(RequestData<D> requestData)

Take RequestData DTO object if there is validation annotation then validate the object and throw exception if any error there, otherwise it will return true.


<D> D copySrcToDstValidate(Object source, Class<D> destination)

Validate and copy source object to destination Class, and return the Destination class


<D> D copySrcToDstValidate(Object source, D destination)

Validate and copy source object to destination object, and return the Destination object


<O> Long getId(RequestData<O> data)

Get id from RequestData, there should be id field and must Long type, otherwise it will return null.


<O> Long validateNGetId(RequestData<O> data, String message)

Try to get id from RequestData, there should be id field and must Long type, otherwise it will throw the provided message.


<O> Long getIdFieldValue(O object)

Try to get id from object, there should be id field and must Long type, otherwise it will return null.


PageRequest paginationNSort(Integer page, Integer size, String sort, String field)

Prepare JPA Page Request object, if page and size not available then it assign default page 0, and size 15, otherwise it generate by input. There is also sorting field and direction object.

Example

paginationNSort(1, 50, "name", "asc")


Static Method for Remote usage

static RequestProcessor instance()

Static method for create Instance.