package us.jyg.freshet.service;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import us.jyg.freshet.Constants;
import us.jyg.freshet.engine.SongQ;
import us.jyg.freshet.engine.DatabaseBuilder;
import us.jyg.freshet.dao.model.Song;
import us.jyg.freshet.dao.model.SongAttribute;
import us.jyg.freshet.dao.model.User;
import us.jyg.freshet.dao.model.Guest;
import us.jyg.freshet.manager.AlbumManager;
import us.jyg.freshet.manager.ArtistManager;
import us.jyg.freshet.manager.GenreManager;
import us.jyg.freshet.manager.SongManager;
import us.jyg.freshet.web.form.FreshetForm;
public class BrowseDisplayService {
private final Log log = LogFactory.getLog(getClass());
public void setBrowseGenresDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseGenresDisplay");
ff.setBrowseItems(new ArrayList<SongAttribute>(genreManager.getGenres()));
ff.setBrowseType(""+Constants.BROWSE_GENRES);
ff.setNextBrowseType(""+Constants.BROWSE_GENRE);
ff.setUser((user==null)?new Guest():user);
log.debug("exiting setBrowseGenresDisplay");
}
public void setBrowseGenreDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseGenreDisplay");
Integer genreId = new Integer(ff.getBrowseId());
ff.setBrowseItems(new ArrayList<SongAttribute>(artistManager.getArtistsbyGenre(genreId)));
ff.setBrowseGenre(genreManager.getGenre(genreId));
ff.setBrowseType(Constants.BROWSE_GENRE);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_ARTIST);
}
public void setBrowseArtistsDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseArtistsDisplay");
ff.setBrowseItems(new ArrayList<SongAttribute>(artistManager.getArtists()));
ff.setBrowseType(Constants.BROWSE_ARTISTS);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_ARTIST);
}
public void setBrowseArtistDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseArtistDisplay");
Integer artistId = new Integer(ff.getBrowseId());
ff.setBrowseArtist(artistManager.getArtist(artistId));
Song song0 = (Song)songManager.getSongs(ff.getBrowseArtist()).get(0);
ff.setBrowseGenre(song0.getGenre());
ff.setBrowseItems(new ArrayList<SongAttribute>(albumManager.getAlbumsbyArtist(artistId)));
ff.setBrowseType(Constants.BROWSE_ARTIST);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_ALBUM);
}
public void setBrowseAlbumDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseAlbumDisplay");
Integer albumId = new Integer(ff.getBrowseId());
ff.setBrowseAlbum(albumManager.getAlbum(albumId));
ff.setBrowseItems(songManager.getSongs(ff.getBrowseAlbum()));
Song song0 = (Song)ff.getBrowseItems().get(0);
ff.setBrowseGenre(song0.getGenre());
ff.setBrowseArtist(song0.getArtist());
ff.setBrowseType(Constants.BROWSE_ALBUM);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_SONG);
}
public void setBrowseSearchDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseSearchDisplay");
List<Song> songs = new ArrayList<Song>();
if (ff.getSearchTerm() != null || !"".equals(ff.getSearchTerm())) {
songs = songManager.findSongs(ff.getSearchTerm());
}
ff.setBrowseItems(songs);
ff.setBrowseType(Constants.BROWSE_SEARCH);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_SONG);
}
public void setBrowseHistoryDisplay(FreshetForm ff, User user) {
log.debug("entering setBrowseSearchDisplay");
ff.setBrowseItems(songQ.getHistory());
ff.setBrowseType(Constants.BROWSE_HISTORY);
ff.setUser((user==null)?new Guest():user);
ff.setNextBrowseType(Constants.BROWSE_SONG);
}
public void seek() {
(new DatabaseBuilder()).seek(songManager);
}
// INJECTED MANAGERS ========================================================
GenreManager genreManager;
public void setGenreManager(GenreManager genreManager) {
this.genreManager = genreManager;
}
ArtistManager artistManager;
public void setArtistManager(ArtistManager artistManager) {
this.artistManager = artistManager;
}
AlbumManager albumManager;
public void setAlbumManager(AlbumManager albumManager) {
this.albumManager = albumManager;
}
SongManager songManager;
public void setSongManager(SongManager songManager) {
this.songManager = songManager;
}
SongQ songQ;
public void setSongQ(SongQ songQ) {
this.songQ = songQ;
}
}