Package su.mauser.service

Source Code of su.mauser.service.SelectPageServiceImpl

package su.mauser.service;

import java.util.List;

import spark.QueryParamsMap;
import su.mauser.dao.DatabaseDAO;
import su.mauser.view.FilmsView;
import su.mauser.view.ListPageView;
import su.mauser.view.SelectPageView;

import com.mongodb.DB;
import com.mongodb.DBObject;

/**
* Сервис выбора/поиска фильма.
*
* @author sibiev
*
*/
public class SelectPageServiceImpl
{
  private final DatabaseDAO dao;
  private final DB db;
  private SelectPageView selectPageView;

  public SelectPageServiceImpl(DB db)
  {
    this.db = db;
    dao = new DatabaseDAO(db);
  }

  public void setSelectPageView(SelectPageView selectPageView)
  {
    this.selectPageView = selectPageView;
  }

  public SelectPageView getSelectPageView()
  {
    selectPageView = new SelectPageView();

    selectPageView.setDirectors(dao.getDistinctValues("director"));
    selectPageView.setActors(dao.getDistinctValues("actors"));
    selectPageView.setNames(dao.getDistinctValues("name"));
    selectPageView.setJanrs(dao.getDistinctValues("janr"));
    selectPageView.setYears(dao.getDistinctYearValues());

    return selectPageView;
  }

  /**
   * Получение результатов поиска.
   *
   * @param queryMap
   *            параметры поиска.
   * @return Выбранный фильм.
   */
  public SelectPageView getSelectPageViewWithResult(QueryParamsMap queryMap)
  {
    SelectPageView selectPageView = getSelectPageView();

    List<DBObject> searchResult = dao.findBySearchCriteria(queryMap);

    ListPageServiceImpl listPageService = new ListPageServiceImpl(db);
    ListPageView listPageView = listPageService.getView(searchResult);

    // выделить в тексте искомую строку
    if (queryMap.get("descriptions").hasValue())
    {
      String search = queryMap.get("descriptions").values()[0];

      for (FilmsView filmsView : listPageView.getFilmsView())
      {
        String description = filmsView.getDescription();
        String marked = description.replaceAll(search, "<span class='marked'>" + search + "</span>");
        filmsView.setDescription(marked);
      }
    }

    selectPageView.setSearchResults(listPageView.getFilmsView());

    return selectPageView;
  }

}
TOP

Related Classes of su.mauser.service.SelectPageServiceImpl

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.