class TargetTypesServiceImpl implements TargetTypesService {

	@Override
	public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) {
		Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes);
		List<TargetTypesDetails> attributes = Lists.newArrayList(); 
		List<TargetTypes> allTargets = targetTypesRepository.findAll();
		for (TargetTypes targetType : allTargets) {
			String targetName = targetType.getTargetName().trim();
			Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase());
			if(index==null) {
				String dataSourceName = targetType.getDataSourceName().trim();
				TargetTypesDetails targetTypeAttribute = new TargetTypesDetails();
				targetTypeAttribute.setAttributes(Lists.newArrayList());
				targetTypeAttribute.setTargetName(targetType.getTargetName().trim());
				targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName));
				targetTypeAttribute.setIncludeAll(false);
				attributes.add(targetTypeAttribute);
			} else {
				String dataSourceName = targetType.getDataSourceName().trim();
				TargetTypesDetails targetTypeAttribute = new TargetTypesDetails();
				targetTypeAttribute.setTargetName(targetType.getTargetName().trim());
				targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName));
				attributes.add(targetTypeAttribute);
			}
		}
		return attributes;
	}

}