Skip to content

Instantly share code, notes, and snippets.

@m-hatch
Created October 26, 2017 20:55
Show Gist options
  • Save m-hatch/7b09ef5685f991ed33d6afd04cddbc8b to your computer and use it in GitHub Desktop.
Save m-hatch/7b09ef5685f991ed33d6afd04cddbc8b to your computer and use it in GitHub Desktop.

Revisions

  1. m-hatch created this gist Oct 26, 2017.
    69 changes: 69 additions & 0 deletions ArtistsListComponent.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    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<ArtistTheme> themes = null;
    List<Artist> artists = null;
    List<ArtistCountry> 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);
    }

    }

    }