Search in sources :

Example 1 with DefaultFactoryUrl

use of org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl in project devspaces-images by redhat-developer.

the class DefaultFactoryParameterResolver method createFactory.

/**
 * Creates factory based on provided parameters. Presumes url parameter as direct URL to a devfile
 * content.
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // This should never be null, because our contract in #accept prohibits that
    String devfileLocation = factoryParameters.get(URL_PARAMETER_NAME);
    URI devfileURI;
    try {
        devfileURI = new URL(devfileLocation).toURI();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new BadRequestException(format("Unable to process provided factory URL. Please check its validity and try again. Parser message: %s", e.getMessage()));
    }
    return urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(devfileLocation), new URLFileContentProvider(devfileURI, urlFetcher), extractOverrideParams(factoryParameters)).orElse(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) BadRequestException(org.eclipse.che.api.core.BadRequestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) DefaultFactoryUrl(org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)

Example 2 with DefaultFactoryUrl

use of org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl in project che-server by eclipse-che.

the class DefaultFactoryParameterResolver method createFactory.

/**
 * Creates factory based on provided parameters. Presumes url parameter as direct URL to a devfile
 * content.
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // This should never be null, because our contract in #accept prohibits that
    String devfileLocation = factoryParameters.get(URL_PARAMETER_NAME);
    URI devfileURI;
    try {
        devfileURI = new URL(devfileLocation).toURI();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new BadRequestException(format("Unable to process provided factory URL. Please check its validity and try again. Parser message: %s", e.getMessage()));
    }
    return urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(devfileLocation), new URLFileContentProvider(devfileURI, urlFetcher), extractOverrideParams(factoryParameters)).orElse(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) BadRequestException(org.eclipse.che.api.core.BadRequestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) DefaultFactoryUrl(org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)

Aggregations

MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 DefaultFactoryUrl (org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl)2 URLFileContentProvider (org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)2