Search in sources :

Example 21 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.

the class ClasspathRepository method buildApplication.

private ApplicationDTO buildApplication(String typeId, String categoryId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
    try {
        final String applicationDirectory = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName;
        File applicationJson = new File(applicationDirectory, "application.json");
        final ApplicationDTO applicationDTO = objectMapper.readValue(getClass().getResourceAsStream(applicationJson.getAbsolutePath()), ApplicationDTO.class);
        ApplicationDTO.Builder applicationDTOBuilder = new ApplicationDTO.Builder(applicationDTO).withTypeId(typeId).withCategoryId(categoryId).withId(applicationFileName);
        applicationDTOBuilder.withScripts(buildScripts(applicationDTOBuilder.getTypeId(), applicationDTOBuilder.getCategoryId(), applicationDTOBuilder.getId(), typeFileName, categoryFileName, applicationFileName)).withMiniatures(buildMiniatures(typeFileName, categoryFileName, applicationFileName));
        return applicationDTOBuilder.build();
    } catch (IOException e) {
        throw new RepositoryException("Could not build application", e);
    }
}
Also used : RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException) File(java.io.File)

Example 22 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.

the class ClasspathRepository method buildType.

private TypeDTO buildType(String typeFileName) throws RepositoryException {
    try {
        final String jsonTypePath = packagePath + "/" + typeFileName + "/type.json";
        final URL jsonTypeFile = getClass().getResource(jsonTypePath);
        if (jsonTypeFile != null) {
            final TypeDTO typeDTO = objectMapper.readValue(jsonTypeFile, TypeDTO.class);
            TypeDTO.Builder typeDTOBuilder = new TypeDTO.Builder(typeDTO).withId(typeFileName);
            typeDTOBuilder.withCategories(buildCategories(typeDTOBuilder.getId(), typeFileName)).build();
            try {
                typeDTOBuilder.withIcon(new URI(packagePath + "/" + typeFileName + "/icon.png"));
            } catch (URISyntaxException e) {
                LOGGER.warn("Invalid icon path", e);
            }
            return typeDTOBuilder.build();
        } else {
            LOGGER.debug(String.format("type.json %s for classpath repository does not exist", jsonTypePath));
            return new TypeDTO.Builder().build();
        }
    } catch (IOException e) {
        throw new RepositoryException("Could not build type", e);
    }
}
Also used : RepositoryException(org.phoenicis.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL)

Example 23 with RepositoryException

use of org.phoenicis.repository.RepositoryException 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)

Example 24 with RepositoryException

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

the class ClasspathRepository method buildCategories.

private List<CategoryDTO> buildCategories(String typeId, String typeFileName) throws RepositoryException {
    try {
        final String categoryScanClassPath = packagePath + "/" + typeFileName;
        Resource[] resources = resourceResolver.getResources(categoryScanClassPath + "/*");
        final List<CategoryDTO> categoryDTOS = new ArrayList<>();
        for (Resource resource : resources) {
            final String fileName = resource.getFilename();
            if (!"icon.png".equals(fileName) && !"category.json".equals(fileName)) {
                final CategoryDTO category = buildCategory(typeId, typeFileName, fileName);
                if (!category.getApplications().isEmpty()) {
                    categoryDTOS.add(category);
                }
            }
        }
        categoryDTOS.sort(Comparator.comparing(CategoryDTO::getName));
        return categoryDTOS;
    } catch (IOException e) {
        throw new RepositoryException("Could not build categories", e);
    }
}
Also used : Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException)

Example 25 with RepositoryException

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

the class ClasspathRepository method buildMiniatures.

private List<URI> buildMiniatures(String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
    try {
        final String applicationScanClassPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName + "/miniatures/";
        Resource[] resources = resourceResolver.getResources(applicationScanClassPath + "/*");
        return Arrays.stream(resources).map(resource -> {
            final String resourceFile = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName + "/miniatures/" + resource.getFilename();
            try {
                return getClass().getResource(resourceFile).toURI();
            } catch (URISyntaxException e) {
                return null;
            }
        }).collect(Collectors.toList());
    } catch (IOException e) {
        throw new RepositoryException("Could not build miniatures", e);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) LoggerFactory(org.slf4j.LoggerFactory) IOUtils(org.apache.commons.compress.utils.IOUtils) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) IOException(java.io.IOException) org.phoenicis.repository.dto(org.phoenicis.repository.dto) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) URI(java.net.URI) Comparator(java.util.Comparator) RepositoryException(org.phoenicis.repository.RepositoryException) Resource(org.springframework.core.io.Resource) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) RepositoryException(org.phoenicis.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

RepositoryException (org.phoenicis.repository.RepositoryException)34 IOException (java.io.IOException)32 URI (java.net.URI)12 URISyntaxException (java.net.URISyntaxException)12 URL (java.net.URL)12 ArrayList (java.util.ArrayList)12 Resource (org.springframework.core.io.Resource)12 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)11 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)11 ToStringBuilder (org.apache.commons.lang.builder.ToStringBuilder)11 File (java.io.File)9 InputStream (java.io.InputStream)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FileInputStream (java.io.FileInputStream)3 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IOUtils (org.apache.commons.compress.utils.IOUtils)3 StringUtils (org.apache.commons.lang.StringUtils)3