use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
the class GitRepository method fetchInstallableApplications.
@Override
public RepositoryDTO fetchInstallableApplications() {
try {
cloneOrUpdateWithLock();
final RepositoryDTO result = this.localRepositoryFactory.createInstance(this.localFolder, this.repositoryUri).fetchInstallableApplications();
return result;
} catch (RepositoryException e) {
final String message = String.format("Could not fetch installable applications for git-repository %s", this.toString());
throw new RepositoryException(message, e);
}
}
use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.
the class ClasspathRepository method buildApplications.
private List<ApplicationDTO> buildApplications(String typeId, String categoryId, String typeFileName, String categoryFileName) throws RepositoryException {
try {
final String categoryScanClassPath = packagePath + "/" + typeFileName + "/" + categoryFileName;
Resource[] resources = resourceResolver.getResources(categoryScanClassPath + "/*");
final List<ApplicationDTO> applicationDTOS = new ArrayList<>();
for (Resource resource : resources) {
final String fileName = resource.getFilename();
if (!"icon.png".equals(fileName) && !"category.json".equals(fileName)) {
final ApplicationDTO application = buildApplication(typeId, categoryId, typeFileName, categoryFileName, fileName);
if (!application.getScripts().isEmpty()) {
applicationDTOS.add(application);
}
}
}
applicationDTOS.sort(Comparator.comparing(ApplicationDTO::getName));
return applicationDTOS;
} catch (IOException e) {
throw new RepositoryException("Could not build applications", e);
}
}
use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.
the class ClasspathRepository method buildScript.
private ScriptDTO buildScript(String typeId, String categoryId, String applicationId, String typeFileName, String categoryFileName, String applicationFileName, String scriptFileName) throws RepositoryException {
try {
final String scriptJsonFile = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName + "/" + scriptFileName + "/script.json";
final InputStream scriptJsonInputStream = getClass().getResourceAsStream(scriptJsonFile);
final InputStream scriptFile = getClass().getResourceAsStream(packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName + "/" + scriptFileName + "/script.js");
if (scriptJsonInputStream == null) {
return null;
}
URI icon = null;
final String iconResource = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName + "/" + scriptFileName + "/icon.png";
URL iconResourceURL = getClass().getResource(iconResource);
if (iconResourceURL != null) {
try {
icon = iconResourceURL.toURI();
} catch (URISyntaxException e) {
LOGGER.debug("Could not get URI of script icon.");
}
} else {
LOGGER.debug("Could not find script icon.");
}
ScriptDTO.Builder scriptDTOBuilder = new ScriptDTO.Builder(objectMapper.readValue(scriptJsonInputStream, ScriptDTO.class)).withTypeId(typeId).withCategoryId(categoryId).withApplicationId(applicationId).withScript(new String(IOUtils.toByteArray(scriptFile))).withIcon(icon);
if (StringUtils.isBlank(scriptDTOBuilder.getId())) {
if (!StringUtils.isBlank(scriptDTOBuilder.getScriptName())) {
scriptDTOBuilder.withId(scriptDTOBuilder.getScriptName().replaceAll("[^a-zA-Z0-9_]", ""));
} else {
scriptDTOBuilder.withId(scriptFileName.replaceAll("[^a-zA-Z0-9_]", ""));
}
}
return scriptDTOBuilder.build();
} catch (IOException e) {
throw new RepositoryException("Could not build script", e);
}
}
use of org.phoenicis.repository.RepositoryException in project phoenicis 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 phoenicis 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);
}
}
Aggregations