25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12 ■ Exposing a REST API<br />

Listing 12-2. DocumentServiceFacade.java<br />

package com.apress.isf.spring.service;<br />

import java.util.List;<br />

import org.springframework.beans.factory.annotation.Autowired;<br />

import org.springframework.stereotype.Component;<br />

import com.apress.isf.java.model.Document;<br />

import com.apress.isf.java.service.DocumentService;<br />

import com.apress.isf.spring.data.DocumentDAO;<br />

@Component("documentFacade")<br />

public class DocumetServiceFacade implements DocumentService {<br />

}<br />

@Autowired<br />

DocumentDAO documentDAO;<br />

public List getAllDocuments(){<br />

return documentDAO.getAll();<br />

}<br />

public Document saveDocument(String id, Document document) {<br />

return documentDAO.save(id, document);<br />

}<br />

public Document removeDocumentById(String id) {<br />

return documentDAO.removeById(id);<br />

}<br />

public Document findDocumentById(String id){<br />

return documentDAO.findById(id);<br />

}<br />

public boolean updateLocationFromDocumentId(String documentId, String location) {<br />

Document document = documentDAO.findById(documentId);<br />

if(null == document)<br />

return false;<br />

document.setLocation(location);<br />

saveDocument(documentId, document);<br />

return true;<br />

}<br />

Listing 12-2 shows the DocumentServiceFacade class. This class is using the DocumentDAO implementation<br />

that takes care of persistence because it has direct access to the database. Listing 12-3 shows the DocumentDAO<br />

implementation class that needs to be modified as well.<br />

171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!