package org.acm.artists.components; import java.util.List; import org.acm.components.BaseComponent; import org.acm.artists.common.dao.ArtistsDao; import org.acm.artists.common.domain.Artist; import org.acm.artists.common.domain.ArtistCountry; import org.acm.artists.common.domain.ArtistTheme; import org.acm.artists.componentinfo.ArtistsListComponentInfo; import org.hippoecm.hst.core.component.HstComponentException; import org.hippoecm.hst.core.component.HstRequest; import org.hippoecm.hst.core.component.HstResponse; import org.hippoecm.hst.core.parameters.ParametersInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @ParametersInfo(type = ArtistsListComponentInfo.class) public class ArtistsListComponent extends BaseComponent { private static Logger log = LoggerFactory.getLogger(ArtistsComponent.class); @Override public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException { super.doBeforeRender(request, response); ArtistsListComponentInfo info = getComponentParametersInfo(request); String heading = (info.getHeading() != null) ? info.getHeading() : ""; List themes = null; List artists = null; List countries = null; try { ArtistsDao artistsDao = new ArtistsDao(); if(info.getShowThemes()){ themes = artistsDao.getAllThemes().getList(); log.info("****Got [{}] themes", themes.size()); } if(info.getShowArtists()){ artists = artistsDao.getAllArtists().getList(); for(Artist artist: artists){ String lower = artist.getArtistLastName().toLowerCase(); artist.setArtistLastName(lower); } log.info("****Got [{}] artists", artists.size()); } if(info.getShowCountries()){ countries = artistsDao.getAllCountries().getList(); log.info("****Got [{}] countries", countries.size()); } request.setAttribute("heading", heading); request.setAttribute("themes", themes); request.setAttribute("artists", artists); request.setAttribute("countries", countries); } catch (Exception e) { log.error("Error trying to get ArtistsListComponent", e); } finally { request.setAttribute("info", info); } } }