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());
}
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();
}
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());
}
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();
}
}
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();
}
}
Aggregations