<commit_before>package com.worth.ifs.finance.handler.item;

import com.worth.ifs.finance.domain.Cost;
import com.worth.ifs.finance.resource.category.LabourCostCategory;
import com.worth.ifs.finance.resource.cost.CostItem;
import com.worth.ifs.finance.resource.cost.LabourCost;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindingResult;

import java.util.ArrayList;
import java.util.List;

/**
 * Handles the labour costs, i.e. converts the costs to be stored into the database
 * or for sending it over.
 */
public class LabourCostHandler extends CostHandler {
    private static final Log LOG = LogFactory.getLog(LabourCostHandler.class);
    public static final String COST_KEY = "labour";

    @Override
    public void validate(CostItem costItem, BindingResult bindingResult) {
        LabourCost labourCost = (LabourCost) costItem;
        if(StringUtils.isNotEmpty(labourCost.getName()) && labourCost.getName().equals(LabourCostCategory.WORKING_DAYS_KEY)){
            super.validate(costItem, bindingResult, LabourCost.YearlyWorkingDays.class);
        }else{
            super.validate(costItem, bindingResult);
        }
    }

    @Override
    public Cost toCost(CostItem costItem) {
        Cost cost = null;
        if (costItem instanceof LabourCost) {
            LabourCost labourCostItem = (LabourCost) costItem;
            cost = new Cost(labourCostItem.getId(), labourCostItem.getName(), labourCostItem.getRole(), labourCostItem.getDescription(), labourCostItem.getLabourDays(), labourCostItem.getGrossAnnualSalary(), null, null);
        }
        return cost;
    }

    @Override
    public CostItem toCostItem(Cost cost) {
        return new LabourCost(cost.getId(), cost.getName(), cost.getItem(), cost.getCost(), cost.getQuantity(), cost.getDescription());
    }

    @Override
    public List<Cost> initializeCost() {
        ArrayList<Cost> costs = new ArrayList<>();
        costs.add(initializeWorkingDays());
        return costs;
    }

    private Cost initializeWorkingDays() {
        String description = LabourCostCategory.WORKING_DAYS_PER_YEAR;
        Integer labourDays = null;
        LabourCost costItem = new LabourCost(null, LabourCostCategory.WORKING_DAYS_KEY, null, null, labourDays, description);
        return toCost(costItem);
    }
}<commit_msg>INFUND-2961 initialise the working days per year 232<commit_after>package com.worth.ifs.finance.handler.item;

import com.worth.ifs.finance.domain.Cost;
import com.worth.ifs.finance.resource.category.LabourCostCategory;
import com.worth.ifs.finance.resource.cost.CostItem;
import com.worth.ifs.finance.resource.cost.LabourCost;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindingResult;

import java.util.ArrayList;
import java.util.List;

/**
 * Handles the labour costs, i.e. converts the costs to be stored into the database
 * or for sending it over.
 */
public class LabourCostHandler extends CostHandler {
    private static final Log LOG = LogFactory.getLog(LabourCostHandler.class);
    public static final String COST_KEY = "labour";
    public static final Integer DEFAULT_WORKING_DAYS = 232;

    @Override
    public void validate(CostItem costItem, BindingResult bindingResult) {
        LabourCost labourCost = (LabourCost) costItem;
        if(StringUtils.isNotEmpty(labourCost.getName()) && labourCost.getName().equals(LabourCostCategory.WORKING_DAYS_KEY)){
            super.validate(costItem, bindingResult, LabourCost.YearlyWorkingDays.class);
        }else{
            super.validate(costItem, bindingResult);
        }
    }

    @Override
    public Cost toCost(CostItem costItem) {
        Cost cost = null;
        if (costItem instanceof LabourCost) {
            LabourCost labourCostItem = (LabourCost) costItem;
            cost = new Cost(labourCostItem.getId(), labourCostItem.getName(), labourCostItem.getRole(), labourCostItem.getDescription(), labourCostItem.getLabourDays(), labourCostItem.getGrossAnnualSalary(), null, null);
        }
        return cost;
    }

    @Override
    public CostItem toCostItem(Cost cost) {
        return new LabourCost(cost.getId(), cost.getName(), cost.getItem(), cost.getCost(), cost.getQuantity(), cost.getDescription());
    }

    @Override
    public List<Cost> initializeCost() {
        ArrayList<Cost> costs = new ArrayList<>();
        costs.add(initializeWorkingDays());
        return costs;
    }

    private Cost initializeWorkingDays() {
        String description = LabourCostCategory.WORKING_DAYS_PER_YEAR;
        Integer labourDays = DEFAULT_WORKING_DAYS;
        LabourCost costItem = new LabourCost(null, LabourCostCategory.WORKING_DAYS_KEY, null, null, labourDays, description);
        return toCost(costItem);
    }
}
{'fraction_non_alphanumeric': 0.10070635721493441, 'fraction_numerical': 0.0024217961654894047, 'mean_word_length': 3.793036750483559, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5221597', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1378, 'n_words': 311}