<commit_before>package org.cru.godtools.api.packages;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.cru.godtools.api.translations.GodToolsTranslation;
import org.cru.godtools.api.translations.GodToolsTranslationService;
import org.cru.godtools.domain.GodToolsVersion;
import org.cru.godtools.domain.images.Image;
import org.cru.godtools.domain.images.ImageService;
import org.cru.godtools.domain.images.ReferencedImage;
import org.cru.godtools.domain.images.ReferencedImageService;
import org.cru.godtools.domain.languages.LanguageCode;
import org.cru.godtools.domain.packages.PackageStructure;
import org.cru.godtools.domain.packages.PixelDensity;

import javax.enterprise.inject.Default;
import javax.inject.Inject;
import java.util.List;
import java.util.Set;

/**
 * Service which uses lower-level domain services to assemble XML structure files and associated images for
 * a translation of a GodTools package and return the results bundled as a GodToolsPackage.
 *
 * There are services for a specific language & package combo, as well as a service which would load all packages
 * for a language and return them as a Set.
 *
 * Created by ryancarlson on 3/20/14.
 */

@Default
public class GodToolsPackageService
{
	private GodToolsTranslationService godToolsTranslationService;
	private ImageService imageService;
	private ReferencedImageService referencedImageService;

	@Inject
	public GodToolsPackageService(GodToolsTranslationService godToolsTranslationService,ImageService imageService, ReferencedImageService referencedImageService)
	{
		this.godToolsTranslationService = godToolsTranslationService;
		this.imageService = imageService;
		this.referencedImageService = referencedImageService;
	}

	/**
     * Retrieves a specific package in a specific language at a specific revision if revision number is passed, or the latest version if null.
     *
     *
     * @param languageCode
     * @param packageCode
     * @return
     */
    public GodToolsPackage getPackage(LanguageCode languageCode,
                                      String packageCode,
                                      GodToolsVersion godToolsVersion,
                                      Integer minimumInterpreterVersion,
									  boolean includeDrafts,
                                      PixelDensity pixelDensity)
	{
		GodToolsTranslation godToolsTranslation = godToolsTranslationService.getTranslation(languageCode,
				packageCode,
				godToolsVersion);

		return GodToolsPackage.assembleFromComponents(godToolsTranslation,
				loadImages(godToolsTranslation.getPackageStructure()),
				loadIcon(godToolsTranslation.getPackageCode()));
	}

    /**
     * Retrieves all packages for specified language at specified revision
     *
     *
     * @param languageCode
     * @return

     */
    public Set<GodToolsPackage> getPackagesForLanguage(LanguageCode languageCode,
                                                       Integer minimumInterpreterVersion,
													   boolean includeDrafts,
                                                       PixelDensity pixelDensity)
    {
		Set<GodToolsTranslation> godToolsTranslations = godToolsTranslationService.getTranslationsForLanguage(languageCode, includeDrafts);

        Set<GodToolsPackage> godToolsPackages = Sets.newHashSet();

        for(GodToolsTranslation godToolsTranslation : godToolsTranslations)
        {
			godToolsPackages.add(GodToolsPackage.assembleFromComponents(godToolsTranslation,
					loadImages(godToolsTranslation.getPackageStructure()),
					loadIcon(godToolsTranslation.getPackageCode())));
		}

		return godToolsPackages;
    }

	private List<Image> loadImages(PackageStructure packageStructure)
	{
		List<ReferencedImage> referencedImages = referencedImageService.selectByPackageStructureId(packageStructure.getId());

		List<Image> imageList = Lists.newArrayList();

		for(ReferencedImage referencedImage : referencedImages)
		{
			imageList.add(imageService.selectById(referencedImage.getImageId()));
		}

		return imageList;
	}

