<commit_before>package com.blackducksoftware.integration.hub.dataservices.extension.transformer;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.blackducksoftware.integration.hub.api.extension.ConfigurationItem;
import com.blackducksoftware.integration.hub.api.extension.ExtensionRestService;
import com.blackducksoftware.integration.hub.api.user.UserItem;
import com.blackducksoftware.integration.hub.dataservices.ItemTransform;
import com.blackducksoftware.integration.hub.dataservices.extension.item.UserConfigItem;
import com.blackducksoftware.integration.hub.exception.BDRestException;
import com.blackducksoftware.integration.hub.exception.HubItemTransformException;
import com.blackducksoftware.integration.hub.exception.MissingUUIDException;

public class UserConfigTransform implements ItemTransform<List<UserConfigItem>, UserItem> {
	private String extensionId;
	private final ExtensionRestService extensionRestService;

	public UserConfigTransform(final ExtensionRestService extensionRestService) {
		this.extensionRestService = extensionRestService;
	}

	@Override
	public List<UserConfigItem> transform(final UserItem item) throws HubItemTransformException {
		try {
			if (!item.isActive()) {
				return Collections.emptyList();
			} else {
				final LinkedList<UserConfigItem> itemList = new LinkedList<>();
				final Map<String, ConfigurationItem> configItems = getUserConfigOptions(extensionId, item);
				itemList.add(new UserConfigItem(item, configItems));
				return itemList;
			}
		} catch (final IOException | URISyntaxException | BDRestException | MissingUUIDException e) {
			throw new HubItemTransformException("Error processing user config for extension", e);
		}
	}

	private Map<String, ConfigurationItem> getUserConfigOptions(final String extensionId, final UserItem user)
			throws IOException, URISyntaxException, BDRestException, MissingUUIDException {
		final String userId = user.getUserId().toString();
		final List<ConfigurationItem> userItemList = extensionRestService.getUserConfiguration(extensionId, userId);
		final Map<String, ConfigurationItem> itemMap = createConfigMap(userItemList);
		return itemMap;
	}

	private Map<String, ConfigurationItem> createConfigMap(final List<ConfigurationItem> itemList) {<commit_msg>Minor update to list initialization <commit_after>package com.blackducksoftware.integration.hub.dataservices.extension.transformer;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blackducksoftware.integration.hub.api.extension.ConfigurationItem;
import com.blackducksoftware.integration.hub.api.extension.ExtensionRestService;
import com.blackducksoftware.integration.hub.api.user.UserItem;
import com.blackducksoftware.integration.hub.dataservices.ItemTransform;
import com.blackducksoftware.integration.hub.dataservices.extension.item.UserConfigItem;
import com.blackducksoftware.integration.hub.exception.BDRestException;
import com.blackducksoftware.integration.hub.exception.HubItemTransformException;
import com.blackducksoftware.integration.hub.exception.MissingUUIDException;

public class UserConfigTransform implements ItemTransform<List<UserConfigItem>, UserItem> {
	private String extensionId;
	private final ExtensionRestService extensionRestService;

	public UserConfigTransform(final ExtensionRestService extensionRestService) {
		this.extensionRestService = extensionRestService;
	}

	@Override
	public List<UserConfigItem> transform(final UserItem item) throws HubItemTransformException {
		try {
			if (!item.isActive()) {
				return Collections.emptyList();
			} else {
				final Map<String, ConfigurationItem> configItems = getUserConfigOptions(extensionId, item);
				final List<UserConfigItem> itemList = new ArrayList<>(configItems.size());
				itemList.add(new UserConfigItem(item, configItems));
				return itemList;
			}
		} catch (final IOException | URISyntaxException | BDRestException | MissingUUIDException e) {
			throw new HubItemTransformException("Error processing user config for extension", e);
		}
	}

	private Map<String, ConfigurationItem> getUserConfigOptions(final String extensionId, final UserItem user)
			throws IOException, URISyntaxException, BDRestException, MissingUUIDException {
		final String userId = user.getUserId().toString();
		final List<ConfigurationItem> userItemList = extensionRestService.getUserConfiguration(extensionId, userId);
		final Map<String, ConfigurationItem> itemMap = createConfigMap(userItemList);
		return itemMap;
	}

	private Map<String, ConfigurationItem> createConfigMap(final List<ConfigurationItem> itemList) {
{'fraction_non_alphanumeric': 0.0835214446952596, 'fraction_numerical': 0.0, 'mean_word_length': 7.10981697171381, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '2503794', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1286, 'n_words': 271}