use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto in project che-server by eclipse-che.
the class FactoryService method resolveFactory.
@POST
@Path("/resolver")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Operation(summary = "Create factory by providing map of parameters. Get JSON with factory information", responses = { @ApiResponse(responseCode = "200", description = "Factory successfully built from parameters"), @ApiResponse(responseCode = "400", description = "Missed required parameters, failed to validate factory"), @ApiResponse(responseCode = "500", description = "Internal server error") })
public FactoryMetaDto resolveFactory(@Parameter(description = "Parameters provided to create factories") Map<String, String> parameters, @Parameter(description = "Whether or not to validate values like it is done when accepting a Factory") @DefaultValue("false") @QueryParam(VALIDATE_QUERY_PARAMETER) Boolean validate) throws ApiException {
// check parameter
requiredNotNull(parameters, "Factory build parameters");
// search matching resolver and create factory from matching resolver
FactoryMetaDto resolvedFactory = factoryParametersResolverHolder.getFactoryParametersResolver(parameters).createFactory(parameters);
if (resolvedFactory == null) {
throw new BadRequestException(FACTORY_NOT_RESOLVABLE);
}
if (validate) {
acceptValidator.validateOnAccept(resolvedFactory);
}
resolvedFactory = injectLinks(resolvedFactory, parameters);
return resolvedFactory;
}
use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testShouldReturnV2WithDevworkspacesDisabled.
@Test
public void testShouldReturnV2WithDevworkspacesDisabled() throws ApiException, DevfileException {
String myLocation = "http://foo-location/";
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
URLFactoryBuilder localUrlFactoryBuilder = new URLFactoryBuilder(defaultEditor, defaultPlugin, false, devfileParser, devfileVersionDetector);
FactoryMetaDto factory = localUrlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto in project che-server by eclipse-che.
the class URLFactoryBuilderTest method checkWithCustomDevfileAndRecipe.
@Test
public void checkWithCustomDevfileAndRecipe() throws Exception {
DevfileImpl devfile = new DevfileImpl();
WorkspaceConfigImpl workspaceConfigImpl = new WorkspaceConfigImpl();
String myLocation = "http://foo-location/";
RecipeImpl expectedRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "application/x-yaml", "content", "");
EnvironmentImpl expectedEnv = new EnvironmentImpl(expectedRecipe, emptyMap());
workspaceConfigImpl.setEnvironments(singletonMap("name", expectedEnv));
workspaceConfigImpl.setDefaultEnv("name");
when(devfileParser.parseYamlRaw(anyString())).thenReturn(new ObjectNode(JsonNodeFactory.instance));
when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDto);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testDevfileV2.
@Test
public void testDevfileV2() throws ApiException, DevfileException {
String myLocation = "http://foo-location/";
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto in project devspaces-images by redhat-developer.
the class URLFactoryBuilderTest method testDevfileV2.
@Test
public void testDevfileV2() throws ApiException, DevfileException {
String myLocation = "http://foo-location/";
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
Aggregations