use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
the class ClasspathRepository method buildScripts.
private List<ScriptDTO> buildScripts(String typeId, String categoryId, String applicationId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
try {
final String applicationScanClassPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName;
Resource[] resources = resourceResolver.getResources(applicationScanClassPath + "/*");
final List<ScriptDTO> scriptDTOs = new ArrayList<>();
for (Resource resource : resources) {
final String fileName = resource.getFilename();
if (!"resources".equals(fileName) && !"miniatures".equals(fileName) && !"application.json".equals(fileName)) {
final ScriptDTO script = buildScript(typeId, categoryId, applicationId, typeFileName, categoryFileName, applicationFileName, fileName);
scriptDTOs.add(script);
}
}
scriptDTOs.sort(Comparator.comparing(ScriptDTO::getScriptName));
return scriptDTOs;
} catch (IOException e) {
throw new RepositoryException("Could not build scripts", e);
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
the class ClasspathRepository method buildCategory.
private CategoryDTO buildCategory(String typeId, String typeFileName, String categoryFileName) throws RepositoryException {
try {
final String jsonCategoryPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/category.json";
final URL jsonCategoryFile = getClass().getResource(jsonCategoryPath);
if (jsonCategoryFile != null) {
final CategoryDTO categoryDTO = objectMapper.readValue(jsonCategoryFile, CategoryDTO.class);
CategoryDTO.Builder categoryDTOBuilder = new CategoryDTO.Builder(categoryDTO).withTypeId(typeId);
if (StringUtils.isBlank(categoryDTO.getId())) {
if (!StringUtils.isBlank(categoryDTO.getName())) {
categoryDTOBuilder.withId(categoryDTO.getName().replaceAll(INVALID_ID_CHARS_REGEX, ""));
} else {
categoryDTOBuilder.withId(categoryFileName.replaceAll(INVALID_ID_CHARS_REGEX, ""));
}
}
categoryDTOBuilder.withApplications(buildApplications(categoryDTOBuilder.getTypeId(), categoryDTOBuilder.getId(), typeFileName, categoryFileName));
try {
categoryDTOBuilder.withIcon(new URI(packagePath + "/" + typeFileName + "/" + categoryFileName + "/icon.png"));
} catch (URISyntaxException e) {
LOGGER.warn("Invalid icon path", e);
}
return categoryDTOBuilder.build();
} else {
LOGGER.debug(String.format("category.json %s for classpath repository does not exist", jsonCategoryPath));
return new CategoryDTO.Builder().build();
}
} catch (IOException e) {
throw new RepositoryException("Could not build category", e);
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
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);
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
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);
}
}
use of org.phoenicis.repository.RepositoryException 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();
}
Aggregations