0

I'm creating a bookmark app from the book The Definitive Guide to Grails by Graeme Rocher. In this app I am trying to create a service where when I search for a bookmark, it'll also search in del.icio.us and list the bookmarks of both places. I'm using Grails 1.3.9 and the files that I have on my Lib are: Commons-codec-1.3, commons-httpclient-3.0.1 and groovy-all-2.0.1.

The Bookmark Domain:

URL url
String title
String notes

The User Domain:

static hasMany = [bookmarks:Bookmark] 
String login
String password
(...)

bookmarkController - List:

def list = {

   if(!params.max) {
       params.max=10   
   }
def fromDelicious                         
try {
        fromDelicious = deliciousService?.findRecent(session.user)
}
catch(Exception e) {
        println e.message
        e.printStackTrace(System.out)
}

    [ bookmarkInstanceList: Bookmark.findAllByUser(session.user, params), deliciousList: fromDelicious ]
}

bookmarkController - Search

def search = {
    def b = criteria.list { ... }
           def fromDelicious = null
           try {
               fromDelicious = deliciousService.findRecent(session.user)
           }
           catch(Exception e) {
               log.error('Failed to invoke del.icio.us: ' + e.message, e)
           }
        render(view:'list',model:[bookmarkInstanceList:b.unique(),deliciousResults:fromDelicious])}

DeliciousService:

static final API = "https://api.del.icio.us/v1"
static transactional = false

static final EXTRA_BOOKMARKS = {
    xml -> def bookmarks = []
           xml.post.each {
             bookmarks << new Bookmark(title:"${p.@description}", url:new URL("${p.@href}"))            
                }
                return bookmarks
}

List findRecent(User user) {
    return withDelicious(name:"posts/recent",params:[count:5],user:user,EXTRACT_BOOKMARKS)
}

private withDelicious(args,callable) {
    if(!args.user) throw new IllegalArgumentException("Property [user] is required and cannot be null")


    def url = "${API}/${args.name}?"
    args.params?.each {k,v->
        url+="&$k=$v"
    }

    (...)       callable( new XmlSlurper().parse(get.responseBodyAsStream) )        
}

views/bookmark/list

(...)
<g:if test="${deliciousList}"> 
            <h2>Latest from <a href="http://del.icio.us/${session.user.login}" target="_blank">del.icio.us</a></h2>
            <g:set var="edit" value="${false}" />
            <g:render template="bookmark" var="bookmark" collection="${deliciousList}" />               
        </g:if>
        <g:if test="${deliciousResults}">
            <h2>Results from <a href="http://del.icio.us/${session.user.login}" target="_blank">del.icio.us</a></h2>
            <g:render template="bookmark" var="bookmark" collection="${deliciousResults}" />
        </g:if>

When I run the app, in the console it appears this error:

[http-8080-1] ERROR bookmarks.BookmarkController  - Failed to invoke del.icio.us: No signature of method: bookmarks.DeliciousService.findRecent() is applicable for argument types: (bookmarks.User) values: [bookmarks.User : 1] Possible solutions: findResult(groovy.lang.Closure), findResult(java.lang.Object, groovy.lang.Closure)

When I try to list the part from Delicious, the area where it's supposed to appear is empty (which means that the ifs on the views are not going in). I also don't understand what's wrong with the arguments that I send to findRecent().

Rita Dias
  • 29
  • 4
  • Are you sure the User parameter in the findRecent is a bookmarks.User and not a User that comes from any other package? – Fran García Mar 29 '14 at 13:45
  • @FranGarcía I only have one type of user. I'll edit the post to say that a bookmark belongs to a user. But I only call the findRecent where I show on the codes, I'm not sure how could it be anything else besides a bookmarks.User – Rita Dias Mar 29 '14 at 13:51

0 Answers0