Search in sources :

Example 11 with CategoryDTO

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

the class EnginesController method setDefaultEngineIcons.

/**
 * Generates css for the button design associated with the given categories
 *
 * @param categoryDTOS The categories
 */
private void setDefaultEngineIcons(List<CategoryDTO> categoryDTOS) {
    try {
        StringBuilder cssBuilder = new StringBuilder();
        for (CategoryDTO category : categoryDTOS) {
            cssBuilder.append("#" + category.getName().toLowerCase() + "Button{\n");
            URI categoryIcon = category.getIcon();
            if (categoryIcon == null) {
                cssBuilder.append("-fx-background-image: url('/org/phoenicis/javafx/views/common/phoenicis.png');\n");
            } else {
                cssBuilder.append("-fx-background-image: url('" + categoryIcon + "');\n");
            }
            cssBuilder.append("}\n");
        }
        String css = cssBuilder.toString();
        Path temp = Files.createTempFile("defaultEngineIcons", ".css").toAbsolutePath();
        File tempFile = temp.toFile();
        tempFile.deleteOnExit();
        Files.write(temp, css.getBytes());
        String defaultEngineIconsCss = temp.toUri().toString();
        themeManager.setDefaultEngineIconsCss(defaultEngineIconsCss);
    } catch (IOException e) {
        LOGGER.warn("Could not set default engine icons.", e);
    }
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) Path(java.nio.file.Path) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 12 with CategoryDTO

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

the class Repository method getApplication.

default default ApplicationDTO getApplication(List<String> path) {
    final CategoryDTO categoryDTO = getCategory(path);
    if (categoryDTO == null) {
        return null;
    }
    final Optional<ApplicationDTO> applicationDTO = categoryDTO.getApplications().stream().filter(application -> path.get(1).equals(application.getName())).findFirst();
    return applicationDTO.orElse(null);
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Consumer(java.util.function.Consumer) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) List(java.util.List) Optional(java.util.Optional) Collections(java.util.Collections) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO)

Example 13 with CategoryDTO

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

the class GitRepository method fetchInstallableApplications.

@Override
public synchronized List<CategoryDTO> fetchInstallableApplications() {
    LOGGER.info(String.format("Begin fetching process of git-repository '%s' in '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
    boolean folderExists = gitRepositoryLocation.exists();
    // check that the repository folder exists
    if (!folderExists) {
        LOGGER.info(String.format("Creating new folder '%s' for git-repository '%s'", gitRepositoryLocation.getAbsolutePath(), this.gitRepositoryUri));
        if (!gitRepositoryLocation.mkdirs()) {
            LOGGER.error(String.format("Couldn't create folder for git repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            return Collections.emptyList();
        }
    }
    List<CategoryDTO> result = Collections.emptyList();
    try {
        Git gitRepository = null;
        /*
             * if the repository folder previously didn't exist, clone the
             * repository now
             */
        if (!folderExists) {
            LOGGER.info(String.format("Cloning git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository = Git.cloneRepository().setURI(this.gitRepositoryUri.toString()).setDirectory(gitRepositoryLocation).call();
        } else /*
             * otherwise open the folder and pull the newest updates from the
             * repository
             */
        {
            LOGGER.info(String.format("Opening git-repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository = Git.open(gitRepositoryLocation);
            LOGGER.info(String.format("Pulling new commits from git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository.pull().call();
        }
        // close repository to free resources
        gitRepository.close();
        result = localRepositoryFactory.createInstance(this.gitRepositoryLocation, this.gitRepositoryUri).fetchInstallableApplications();
    } catch (RepositoryNotFoundException | GitAPIException e) {
        LOGGER.error(String.format("Folder '%s' is no git-repository", gitRepositoryLocation.getAbsolutePath()), e);
    } catch (IOException e) {
        LOGGER.error(String.format("An unknown error occured", e));
    }
    return result;
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException)

Example 14 with CategoryDTO

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

the class EnginesController method populateView.

private void populateView(RepositoryDTO repositoryDTO) {
    Platform.runLater(() -> {
        List<CategoryDTO> categoryDTOS = new ArrayList<>();
        for (TypeDTO typeDTO : repositoryDTO.getTypes()) {
            if (typeDTO.getId().equals("Engines")) {
                categoryDTOS = typeDTO.getCategories();
            }
        }
        setDefaultEngineIcons(categoryDTOS);
        enginesSource.fetchAvailableEngines(categoryDTOS, versions -> Platform.runLater(() -> this.enginesView.populate(versions)));
    });
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) ArrayList(java.util.ArrayList) TypeDTO(org.phoenicis.repository.dto.TypeDTO)

Example 15 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project phoenicis by PhoenicisOrg.

the class AppsController method setDefaultCategoryIcons.

private void setDefaultCategoryIcons(List<CategoryDTO> categoryDTOS) {
    try {
        StringBuilder cssBuilder = new StringBuilder();
        for (CategoryDTO category : categoryDTOS) {
            cssBuilder.append("#" + category.getId().toLowerCase() + "Button{\n");
            URI categoryIcon = category.getIcon();
            if (categoryIcon == null) {
                cssBuilder.append("-fx-background-image: url('/org/phoenicis/javafx/views/common/phoenicis.png');\n");
            } else {
                cssBuilder.append("-fx-background-image: url('" + categoryIcon + "');\n");
            }
            cssBuilder.append("}\n");
        }
        String css = cssBuilder.toString();
        Path temp = Files.createTempFile("defaultCategoryIcons", ".css").toAbsolutePath();
        File tempFile = temp.toFile();
        tempFile.deleteOnExit();
        Files.write(temp, css.getBytes());
        String defaultCategoryIconsCss = temp.toUri().toString();
        themeManager.setDefaultCategoryIconsCss(defaultCategoryIconsCss);
    } catch (IOException e) {
        LOGGER.warn("Could not set default category icons.", e);
    }
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Path(java.nio.file.Path) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Aggregations

CategoryDTO (org.phoenicis.repository.dto.CategoryDTO)27 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 ApplicationDTO (org.phoenicis.repository.dto.ApplicationDTO)10 File (java.io.File)7 URI (java.net.URI)7 Path (java.nio.file.Path)6 List (java.util.List)6 TypeDTO (org.phoenicis.repository.dto.TypeDTO)6 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 EngineCategoryDTO (org.phoenicis.engines.dto.EngineCategoryDTO)4 EngineSubCategoryDTO (org.phoenicis.engines.dto.EngineSubCategoryDTO)4 ApplicationsFeaturePanel (org.phoenicis.javafx.components.application.control.ApplicationsFeaturePanel)4 Collections (java.util.Collections)3 Consumer (java.util.function.Consumer)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