I'm building a REST API service based on Jersey & Hibernate which contains the following layers: Architecture
Each entity in the model has its own service in the service layer (interfaces). As described above, DTOs are passed to and from the service layer to the endpoints layer. The following is PolicySetService interface:
public interface PolicySetService extends BaseService<PolicySet, PolicySetDao> {
String createPolicySet(String accountId, PolicySetDto policySet) throws PolicyException;
void updatePolicySet(String accountId, String policySetId, PolicySetDto newPolicySet) throws PolicyException;
PolicySetDto getPolicySetDto(String accountId, String policySetId) throws PolicyException;
void deletePolicySet(String accountId, String policySetId) throws PolicyException;
}
Now lets take a look at EvaluationService interface:
public interface EvaluationService extends BaseService<Evaluation, EvaluationDao> {
EvaluationDto createEvaluation(String accountId, String policySetId, EvaluationRequestData requestData) throws PolicyException;
}
I have been reading that its a best practice for one service (lets say EvaluationService) to call another (lets say PolicySetService) in order to get domain model entity for instance (Instead of calling directly to PolicySet Dao from EvaluationService) In my case, EvaluationService implementation should use PolicySetService to get PolicySet entity (not the DTO) to perform some business logic before the Evaluation Entity is being persisted. Currently, the PolicySetService returns DTO and i need to convert it to the real PolicySet entity in the EvaluationService. Note that the services should expose only DTOs to higher layers (but i need some how to expose the entity domain model inside the service layer, meaning between services) What is the best architecture to get this? Should i create another "internal" service interface for services to communicate with each other? Is there any better architecture for this?