<commit_before>package lt.baraksoft.summersystem.portal.controller;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import lt.baraksoft.summersystem.portal.helper.ReservationPaymentHelper;
import lt.baraksoft.summersystem.portal.view.ReservationView;
import lt.baraksoft.summersystem.portal.view.UserView;
import org.primefaces.context.RequestContext;

import lt.baraksoft.summersystem.dao.model.SummerhouseSearch;
import lt.baraksoft.summersystem.portal.helper.SummerhouseViewHelper;
import lt.baraksoft.summersystem.portal.view.SummerhouseView;

/**
 * Created by etere on 2016-04-27.
 */
@Named
@SessionScoped
@Stateful
public class SearchController implements Serializable {

	private static final long serialVersionUID = 7491298817566550329L;

	@EJB
	private SummerhouseViewHelper summerhouseViewHelper;

	@Inject
	private UserLoginController userLoginController;

    @EJB
    private ReservationPaymentHelper reservationPaymentHelper;

	private List<SummerhouseView> list;
    private List<ReservationView> reservations;
	private SummerhouseSearch searchObject;
	private SummerhouseView selectedSummerhouse;
	private Date dateFrom;
	private Date dateTo;
	private Date today;
	private boolean visibleResults;
    private UserView loggedUser;

	@PostConstruct
	public void init() {
		searchObject = new SummerhouseSearch();
		today = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
		visibleResults = false;
        loggedUser = userLoginController.getLoggedUser();
	}

	public void makeSelectedSummerhouse(SummerhouseView summerhouse) {
		selectedSummerhouse = summerhouse;
        reservations = reservationPaymentHelper.getReservationsBySummerhouse(selectedSummerhouse.getId());
	}

	public String doSelectSummerhouse() {
        loggedUser = userLoginController.getLoggedUser();
		if (selectedSummerhouse.getPrice().intValue() > loggedUser.getPoints()) {
			FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Klaida", "Nepakanka pinigų rezervacijai");
			FacesContext.getCurrentInstance().addMessage(null, msg);
		}
        else if (loggedUser.getValidTo() == null || loggedUser.getValidTo().isBefore(LocalDate.now())) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Klaida", "Sumokėkite metinį narystės mokestį");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
        else {
			return "/reservationPaymentProcess.xhtml?faces-redirect=true";
		}
		return "";
	}

    private void createErrorMessage(String first, String second) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, first, second);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

	public void doUpdateSummerhouseList() {
        if (dateFrom == null || dateTo == null){
            createErrorMessage("Klaida", "Nepasirinkote datos");
            list = null;
        }
		else if (dateFrom.after(dateTo)){
            createErrorMessage("Klaida", "Pasirinktas neteisingas laikotarpis");
            list = null;
        }
        else{
            searchObject.setDateFrom(dateFrom != null ? dateFrom.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            searchObject.setDateTo(dateTo != null ? dateTo.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            list = summerhouseViewHelper.search(searchObject);
            visibleResults = !list.isEmpty();
            RequestContext context = RequestContext.getCurrentInstance();
            context.scrollTo("form2:cars");
        }
	}

	public Date getToday() {
		return today;
	}

	public void setToday(Date today) {
		this.today = today;
	}

	public boolean isVisibleResults() {
		return visibleResults;
	}

	public void setVisibleResults(boolean visibleResults) {
		this.visibleResults = visibleResults;
	}
<commit_msg>User entity fields added<commit_after>package lt.baraksoft.summersystem.portal.controller;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import lt.baraksoft.summersystem.portal.helper.ReservationPaymentHelper;
import lt.baraksoft.summersystem.portal.view.ReservationView;
import lt.baraksoft.summersystem.portal.view.UserView;
import org.primefaces.context.RequestContext;

import lt.baraksoft.summersystem.dao.model.SummerhouseSearch;
import lt.baraksoft.summersystem.portal.helper.SummerhouseViewHelper;
import lt.baraksoft.summersystem.portal.view.SummerhouseView;

/**
 * Created by etere on 2016-04-27.
 */
@Named
@SessionScoped
@Stateful
public class SearchController implements Serializable {

	private static final long serialVersionUID = 7491298817566550329L;

	@EJB
	private SummerhouseViewHelper summerhouseViewHelper;

	@Inject
	private UserLoginController userLoginController;

    @EJB
    private ReservationPaymentHelper reservationPaymentHelper;

	private List<SummerhouseView> list;
    private List<ReservationView> reservations;
	private SummerhouseSearch searchObject;
	private SummerhouseView selectedSummerhouse;
	private Date dateFrom;
	private Date dateTo;
	private Date today;
	private boolean visibleResults;
    private UserView loggedUser;

	@PostConstruct
	public void init() {
		searchObject = new SummerhouseSearch();
		today = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
		visibleResults = false;
        loggedUser = userLoginController.getLoggedUser();
	}

	public void makeSelectedSummerhouse(SummerhouseView summerhouse) {
		selectedSummerhouse = summerhouse;
        reservations = reservationPaymentHelper.getReservationsBySummerhouse(selectedSummerhouse.getId());
	}

	public String doSelectSummerhouse() {
        loggedUser = userLoginController.getLoggedUser();
		if (selectedSummerhouse.getPrice().intValue() > loggedUser.getPoints()) {
			FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Klaida", "Nepakanka pinigų rezervacijai");
			FacesContext.getCurrentInstance().addMessage(null, msg);
		}
        else if (loggedUser.getValidTo() == null || loggedUser.getValidTo().isBefore(LocalDate.now())) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Klaida", "Sumokėkite metinį narystės mokestį");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
        else {
			return "/reservationPaymentProcess.xhtml?faces-redirect=true";
		}
		return "";
	}

    private void createErrorMessage(String first, String second) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, first, second);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

	public void doUpdateSummerhouseList() {
		if (dateFrom != null && dateTo != null && dateFrom.after(dateTo)){
            createErrorMessage("Klaida", "Pasirinktas neteisingas laikotarpis");
            list = null;
        }
        else{
            searchObject.setDateFrom(dateFrom != null ? dateFrom.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            searchObject.setDateTo(dateTo != null ? dateTo.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            list = summerhouseViewHelper.search(searchObject);
            visibleResults = !list.isEmpty();
            RequestContext context = RequestContext.getCurrentInstance();
            context.scrollTo("form2:cars");
        }
	}

	public Date getToday() {
		return today;
	}

	public void setToday(Date today) {
		this.today = today;
	}

	public boolean isVisibleResults() {
		return visibleResults;
	}

	public void setVisibleResults(boolean visibleResults) {
		this.visibleResults = visibleResults;
	}

{'fraction_non_alphanumeric': 0.09844746660247924, 'fraction_numerical': 0.006739679865206402, 'mean_word_length': 4.562248995983936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3639915', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2417, 'n_words': 464}