Search in sources :

Example 1 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle in project phoenicis by PhoenicisOrg.

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 repositoriesMap A map containing a binding between the application sources and
 *                      their repository DTO
 * @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 RepositoryDTO mergeRepositories(Map<Repository, RepositoryDTO> repositoriesMap, List<Repository> repositories) {
    int numberOfRepositories = repositories.size();
    if (numberOfRepositories == 0) {
        return null;
    }
    RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName("merged repository");
    Properties translationProperties = new Properties();
    Map<Repository, List<TypeDTO>> typesMap = new HashMap<>();
    for (Map.Entry<Repository, RepositoryDTO> entry : repositoriesMap.entrySet()) {
        RepositoryDTO repositoryDTO = entry.getValue();
        translationProperties.putAll(repositoryDTO.getTranslations().getProperties());
        typesMap.put(entry.getKey(), repositoryDTO.getTypes());
    }
    repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(translationProperties).build());
    Localisation.setAdditionalTranslations(new PropertiesResourceBundle(translationProperties));
    /*
         * Take the first application source, from behind, as the default one
         */
    final Map<String, TypeDTO> mergedTypes = createSortedMap(typesMap.get(repositories.get(numberOfRepositories - 1)), TypeDTO::getId);
    for (int otherRepositoryIndex = numberOfRepositories - 2; otherRepositoryIndex >= 0; otherRepositoryIndex--) {
        final List<TypeDTO> otherTypes = typesMap.get(repositories.get(otherRepositoryIndex));
        final Map<String, TypeDTO> otherTypesMap = createSortedMap(otherTypes, TypeDTO::getId);
        for (Map.Entry<String, TypeDTO> entry : otherTypesMap.entrySet()) {
            final TypeDTO type = entry.getValue();
            if (mergedTypes.containsKey(entry.getKey())) {
                mergedTypes.put(entry.getKey(), mergeTypes(mergedTypes.get(entry.getKey()), type));
            } else {
                mergedTypes.put(entry.getKey(), type);
            }
        }
    }
    RepositoryDTO mergedRepositoryDTO = repositoryDTOBuilder.withTypes(new ArrayList<>(mergedTypes.values())).build();
    return mergedRepositoryDTO;
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle)

Example 2 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle 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 repositoriesMap A map containing a binding between the application sources and
 *            their repository DTO
 * @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 RepositoryDTO mergeRepositories(Map<Repository, RepositoryDTO> repositoriesMap, List<Repository> repositories) {
    int numberOfRepositories = repositories.size();
    if (numberOfRepositories == 0) {
        return null;
    }
    RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName("merged repository");
    Properties translationProperties = new Properties();
    Map<Repository, List<TypeDTO>> typesMap = new HashMap<>();
    for (Map.Entry<Repository, RepositoryDTO> entry : repositoriesMap.entrySet()) {
        RepositoryDTO repositoryDTO = entry.getValue();
        translationProperties.putAll(repositoryDTO.getTranslations().getProperties());
        typesMap.put(entry.getKey(), repositoryDTO.getTypes());
    }
    repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(translationProperties).build());
    Localisation.setAdditionalTranslations(new PropertiesResourceBundle(translationProperties));
    /*
         * Take the first application source, from behind, as the default one
         */
    final Map<String, TypeDTO> mergedTypes = createSortedMap(typesMap.get(repositories.get(numberOfRepositories - 1)), TypeDTO::getId);
    for (int otherRepositoryIndex = numberOfRepositories - 2; otherRepositoryIndex >= 0; otherRepositoryIndex--) {
        final List<TypeDTO> otherTypes = typesMap.get(repositories.get(otherRepositoryIndex));
        final Map<String, TypeDTO> otherTypesMap = createSortedMap(otherTypes, TypeDTO::getId);
        for (Map.Entry<String, TypeDTO> entry : otherTypesMap.entrySet()) {
            final TypeDTO type = entry.getValue();
            if (mergedTypes.containsKey(entry.getKey())) {
                mergedTypes.put(entry.getKey(), mergeTypes(mergedTypes.get(entry.getKey()), type));
            } else {
                mergedTypes.put(entry.getKey(), type);
            }
        }
    }
    RepositoryDTO mergedRepositoryDTO = repositoryDTOBuilder.withTypes(new ArrayList<>(mergedTypes.values())).build();
    return mergedRepositoryDTO;
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle)

Example 3 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle in project POL-POM-5 by PhoenicisOrg.

the class LocalRepository method fetchInstallableApplications.

