<commit_before>package gov.nih.nci.ncicb.cadsr.bulkloader.util;

import gov.nih.nci.ncicb.cadsr.bulkloader.beans.CaDSRObjects;
import gov.nih.nci.ncicb.cadsr.bulkloader.beans.LoadObjects;
import gov.nih.nci.ncicb.cadsr.bulkloader.dao.BulkLoaderDAORuntimeException;
import gov.nih.nci.ncicb.cadsr.domain.AdminComponent;
import gov.nih.nci.ncicb.cadsr.domain.AdminComponentClassSchemeClassSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.ClassSchemeClassSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.ClassificationScheme;
import gov.nih.nci.ncicb.cadsr.domain.ClassificationSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.Context;
import gov.nih.nci.ncicb.cadsr.domain.LoaderDefault;
import gov.nih.nci.ncicb.cadsr.loader.ElementsLists;
import gov.nih.nci.ncicb.cadsr.loader.UserSelections;
import gov.nih.nci.ncicb.cadsr.loader.defaults.UMLDefaults;
import gov.nih.nci.ncicb.cadsr.loader.persister.PersisterException;
import gov.nih.nci.ncicb.cadsr.loader.util.PropertyAccessor;
import gov.nih.nci.ncicb.cadsr.loader.util.UserPreferences;

import java.util.Collection;
import java.util.List;

public class UMLLoaderHandler {
	
	private LoaderDefault currentDefault;
	private ElementsLists elements = ElementsLists.getInstance();
	private UMLDefaults defaults = UMLDefaults.getInstance();
	private boolean propertiesLoaded;

	public synchronized void loadElements(CaDSRObjects caDSRObjects, LoadObjects loadObjects) {
		loadDefaultsIfNotLoaded(loadObjects);
		
		List<? extends AdminComponent> adminComponents = caDSRObjects.getList();
		for (AdminComponent adminComponent: adminComponents) {
			elements.addElement(adminComponent);
		}
		
		Context loadContext = loadObjects.getLoadContext();
		elements.addElement(loadContext);
		
		ClassificationScheme loadClassScheme = loadObjects.getLoadClassScheme();			
		elements.addElement(loadClassScheme);
		
		loadComponentDefaults(adminComponents);
		
	}
	
	public synchronized void unLoadElements() {
		elements.clear();
	}
	
	public synchronized void loadDefaultsIfNotLoaded(LoadObjects loadObjects) throws BulkLoaderDAORuntimeException{
		
		if (!propertiesLoaded) {
			try {
				loadPropertiesAndSetFlag(loadObjects);
			} catch (PersisterException e) {
				throw new BulkLoaderDAORuntimeException(e);
			}
		}
		
	}
	
	private void loadPropertiesAndSetFlag(LoadObjects loadObjects) throws PersisterException {
		LoaderDefault loaderDefault = getLoaderDefault(loadObjects);
		
		if (currentDefault == null || !currentDefault.equals(loaderDefault)) {
			currentDefault = loaderDefault;
			
			defaults.useDefaults(loaderDefault);
			defaults.initWithDB();
			
			UserSelections.getInstance().setProperty("ignore-vd", new Boolean(false));
			UserPreferences userPrefs = SpringBeansUtil.getInstance().getUserPreferences();
			userPrefs.setUsePrivateApi(true);
			
			propertiesLoaded = true;
		}<commit_msg>set loadobjects<commit_after>package gov.nih.nci.ncicb.cadsr.bulkloader.util;

import gov.nih.nci.ncicb.cadsr.bulkloader.beans.CaDSRObjects;
import gov.nih.nci.ncicb.cadsr.bulkloader.beans.LoadObjects;
import gov.nih.nci.ncicb.cadsr.bulkloader.dao.BulkLoaderDAORuntimeException;
import gov.nih.nci.ncicb.cadsr.domain.AdminComponent;
import gov.nih.nci.ncicb.cadsr.domain.AdminComponentClassSchemeClassSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.ClassSchemeClassSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.ClassificationScheme;
import gov.nih.nci.ncicb.cadsr.domain.ClassificationSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.Context;
import gov.nih.nci.ncicb.cadsr.domain.LoaderDefault;
import gov.nih.nci.ncicb.cadsr.loader.ElementsLists;
import gov.nih.nci.ncicb.cadsr.loader.UserSelections;
import gov.nih.nci.ncicb.cadsr.loader.defaults.UMLDefaults;
import gov.nih.nci.ncicb.cadsr.loader.persister.PersisterException;
import gov.nih.nci.ncicb.cadsr.loader.util.PropertyAccessor;
import gov.nih.nci.ncicb.cadsr.loader.util.UserPreferences;

import java.util.Collection;
import java.util.List;

public class UMLLoaderHandler {
	
	private LoaderDefault currentDefault;
	private ElementsLists elements = ElementsLists.getInstance();
	private UMLDefaults defaults = UMLDefaults.getInstance();
	private boolean propertiesLoaded;
	private static LoadObjects loadObjects;

	
	public static LoadObjects getLoadObjects() {
		return loadObjects;
	}

	public synchronized void loadElements(CaDSRObjects caDSRObjects, LoadObjects loadObjects) {
		loadDefaultsIfNotLoaded(loadObjects);
		
		List<? extends AdminComponent> adminComponents = caDSRObjects.getList();
		for (AdminComponent adminComponent: adminComponents) {
			elements.addElement(adminComponent);
		}
		
		Context loadContext = loadObjects.getLoadContext();
		elements.addElement(loadContext);
		
		ClassificationScheme loadClassScheme = loadObjects.getLoadClassScheme();			
		elements.addElement(loadClassScheme);
		
		loadComponentDefaults(adminComponents);
		
	}
	
	public synchronized void unLoadElements() {
		elements.clear();
	}
	
	public synchronized void loadDefaultsIfNotLoaded(LoadObjects loadObjects) throws BulkLoaderDAORuntimeException{
		
		if (!propertiesLoaded) {
			try {
				loadPropertiesAndSetFlag(loadObjects);
			} catch (PersisterException e) {
				throw new BulkLoaderDAORuntimeException(e);
			}
		}
		
	}
	
	private void loadPropertiesAndSetFlag(LoadObjects _loadObjects) throws PersisterException {
		loadObjects = _loadObjects;
		LoaderDefault loaderDefault = getLoaderDefault(_loadObjects);
		
		if (currentDefault == null || !currentDefault.equals(loaderDefault)) {
			currentDefault = loaderDefault;
			
			defaults.useDefaults(loaderDefault);
			defaults.initWithDB();
			
			UserSelections.getInstance().setProperty("ignore-vd", new Boolean(false));
			UserPreferences userPrefs = SpringBeansUtil.getInstance().getUserPreferences();
			userPrefs.setUsePrivateApi(true);
			
			propertiesLoaded = true;
		}
{'fraction_non_alphanumeric': 0.09643891634009201, 'fraction_numerical': 0.0, 'mean_word_length': 5.754890678941312, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2897789', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1843, 'n_words': 273}