<commit_before>package org.sanelib.eboss.core.activities.employee;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

@Component
public class CheckEmployeeDuplicationDelegate implements JavaDelegate {

	@Override
	public void execute(DelegateExecution execution) throws Exception {
		System.out.println("Checking employee for duplication");
	}
}
<commit_msg>Applying check for duplication of employee code and employee mail address.<commit_after>package org.sanelib.eboss.core.activities.employee;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.sanelib.eboss.core.commands.employee.AddEmployee;
import org.sanelib.eboss.core.commands.employee.UpdateEmployee;
import org.sanelib.eboss.core.dao.EmployeeRepository;
import org.sanelib.eboss.core.domain.entity.Employee;
import org.sanelib.eboss.core.exceptions.AppException;
import org.sanelib.eboss.core.exceptions.ProcessError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Component
public class CheckEmployeeDuplicationDelegate implements JavaDelegate {

    @Autowired
    EmployeeRepository employeeRepository;

    @Autowired
    ProcessError processError;

    @Override
	public void execute(DelegateExecution execution) throws Exception {
		System.out.println("Checking employee for duplication");

        Object command = execution.getVariable("command");

        Integer existingEmployeeId = (command instanceof UpdateEmployee) ? ((UpdateEmployee) command).getId() : null;

        //Code duplication check
        String employeeCode = ((AddEmployee) command).getCode();

        List<Employee> employees = employeeRepository.findByColumnAndValue("code", employeeCode);

        if(!employees.isEmpty() && !Objects.equals(existingEmployeeId, employees.get(0).getId())){
            processError.addError("common.field.duplicate", "code", Arrays.asList("domain.employee.name", "domain.employee.code"), employeeCode);
        }

        //Email duplication check
        String emailAddress = ((AddEmployee) command).getEmail();

        employees = employeeRepository.findByColumnAndValue("email", emailAddress);

        if(!employees.isEmpty() && !Objects.equals(existingEmployeeId, employees.get(0).getId())){
            processError.addError("common.field.duplicate", "email", Arrays.asList("domain.employee.name", "domain.employee.email"), emailAddress);
        }

        if(!processError.isValid()){
            throw new AppException(processError);
        }
    }
}

{'fraction_non_alphanumeric': 0.10816696914700545, 'fraction_numerical': 0.0007259528130671506, 'mean_word_length': 4.814345991561181, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5330771', 'n_tokens_mistral': 755, 'n_tokens_neox': 722, 'n_words': 138}