Search in sources :

Example 1 with TemplateApplicationSource

use of org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModel method getLocalAppSource.

private IApplicationSource getLocalAppSource(IProgressMonitor monitor, String filename) {
    if (StringUtils.isBlank(filename)) {
        return null;
    }
    IResource resource = null;
    filename = VariablesHelper.replaceVariables(filename);
    try {
        if (!OpenshiftUIConstants.URL_VALIDATOR.isValid(filename) && !Files.isRegularFile(Paths.get(filename))) {
            return null;
        }
        try (InputStream input = createInputStream(filename, monitor)) {
            resource = resourceFactory.create(input);
            if (resource != null && !(resource instanceof ITemplate)) {
                throw new NotATemplateException(resource.getKind());
            }
        }
    } catch (FileNotFoundException e) {
        throw new OpenShiftException(e, NLS.bind("Could not find the file \"{0}\" to upload", filename));
    } catch (IOException e) {
        throw new OpenShiftException(e, NLS.bind("Error reading the file or URL \"{0}\" to upload", filename));
    } catch (ResourceFactoryException | ClassCastException e) {
        throw e;
    }
    switch(resource.getKind()) {
        case ResourceKind.TEMPLATE:
            return new TemplateApplicationSource((ITemplate) resource);
    }
    throw new OpenShiftException("Creating applications from local files is only allowed using a template");
}
Also used : OpenShiftException(com.openshift.restclient.OpenShiftException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) TemplateApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource) ITemplate(com.openshift.restclient.model.template.ITemplate) IOException(java.io.IOException) IResource(com.openshift.restclient.model.IResource) ResourceFactoryException(com.openshift.restclient.ResourceFactoryException)

Aggregations

OpenShiftException (com.openshift.restclient.OpenShiftException)1 ResourceFactoryException (com.openshift.restclient.ResourceFactoryException)1 IResource (com.openshift.restclient.model.IResource)1 ITemplate (com.openshift.restclient.model.template.ITemplate)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TemplateApplicationSource (org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource)1