...

/

Develop the Business Service Tier

Develop the Business Service Tier

Let's see how the business service can be developed for a one-to-one bi-directional relationship with a join attribute scenario.

We will shift to the business service tier.

“Find all records” operation

First, we will review the test to find all records.

Press + to interact
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class ManuscriptAuthorServiceImplTest {
@Autowired
private ManuscriptService manuscriptService;
@Autowired
private AuthorService authorService;
@Autowired
private ManuscriptAuthorService manuscriptAuthorService;
@Test
public void testFindAll() {
Assert.assertEquals(0L, manuscriptAuthorService.findAll().size());
}
}

Let’s review how to code a similar method in the business service.

Press + to interact
@Service
@Transactional
public class ManuscriptAuthorServiceImpl implements ManuscriptAuthorService {
@Autowired
private ManuscriptDao manuscriptDao;
@Autowired
private ManuscriptMapper manuscriptMapper;
@Autowired
private AuthorDao authorDao;
@Autowired
private AuthorMapper authorMapper;
@Autowired
private ManuscriptAuthorDao manuscriptAuthorDao;
@Override
public List<ManuscriptAuthorDto> findAll() {
List<ManuscriptAuthorDto> manuscriptAuthorDtos = new ArrayList<ManuscriptAuthorDto>();
List<ManuscriptAuthor> manuscriptList = manuscriptAuthorDao.getAll();
for(ManuscriptAuthor manuscriptAuthor : manuscriptList) {
ManuscriptAuthorDto manuscriptAuthorDto = new ManuscriptAuthorDto();
manuscriptAuthorDto.setManuscriptDto(manuscriptMapper.mapEntityToDto(manuscriptAuthor.getManuscript()));
manuscriptAuthorDto.setAuthorDto(authorMapper.mapEntityToDto(manuscriptAuthor.getAuthor()));
manuscriptAuthorDto.setPublisher(manuscriptAuthor.getPublisher());
manuscriptAuthorDtos.add(manuscriptAuthorDto);
}
return manuscriptAuthorDtos;
}
}

Create operation

Let’s move on to the ...