<commit_before>package com.atlassian.jira.plugins.dvcs.scheduler;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.atlassian.jira.plugins.dvcs.model.Organization;
import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.OrganizationService;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import com.atlassian.sal.api.scheduling.PluginJob;

public class DvcsSchedulerJob implements PluginJob
{
    private static final Logger log = LoggerFactory.getLogger(DvcsSchedulerJob.class);

    @Override
    public void execute(Map<String, Object> jobDataMap)
    {
        log.debug("Running DvcsSchedulerJob ");

        OrganizationService organizationService = (OrganizationService) jobDataMap.get("organizationService");
        RepositoryService repositoryService = (RepositoryService) jobDataMap.get("repositoryService");
        syncOrganizations(organizationService, repositoryService);
        cleanOrphanRepositories(organizationService, repositoryService);
    }

    /**
     * Synchronizes all organizations.
     * 
     * @param organizationService
     * @param repositoryService
     */
    private void syncOrganizations(OrganizationService organizationService, RepositoryService repositoryService)
    {
        List<Organization> organizations = organizationService.getAll(false);
        for (Organization organization : organizations)
        {
            repositoryService.syncRepositoryList(organization);
        }
    }

    /**
     * Cleans orphan repositories - repositories mark as deleted with not existing organization.
     * 
     * @param organizationService
     * @param repositoryService
     */
    private void cleanOrphanRepositories(OrganizationService organizationService, RepositoryService repositoryService)
    {
        List<Repository> orphanRepositories = new LinkedList<Repository>();
        for (Repository repository : repositoryService.getAllRepositories(true))
        {
            if (repository.isDeleted() && organizationService.get(repository.getOrganizationId(), false) == null)
            {
                orphanRepositories.add(repository);
            }
        }
        repositoryService.removeOrphanRepositories(orphanRepositories);
    }

}<commit_msg>Changeset was moved to issue/BBC-531_v1.4.1<commit_after>package com.atlassian.jira.plugins.dvcs.scheduler;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.atlassian.jira.plugins.dvcs.model.Organization;
import com.atlassian.jira.plugins.dvcs.service.OrganizationService;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import com.atlassian.sal.api.scheduling.PluginJob;

public class DvcsSchedulerJob implements PluginJob
{
    private static final Logger log = LoggerFactory.getLogger(DvcsSchedulerJob.class);

	@Override
    public void execute(Map<String, Object> jobDataMap)
    {   
		log.debug("Running DvcsSchedulerJob ");
		
		OrganizationService organizationService = (OrganizationService) jobDataMap.get("organizationService");
		RepositoryService repositoryService = (RepositoryService) jobDataMap.get("repositoryService");
		List<Organization> organizations = organizationService.getAll(false);
		for (Organization organization : organizations)
        {
			repositoryService.syncRepositoryList(organization);
        }
    }
	
}
{'fraction_non_alphanumeric': 0.08758915834522112, 'fraction_numerical': 0.0028530670470756064, 'mean_word_length': 4.201780415430267, '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': '6351666', 'n_tokens_mistral': 977, 'n_tokens_neox': 939, 'n_words': 167}