@Override
public RepositoryDTO fetchInstallableApplications() {
    if (!repositoryDirectory.exists()) {
        throw new RepositoryException(String.format("Repository %s directory does not exist.", repositoryDirectory));
    }
    final File[] typeDirectories = repositoryDirectory.listFiles();
    if (typeDirectories == null) {
        return new RepositoryDTO.Builder().build();
    }
    LOGGER.info("Reading directory : " + repositoryDirectory);
    final RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName(repositoryDirectory.getName()).withTypes(fetchTypes(typeDirectories));
    final File i18nDirectory = new File(repositoryDirectory, "i18n");
    if (i18nDirectory.exists()) {
        final File[] translationFiles = i18nDirectory.listFiles((dir, name) -> name.endsWith(Locale.getDefault().getLanguage() + ".properties"));
        Properties mergedProperties = new Properties();
        for (File translationFile : translationFiles) {
            try {
                Properties langProperties = new Properties();
                langProperties.load(new FileInputStream(translationFile));
                mergedProperties.putAll(langProperties);
            } catch (IOException e) {
                LOGGER.error("Could not read translation properties", e);
            }
        }
        repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(mergedProperties).build());
        Localisation.setAdditionalTranslations(new PropertiesResourceBundle(mergedProperties));
    }
    return repositoryDTOBuilder.build();
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle in project POL-POM-5 by PhoenicisOrg.

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 repositoriesMap A map containing a binding between the application sources and
 *            their repository DTO
 * @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 RepositoryDTO mergeRepositories(Map<Repository, RepositoryDTO> repositoriesMap, List<Repository> repositories) {
    int numberOfRepositories = repositories.size();
    if (numberOfRepositories == 0) {
        return null;
    }
    RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName("merged repository");
    Properties translationProperties = new Properties();
    Map<Repository, List<TypeDTO>> typesMap = new HashMap<>();
    for (Map.Entry<Repository, RepositoryDTO> entry : repositoriesMap.entrySet()) {
        RepositoryDTO repositoryDTO = entry.getValue();
        translationProperties.putAll(repositoryDTO.getTranslations().getProperties());
        typesMap.put(entry.getKey(), repositoryDTO.getTypes());
    }
    repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(translationProperties).build());
    Localisation.setAdditionalTranslations(new PropertiesResourceBundle(translationProperties));
    /*
         * Take the first application source, from behind, as the default one
         */
    final Map<String, TypeDTO> mergedTypes = createSortedMap(typesMap.get(repositories.get(numberOfRepositories - 1)), TypeDTO::getId);
    for (int otherRepositoryIndex = numberOfRepositories - 2; otherRepositoryIndex >= 0; otherRepositoryIndex--) {
        final List<TypeDTO> otherTypes = typesMap.get(repositories.get(otherRepositoryIndex));
        final Map<String, TypeDTO> otherTypesMap = createSortedMap(otherTypes, TypeDTO::getId);
        for (Map.Entry<String, TypeDTO> entry : otherTypesMap.entrySet()) {
            final TypeDTO type = entry.getValue();
            if (mergedTypes.containsKey(entry.getKey())) {
                mergedTypes.put(entry.getKey(), mergeTypes(mergedTypes.get(entry.getKey()), type));
            } else {
                mergedTypes.put(entry.getKey(), type);
            }
        }
    }
    RepositoryDTO mergedRepositoryDTO = repositoryDTOBuilder.withTypes(new ArrayList<>(mergedTypes.values())).build();
    return mergedRepositoryDTO;
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle)

Example 5 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle in project phoenicis by PhoenicisOrg.

the class LocalRepository method fetchInstallableApplications.

@Override
public RepositoryDTO fetchInstallableApplications() {
    if (!repositoryDirectory.exists()) {
        throw new RepositoryException(String.format("Repository %s directory does not exist.", repositoryDirectory));
    }
    final File[] typeDirectories = repositoryDirectory.listFiles();
    if (typeDirectories == null) {
        return new RepositoryDTO.Builder().build();
    }
    LOGGER.info("Reading directory : " + repositoryDirectory);
    final RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName(repositoryDirectory.getName()).withTypes(fetchTypes(typeDirectories));
    final File i18nDirectory = new File(repositoryDirectory, "i18n");
    if (i18nDirectory.exists()) {
        final File[] translationFiles = i18nDirectory.listFiles((dir, name) -> name.endsWith(Locale.getDefault().getLanguage() + ".properties"));
        Properties mergedProperties = new Properties();
        for (File translationFile : translationFiles) {
            try {
                Properties langProperties = new Properties();
                langProperties.load(new FileInputStream(translationFile));
                mergedProperties.putAll(langProperties);
            } catch (IOException e) {
                LOGGER.error("Could not read translation properties", e);
            }
        }
        repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(mergedProperties).build());
        Localisation.setAdditionalTranslations(new PropertiesResourceBundle(mergedProperties));
    }
    return repositoryDTOBuilder.build();
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

PropertiesResourceBundle (org.phoenicis.configuration.localisation.PropertiesResourceBundle)6 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)3 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)3 ToStringBuilder (org.apache.commons.lang.builder.ToStringBuilder)3 RepositoryException (org.phoenicis.repository.RepositoryException)3