<commit_before>package com.quakearts.approvalengine.web.beans;

import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import com.quakearts.webapp.facelets.base.BaseBean;
import com.quakearts.webapp.orm.query.Range;
import com.quakearts.webapp.orm.query.criteria.CriteriaMapBuilder;
import com.quakearts.webapp.orm.exception.DataStoreException;
import com.quakearts.approvalengine.model.ApprovalProcess;
import com.quakearts.approvalengine.model.Approval;
import com.quakearts.approvalengine.model.ApprovalGroup;

@Named("processPage")
@ViewScoped
public class ApprovalProcessPage extends BaseBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5650031601025364808L;

	private static Logger log = Logger.getLogger(ApprovalProcessPage.class.getName());

	private ApprovalProcess process;
	
	@Inject @Named("approvalapp")
	private ApprovalApplication approvalapp;
	@Inject
	private transient ApprovalProcessFinder finder;
			
	private Range startDateRange = new Range();
	private Range completeDateRange = new Range();
			
	public Range getStartDateRange() {
		return startDateRange;
	}
	
	public Range getCompleteDateRange() {
		return completeDateRange;
	}
	
	public ApprovalApplication getApprovalapp(){
		if(approvalapp == null)
			approvalapp = new ApprovalApplication();
			
		return approvalapp;
	}
	
	public ApprovalProcess getProcess() {
		if(process==null){
			if(hasParameter("process")){
				setProcess(finder.getById(getParameterLong("process")));
				approvalapp.setMode("read");
			} else {
	    		setProcess(new ApprovalProcess());
			}
		}
		
		return process;
	}
    	
	public void setProcess(ApprovalProcess process) {
		this.process = process;
		if(process!=null) {
			ApprovalGroup group = process.getGroup();
			if(group!=null){
				getApprovalGroupDropdownHelper().addToFoundItemsList(group);
			}
			approvals = null;
		}
	}
	
	@Inject
	private ApprovalGroupDropdownHelper approvalGroupDropdownHelper;

	public ApprovalGroupDropdownHelper getApprovalGroupDropdownHelper(){
		return approvalGroupDropdownHelper;
	}
	
	private List<ApprovalProcess> processList;
	
	public List<ApprovalProcess> getProcessList(){
		return processList;
	}
	
	public void findProcess(ActionEvent event){
		CriteriaMapBuilder criteriaBuilder = CriteriaMapBuilder.createCriteria();
		if(process.isApproved()){
			criteriaBuilder.property("approved").mustBeEqualTo(process.isApproved());
		}

		if(process.isComplete()){
			criteriaBuilder.property("complete").mustBeEqualTo(process.isComplete());
		}

		if(process.getCompleteDate() != null){
			criteriaBuilder.property("completeDate").mustBeEqualTo(process.getCompleteDate());
		}

		if(process.getGroup() != null){
			criteriaBuilder.property("group").mustBeEqualTo(process.getGroup());
		}

		if(process.getStartDate() != null){
			criteriaBuilder.property("startDate").mustBeEqualTo(process.getStartDate());
		}

		if(process.isValid()){
			criteriaBuilder.property("valid").mustBeEqualTo(process.isValid());
		}

		try {
			processList = finder.findObjects(criteriaBuilder.finish());
		} catch (DataStoreException e) {
			addError("Search error", "An error occured while searching for Approval Process", FacesContext.getCurrentInstance());
			log.severe("Exception of type " + e.getClass().getName() + " was thrown. Message is " + e.getMessage()
					+ ". Exception occured whiles searching for ApprovalProcess");
		}		
	}
    	
	public void removeProcess(ActionEvent event){
		if(process!=null && processList!=null){
			processList.remove(process);
		}
	}
	
	public boolean isInCreateOrEditMode(){
		return FacesContext.getCurrentInstance().getViewRoot().getViewId().endsWith("create.xhtml") || "edit".equals(approvalapp.getMode());
	}
	
	public boolean isInSearchMode(){
		return FacesContext.getCurrentInstance().getViewRoot().getViewId().endsWith("list.xhtml") 
				&& approvalapp.getMode() == null || approvalapp.getMode().trim().isEmpty();
	}
	
	private List<Approval> approvals;
	
	public List<Approval> getApprovals() {
		if(approvals == null && process != null) {
			approvals = finder.findApprovals(process);
		}
		return approvals;
	}
}<commit_msg>Bug fix: use brackets to ensure sequence of validation<commit_after>package com.quakearts.approvalengine.web.beans;