	private Image loadIcon(String packageCode)
	{
		return imageService.selectByFilename(packageCode + "__" + "en.png");
	}
}<commit_msg>Return the icon now in the packages endpoint<commit_after>package org.cru.godtools.api.packages;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.cru.godtools.api.translations.GodToolsTranslation;
import org.cru.godtools.api.translations.GodToolsTranslationService;
import org.cru.godtools.domain.GodToolsVersion;
import org.cru.godtools.domain.images.Image;
import org.cru.godtools.domain.images.ImageService;
import org.cru.godtools.domain.images.ReferencedImage;
import org.cru.godtools.domain.images.ReferencedImageService;
import org.cru.godtools.domain.languages.LanguageCode;
import org.cru.godtools.domain.packages.PackageStructure;
import org.cru.godtools.domain.packages.PixelDensity;

import javax.enterprise.inject.Default;
import javax.inject.Inject;
import java.util.List;
import java.util.Set;

/**
 * Service which uses lower-level domain services to assemble XML structure files and associated images for
 * a translation of a GodTools package and return the results bundled as a GodToolsPackage.
 *
 * There are services for a specific language & package combo, as well as a service which would load all packages
 * for a language and return them as a Set.
 *
 * Created by ryancarlson on 3/20/14.
 */

@Default
public class GodToolsPackageService
{
	private GodToolsTranslationService godToolsTranslationService;
	private ImageService imageService;
	private ReferencedImageService referencedImageService;

	@Inject
	public GodToolsPackageService(GodToolsTranslationService godToolsTranslationService,ImageService imageService, ReferencedImageService referencedImageService)
	{
		this.godToolsTranslationService = godToolsTranslationService;
		this.imageService = imageService;
		this.referencedImageService = referencedImageService;
	}

	/**
     * Retrieves a specific package in a specific language at a specific revision if revision number is passed, or the latest version if null.
     *
     *
     * @param languageCode
     * @param packageCode
     * @return
     */
    public GodToolsPackage getPackage(LanguageCode languageCode,
                                      String packageCode,
                                      GodToolsVersion godToolsVersion,
                                      Integer minimumInterpreterVersion,
									  boolean includeDrafts,
                                      PixelDensity pixelDensity)
	{
		GodToolsTranslation godToolsTranslation = godToolsTranslationService.getTranslation(languageCode,
				packageCode,
				godToolsVersion);

		return GodToolsPackage.assembleFromComponents(godToolsTranslation,
				loadImages(godToolsTranslation.getPackageStructure()),
				loadIcon(godToolsTranslation.getPackageCode()));
	}

    /**
     * Retrieves all packages for specified language at specified revision
     *
     *
     * @param languageCode
     * @return

     */
    public Set<GodToolsPackage> getPackagesForLanguage(LanguageCode languageCode,
                                                       Integer minimumInterpreterVersion,
													   boolean includeDrafts,
                                                       PixelDensity pixelDensity)
    {
		Set<GodToolsTranslation> godToolsTranslations = godToolsTranslationService.getTranslationsForLanguage(languageCode, includeDrafts);

        Set<GodToolsPackage> godToolsPackages = Sets.newHashSet();

        for(GodToolsTranslation godToolsTranslation : godToolsTranslations)
        {
			godToolsPackages.add(GodToolsPackage.assembleFromComponents(godToolsTranslation,
					loadImages(godToolsTranslation.getPackageStructure()),
					loadIcon(godToolsTranslation.getPackageCode())));
		}

		return godToolsPackages;
    }

	private List<Image> loadImages(PackageStructure packageStructure)
	{
		List<ReferencedImage> referencedImages = referencedImageService.selectByPackageStructureId(packageStructure.getId());

		List<Image> imageList = Lists.newArrayList();

		for(ReferencedImage referencedImage : referencedImages)
		{
			imageList.add(imageService.selectById(referencedImage.getImageId()));
		}

		return imageList;
	}

	private Image loadIcon(String packageCode)
	{
		return imageService.selectByFilename(Image.buildFilename(packageCode, "icon.png"));
	}
}
{'fraction_non_alphanumeric': 0.06987209853150166, 'fraction_numerical': 0.0011842728564661299, 'mean_word_length': 3.7231543624161074, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2279068', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2089, 'n_words': 473}