Search⌘ K
AI Features

Develop the Business Service Tier

Explore how to develop the business service tier by implementing core operations such as finding, creating, removing, and verifying links between entities. This lesson focuses on managing bi-directional many-to-many relationships with join attributes in a Java Spring context.

We will shift to the business service tier.

“Find all records” operation

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

Java
@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.

Java
@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 create operation that ...