import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import com.quakearts.webapp.facelets.base.BaseBean;
import com.quakearts.webapp.orm.query.Range;
import com.quakearts.webapp.orm.query.criteria.CriteriaMapBuilder;
import com.quakearts.webapp.orm.exception.DataStoreException;
import com.quakearts.approvalengine.model.ApprovalProcess;
import com.quakearts.approvalengine.model.Approval;
import com.quakearts.approvalengine.model.ApprovalGroup;

@Named("processPage")
@ViewScoped
public class ApprovalProcessPage extends BaseBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5650031601025364808L;

	private static Logger log = Logger.getLogger(ApprovalProcessPage.class.getName());

	private ApprovalProcess process;
	
	@Inject @Named("approvalapp")
	private ApprovalApplication approvalapp;
	@Inject
	private transient ApprovalProcessFinder finder;
			
	private Range startDateRange = new Range();
	private Range completeDateRange = new Range();
			
	public Range getStartDateRange() {
		return startDateRange;
	}
	
	public Range getCompleteDateRange() {
		return completeDateRange;
	}
	
	public ApprovalApplication getApprovalapp(){
		if(approvalapp == null)
			approvalapp = new ApprovalApplication();
			
		return approvalapp;
	}
	
	public ApprovalProcess getProcess() {
		if(process==null){
			if(hasParameter("process")){
				setProcess(finder.getById(getParameterLong("process")));
				approvalapp.setMode("read");
			} else {
	    		setProcess(new ApprovalProcess());
			}
		}
		
		return process;
	}
    	
	public void setProcess(ApprovalProcess process) {
		this.process = process;
		if(process!=null) {
			ApprovalGroup group = process.getGroup();
			if(group!=null){
				getApprovalGroupDropdownHelper().addToFoundItemsList(group);
			}
			approvals = null;
		}
	}
	
	@Inject
	private ApprovalGroupDropdownHelper approvalGroupDropdownHelper;

	public ApprovalGroupDropdownHelper getApprovalGroupDropdownHelper(){
		return approvalGroupDropdownHelper;
	}
	
	private List<ApprovalProcess> processList;
	
	public List<ApprovalProcess> getProcessList(){
		return processList;
	}
	
	public void findProcess(ActionEvent event){
		CriteriaMapBuilder criteriaBuilder = CriteriaMapBuilder.createCriteria();
		if(process.isApproved()){
			criteriaBuilder.property("approved").mustBeEqualTo(process.isApproved());
		}

		if(process.isComplete()){
			criteriaBuilder.property("complete").mustBeEqualTo(process.isComplete());
		}

		if(process.getCompleteDate() != null){
			criteriaBuilder.property("completeDate").mustBeEqualTo(process.getCompleteDate());
		}

		if(process.getGroup() != null){
			criteriaBuilder.property("group").mustBeEqualTo(process.getGroup());
		}

		if(process.getStartDate() != null){
			criteriaBuilder.property("startDate").mustBeEqualTo(process.getStartDate());
		}

		if(process.isValid()){
			criteriaBuilder.property("valid").mustBeEqualTo(process.isValid());
		}

		try {
			processList = finder.findObjects(criteriaBuilder.finish());
		} catch (DataStoreException e) {
			addError("Search error", "An error occured while searching for Approval Process", FacesContext.getCurrentInstance());
			log.severe("Exception of type " + e.getClass().getName() + " was thrown. Message is " + e.getMessage()
					+ ". Exception occured whiles searching for ApprovalProcess");
		}		
	}
    	
	public void removeProcess(ActionEvent event){
		if(process!=null && processList!=null){
			processList.remove(process);
		}
	}
	
	public boolean isInCreateOrEditMode(){
		return FacesContext.getCurrentInstance().getViewRoot().getViewId().endsWith("create.xhtml") || "edit".equals(approvalapp.getMode());
	}
	
	public boolean isInSearchMode(){
		return FacesContext.getCurrentInstance().getViewRoot().getViewId().endsWith("list.xhtml") 
				&& (approvalapp.getMode() == null || approvalapp.getMode().trim().isEmpty());
	}
	
	private List<Approval> approvals;
	
	public List<Approval> getApprovals() {
		if(approvals == null && process != null) {
			approvals = finder.findApprovals(process);
		}
		return approvals;
	}
}
{'fraction_non_alphanumeric': 0.12087912087912088, 'fraction_numerical': 0.004395604395604396, 'mean_word_length': 5.352681851579721, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1896554', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2560, 'n_words': 454}