Package com.pugh.sockso.web.action.api

Source Code of com.pugh.sockso.web.action.api.ArtistRelatedAction

package com.pugh.sockso.web.action.api;

import com.pugh.sockso.cache.CacheException;
import com.pugh.sockso.templates.api.TArtists;
import com.pugh.sockso.web.BadRequestException;
import com.pugh.sockso.web.RelatedArtists;
import com.pugh.sockso.web.Request;

import com.google.inject.Inject;

import java.io.IOException;
import java.sql.SQLException;

public class ArtistRelatedAction extends BaseApiAction {

    private final RelatedArtists relatedArtists;

    @Inject
    public ArtistRelatedAction( final RelatedArtists relatedArtists ) {
       
        this.relatedArtists = relatedArtists;

    }

    /**
     *  Shows artists related to the specified one
     *
     */

    @Override
    public void handleRequest() throws BadRequestException, SQLException, IOException, CacheException {

        final int artistId = Integer.parseInt( getRequest().getUrlParam(2) );

        TArtists tpl = new TArtists();
        tpl.setArtists( relatedArtists.getRelatedArtistsFor(artistId) );

        getResponse().showJson( tpl.makeRenderer() );
    }

    /**
     *  Indicates if this action can handle the request
     *
     *  @param req
     *
     *  @return
     *
     */
   
    @Override
    public boolean canHandle( final Request req ) {
       
        return req.getUrlParam( 1 ).equals( "artists" )
            && isInteger( req.getUrlParam(2) )
            && req.getUrlParam( 3 ).equals( "related" );
       
    }
   
}
TOP

Related Classes of com.pugh.sockso.web.action.api.ArtistRelatedAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.