Search in sources :

Example 1 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class MergeableRepository method mergeRepositories.

/**
     * This method merges multiple application sources into a single list of
     * category dtos. For this it receives a map, containing a binding between
     * all application sources and their category dto lists, and an array
     * containing all application sources that should be merged in the correct
     * order. While merging the application source it prioritizes a later
     * application source over an earlier one. This means, that if two
     * application sources contain the same script, the script from the later
     * application source is taken.
     *
     * @param categoriesMap A map containing a binding between the application sources and
     *                      their category dtos
     * @param repositories  A list containing all application sources in the order in
     *                      which they should be merged
     * @return A list containing category dtos of the merged application
     * sources. If no application sources were given, an empty list is
     * returned
     */
protected List<CategoryDTO> mergeRepositories(Map<Repository, List<CategoryDTO>> categoriesMap, List<Repository> repositories) {
    int numberOfRepositories = repositories.size();
    if (numberOfRepositories == 0) {
        return Collections.emptyList();
    }
    /*
         * Take the first application source, from behind, as the default one
         */
    final Map<String, CategoryDTO> mergedCategories = createSortedMap(categoriesMap.get(repositories.get(numberOfRepositories - 1)), CategoryDTO::getName);
    for (int otherRepositoryIndex = numberOfRepositories - 2; otherRepositoryIndex >= 0; otherRepositoryIndex--) {
        final List<CategoryDTO> otherCategories = categoriesMap.get(repositories.get(otherRepositoryIndex));
        final Map<String, CategoryDTO> otherCategoriesMap = createSortedMap(otherCategories, CategoryDTO::getName);
        for (String categoryName : otherCategoriesMap.keySet()) {
            final CategoryDTO category = otherCategoriesMap.get(categoryName);
            if (mergedCategories.containsKey(categoryName)) {
                mergedCategories.put(categoryName, mergeCategories(mergedCategories.get(categoryName), category));
            } else {
                mergedCategories.put(categoryName, category);
            }
        }
    }
    return new ArrayList<>(mergedCategories.values());
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO)

Example 2 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class MergeableRepository method mergeCategories.

protected CategoryDTO mergeCategories(CategoryDTO leftCategory, CategoryDTO rightCategory) {
    final Map<String, ApplicationDTO> leftApplications = createSortedMap(leftCategory.getApplications(), ApplicationDTO::getName);
    final Map<String, ApplicationDTO> rightApplications = createSortedMap(rightCategory.getApplications(), ApplicationDTO::getName);
    final SortedMap<String, ApplicationDTO> mergedApps = new TreeMap<>(rightApplications);
    for (String applicationName : leftApplications.keySet()) {
        final ApplicationDTO application = leftApplications.get(applicationName);
        if (mergedApps.containsKey(applicationName)) {
            mergedApps.put(applicationName, mergeApplications(mergedApps.get(applicationName), application));
        } else {
            mergedApps.put(applicationName, application);
        }
    }
    final List<ApplicationDTO> applications = new ArrayList<>(mergedApps.values());
    applications.sort(ApplicationDTO.nameComparator());
    return new CategoryDTO.Builder().withApplications(applications).withType(leftCategory.getType()).withIcon(leftCategory.getIcon()).withName(leftCategory.getName()).build();
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO)

Example 3 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class FilterRepository method fetchInstallableApplications.

@Override
public List<CategoryDTO> fetchInstallableApplications() {
    final OperatingSystem currentOperatingSystem = operatingSystemFetcher.fetchCurrentOperationSystem();
    final List<CategoryDTO> categories = repository.fetchInstallableApplications();
    return categories.stream().map(category -> {
        final List<ApplicationDTO> applications = new ArrayList<>();
        for (ApplicationDTO application : category.getApplications()) {
            List<ScriptDTO> scripts = application.getScripts();
            if (!enforceIncompatibleOperatingSystems) {
                scripts = application.getScripts().stream().filter(script -> script.getCompatibleOperatingSystems() == null || script.getCompatibleOperatingSystems().contains(currentOperatingSystem)).collect(Collectors.toList());
            }
            if (!scripts.isEmpty()) {
                applications.add(new ApplicationDTO.Builder(application).withScripts(scripts).build());
            }
        }
        return new CategoryDTO.Builder(category).withApplications(applications).build();
    }).filter(category -> !category.getApplications().isEmpty()).collect(Collectors.toList());
}
Also used : OperatingSystem(org.phoenicis.entities.OperatingSystem) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) List(java.util.List) OperatingSystem(org.phoenicis.entities.OperatingSystem) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) Collectors(java.util.stream.Collectors) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ArrayList(java.util.ArrayList) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) ArrayList(java.util.ArrayList)

Example 4 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class ClasspathRepository method buildCategory.

private CategoryDTO buildCategory(String categoryFileName) throws IOException {
    final String jsonCategoryFile = packagePath + "/" + categoryFileName + "/category.json";
    final CategoryDTO categoryDTO = objectMapper.readValue(getClass().getResourceAsStream(jsonCategoryFile), CategoryDTO.class);
    try {
        return new CategoryDTO.Builder(categoryDTO).withIcon(new URI(packagePath + "/" + categoryFileName + "/icon.png")).withApplications(buildApplications(categoryFileName)).build();
    } catch (URISyntaxException e) {
        LOGGER.warn("Invalid icon path", e);
        return new CategoryDTO.Builder(categoryDTO).withApplications(buildApplications(categoryFileName)).build();
    }
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class ClasspathRepository method fetchInstallableApplications.

@Override
public List<CategoryDTO> fetchInstallableApplications() {
    try {
        final List<CategoryDTO> categoryDTOs = new ArrayList<>();
        Resource[] resources = resourceResolver.getResources(packagePath + "/*");
        for (Resource resource : resources) {
            final CategoryDTO category = buildCategory(resource.getFilename());
            if (!category.getApplications().isEmpty()) {
                categoryDTOs.add(category);
            }
        }
        Collections.sort(categoryDTOs, Comparator.comparing(CategoryDTO::getName));
        return categoryDTOs;
    } catch (IOException e) {
        LOGGER.warn("Error while reading resource directory", e);
        return Collections.emptyList();
    }
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Aggregations

CategoryDTO (org.phoenicis.repository.dto.CategoryDTO)24 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 ApplicationDTO (org.phoenicis.repository.dto.ApplicationDTO)8 File (java.io.File)7 URI (java.net.URI)7 Path (java.nio.file.Path)6 TypeDTO (org.phoenicis.repository.dto.TypeDTO)6 List (java.util.List)5 HashMap (java.util.HashMap)4 Collections (java.util.Collections)3 Optional (java.util.Optional)3 Consumer (java.util.function.Consumer)3 EngineCategoryDTO (org.phoenicis.engines.dto.EngineCategoryDTO)3 EngineSubCategoryDTO (org.phoenicis.engines.dto.EngineSubCategoryDTO)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Map (java.util.Map)2