Search in sources :

Example 11 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed.

@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile"));
    IdeDto ide = newDto(IdeDto.class).withOnAppClosed(newDto(OnAppClosedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 12 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded.

@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("findReplace"));
    IdeDto ide = newDto(IdeDto.class).withOnAppLoaded(newDto(OnAppLoadedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 13 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryService method getFactoryByAttribute.

@GET
@Path("/find")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get factory by attribute, " + "the attribute must match one of the Factory model fields with type 'String', " + "e.g. (factory.name, factory.creator.name)", notes = "If specify more than one value for a single query parameter then will be taken the first one")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains list requested factories"), @ApiResponse(code = 400, message = "When query does not contain at least one attribute to search for"), @ApiResponse(code = 500, message = "Internal server error") })
public List<FactoryDto> getFactoryByAttribute(@DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Context UriInfo uriInfo) throws BadRequestException, ServerException {
    final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems");
    final List<Pair<String, String>> query = URLEncodedUtils.parse(uriInfo.getRequestUri()).entrySet().stream().filter(param -> !skip.contains(param.getKey()) && !param.getValue().isEmpty()).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
    checkArgument(!query.isEmpty(), "Query must contain at least one attribute");
    final List<FactoryDto> factories = new ArrayList<>();
    for (Factory factory : factoryManager.getByAttribute(maxItems, skipCount, query)) {
        factories.add(injectLinks(asDto(factory), null));
    }
    return factories;
}
Also used : URLEncodedUtils(org.eclipse.che.commons.lang.URLEncodedUtils) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) FactoryBuilder(org.eclipse.che.api.factory.server.builder.FactoryBuilder) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) PreferenceManager(org.eclipse.che.api.user.server.PreferenceManager) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) DELETE(javax.ws.rs.DELETE) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ImmutableSet(com.google.common.collect.ImmutableSet) Context(javax.ws.rs.core.Context) Predicate(java.util.function.Predicate) Set(java.util.Set) Pair(org.eclipse.che.commons.lang.Pair) AuthorDto(org.eclipse.che.api.factory.shared.dto.AuthorDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) Response(javax.ws.rs.core.Response) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) UriInfo(javax.ws.rs.core.UriInfo) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) FactoryLinksHelper.createLinks(org.eclipse.che.api.factory.server.FactoryLinksHelper.createLinks) PathParam(javax.ws.rs.PathParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ApiException(org.eclipse.che.api.core.ApiException) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) MULTIPART_FORM_DATA(javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA) Api(io.swagger.annotations.Api) DtoFactory(org.eclipse.che.dto.server.DtoFactory) CONTENT_DISPOSITION(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) JsonSyntaxException(com.google.gson.JsonSyntaxException) FileItem(org.apache.commons.fileupload.FileItem) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Factory(org.eclipse.che.api.core.model.factory.Factory) Collectors.toList(java.util.stream.Collectors.toList) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) PUT(javax.ws.rs.PUT) UserManager(org.eclipse.che.api.user.server.UserManager) Collections(java.util.Collections) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Pair(org.eclipse.che.commons.lang.Pair) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryService method getFactoryJson.

@GET
@Path("/workspace/{ws-id}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Construct factory from workspace", notes = "This call returns a Factory.json that is used to create a factory")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains requested factory JSON"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "Workspace not found"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getFactoryJson(@ApiParam(value = "Workspace identifier") @PathParam("ws-id") String wsId, @ApiParam(value = "Project path") @QueryParam("path") String path) throws BadRequestException, NotFoundException, ServerException {
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(wsId);
    excludeProjectsWithoutLocation(workspace, path);
    final FactoryDto factoryDto = DtoFactory.newDto(FactoryDto.class).withV("4.0").withWorkspace(org.eclipse.che.api.workspace.server.DtoConverter.asDto(workspace.getConfig()));
    return Response.ok(factoryDto, APPLICATION_JSON).header(CONTENT_DISPOSITION, "attachment; filename=factory.json").build();
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBuilder method build.

/**
     * Build factory from json and validate its compatibility.
     *
     * @param json
     *         - json Reader from encoded factory.
     * @return - Factory object represented by given factory json.
     */
public FactoryDto build(Reader json) throws IOException, ApiException {
    FactoryDto factory = DtoFactory.getInstance().createDtoFromJson(json, FactoryDto.class);
    checkValid(factory);
    return factory;
}
Also used : FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto)

Aggregations

FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)30 Test (org.testng.annotations.Test)21 Response (com.jayway.restassured.response.Response)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 Factory (org.eclipse.che.api.core.model.factory.Factory)10 IdeActionDto (org.eclipse.che.api.factory.shared.dto.IdeActionDto)8 IdeDto (org.eclipse.che.api.factory.shared.dto.IdeDto)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)5 BadRequestException (org.eclipse.che.api.core.BadRequestException)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Produces (javax.ws.rs.Produces)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2