25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 17 ■ Be Social and Go Mobile<br />

@Service("documentFacade")<br />

public class DocumetServiceFacade implements DocumentService {<br />

@Autowired<br />

DocumentDAO documentDAO;<br />

@Autowired<br />

DocumentTweet documentTweet;<br />

public List getAllDocuments(){<br />

return documentDAO.getAll();<br />

}<br />

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

Document documentResult = documentDAO.save(id, document);<br />

}<br />

if("WEB".equals(documentResult.getType().getName())){<br />

StringBuilder tweetText = new StringBuilder("My Documents App - A Book update: ");<br />

tweetText.append(documentResult.getName());<br />

tweetText.append(". Check it out: ");<br />

tweetText.append(documentResult.getLocation());<br />

documentTweet.tweet(tweetText.toString());<br />

}<br />

return documentResult;<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 />

public List findByType(Type type) {<br />

return documentDAO.findByTypeName(type.getName());<br />

}<br />

}<br />

In Listing 17-5, you added the DocumentTweet class and added some code to the saveDocument method. You are<br />

adding logic that says if a document is a web type (note that so far you have three types of documents: PDF, note,<br />

and web), you are going to tweet about it.<br />

248

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

Saved successfully!

Ooh no, something went wrong!