<commit_before>package com.breakersoft.plow.service;

import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.breakersoft.plow.Depend;
import com.breakersoft.plow.FrameRange;
import com.breakersoft.plow.Job;
import com.breakersoft.plow.Layer;
import com.breakersoft.plow.Task;
import com.breakersoft.plow.dao.DependDao;
import com.breakersoft.plow.dao.JobDao;
import com.breakersoft.plow.dao.LayerDao;
import com.breakersoft.plow.dao.TaskDao;
import com.breakersoft.plow.thrift.DependSpecT;
import com.google.common.collect.Sets;

@Service
@Transactional
public class DependServiceImpl implements DependService {

    private Logger logger = org.slf4j.LoggerFactory.getLogger(DependServiceImpl.class);

    @Autowired
    JobDao jobDao;

    @Autowired
    LayerDao layerDao;

    @Autowired
    TaskDao taskDao;

    @Autowired
    DependDao dependDao;

    public Depend createDepend(DependSpecT spec) {

        Job dependentJob;
        Job dependOnJob;
        Layer dependentLayer;
        Layer dependOnLayer;
        Task dependentTask;
        Task dependOnTask;

        Depend depend = null;

        switch(spec.getType()) {

        case JOB_ON_JOB:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            depend = dependDao.createJobOnJob(dependentJob, dependOnJob);
            break;

        case LAYER_ON_LAYER:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            dependentLayer = layerDao.get(dependentJob, spec.dependentLayer);
            dependOnLayer = layerDao.get(dependOnJob, spec.dependOnLayer);
            depend = dependDao.createLayerOnLayer(dependentLayer, dependOnLayer);
            break;

        case LAYER_ON_TASK:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependentLayer = layerDao.get(dependentJob, spec.dependentLayer);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            dependOnTask = taskDao.getByNameOrId(dependOnJob, spec.dependOnTask);
            depend = dependDao.createLayerOnTask(dependentLayer, dependOnTask);
            break;

        case TASK_ON_LAYER:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependentTask = taskDao.getByNameOrId(dependentJob, spec.dependentTask);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            dependOnLayer = layerDao.get(dependOnJob, spec.dependOnLayer);
            depend = dependDao.createTaskOnLayer(dependentTask, dependOnLayer);
            break;

        case TASK_ON_TASK:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependentTask = taskDao.getByNameOrId(dependentJob, spec.dependentTask);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            dependOnTask = taskDao.getByNameOrId(dependOnJob, spec.dependOnTask);
            depend = dependDao.createTaskOnTask(dependentTask, dependOnTask);
            break;

        case TASK_BY_TASK:
            dependentJob = jobDao.getByActiveNameOrId(spec.dependentJob);
            dependOnJob = jobDao.getByActiveNameOrId(spec.dependOnJob);
            dependentLayer = layerDao.get(dependentJob, spec.dependentLayer);
            dependOnLayer = layerDao.get(dependOnJob, spec.dependOnLayer);
            createTaskByTask(dependentLayer, dependOnLayer);
            break;
        }

        if (depend != null) {
            dependDao.incrementDependCounts(depend);
        }
        return depend;
    }

    @Override
    public boolean satisfyDepend(Depend depend) {
        if (dependDao.satisfyDepend(depend)) {
            dependDao.decrementDependCounts(depend);
            return true;<commit_msg>Added non null/empty string checks on dependency setups.<commit_after>package com.breakersoft.plow.service;

import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.breakersoft.plow.util.PlowUtils.checkEmpty;

import com.breakersoft.plow.Depend;
import com.breakersoft.plow.FrameRange;
import com.breakersoft.plow.Job;
import com.breakersoft.plow.Layer;
import com.breakersoft.plow.Task;
import com.breakersoft.plow.dao.DependDao;
import com.breakersoft.plow.dao.JobDao;
import com.breakersoft.plow.dao.LayerDao;
import com.breakersoft.plow.dao.TaskDao;
import com.breakersoft.plow.thrift.DependSpecT;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;

@Service
@Transactional
public class DependServiceImpl implements DependService {

    private Logger logger = org.slf4j.LoggerFactory.getLogger(DependServiceImpl.class);

    @Autowired
    JobDao jobDao;

    @Autowired
    LayerDao layerDao;

    @Autowired
    TaskDao taskDao;

    @Autowired
    DependDao dependDao;

    public Depend createDepend(DependSpecT spec) {

        Job dependentJob;
        Job dependOnJob;
        Layer dependentLayer;
        Layer dependOnLayer;
        Task dependentTask;
        Task dependOnTask;

        Depend depend = null;

        switch(spec.getType()) {

        case JOB_ON_JOB:
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            depend = dependDao.createJobOnJob(dependentJob, dependOnJob);
            break;

        case LAYER_ON_LAYER:
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            dependentLayer = layerDao.get(dependentJob,
                    checkEmpty(spec.dependentLayer));
            dependOnLayer = layerDao.get(dependOnJob,
                    checkEmpty(spec.dependOnLayer));
            depend = dependDao.createLayerOnLayer(dependentLayer, dependOnLayer);
            break;

        case LAYER_ON_TASK:
            logger.info(spec.dependentJob);
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependentLayer = layerDao.get(dependentJob,
                    checkEmpty(spec.dependentLayer));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            dependOnTask = taskDao.getByNameOrId(dependOnJob,
                    checkEmpty(spec.dependOnTask));
            depend = dependDao.createLayerOnTask(dependentLayer, dependOnTask);
            break;

        case TASK_ON_LAYER:
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependentTask = taskDao.getByNameOrId(dependentJob,
                    checkEmpty(spec.dependentTask));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            dependOnLayer = layerDao.get(dependOnJob,
                    checkEmpty(spec.dependOnLayer));
            depend = dependDao.createTaskOnLayer(dependentTask, dependOnLayer);
            break;

        case TASK_ON_TASK:
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependentTask = taskDao.getByNameOrId(dependentJob,
                    checkEmpty(spec.dependentTask));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            dependOnTask = taskDao.getByNameOrId(dependOnJob,
                    checkEmpty(spec.dependOnTask));
            depend = dependDao.createTaskOnTask(dependentTask, dependOnTask);
            break;

        case TASK_BY_TASK:
            dependentJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependentJob));
            dependOnJob = jobDao.getByActiveNameOrId(
                    checkEmpty(spec.dependOnJob));
            dependentLayer = layerDao.get(dependentJob,
                    checkEmpty(spec.dependentLayer));
            dependOnLayer = layerDao.get(dependOnJob,
                    checkEmpty(spec.dependOnLayer));
            createTaskByTask(dependentLayer, dependOnLayer);
            break;
        }

        if (depend != null) {
            dependDao.incrementDependCounts(depend);
        }
        return depend;
    }

    @Override
    public boolean satisfyDepend(Depend depend) {
        if (dependDao.satisfyDepend(depend)) {
            dependDao.decrementDependCounts(depend);
            return true;
{'fraction_non_alphanumeric': 0.08024691358024691, 'fraction_numerical': 0.0004409171075837742, 'mean_word_length': 2.6190666134822496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5013887', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2582, 'n_words': 392}