Search in sources :

Example 6 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldRemoveFactoryByGivenIdentifier.

@Test
public void shouldRemoveFactoryByGivenIdentifier() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).param("id", FACTORY_ID).expect().statusCode(204).when().delete(SERVICE_PATH + "/" + FACTORY_ID);
    verify(factoryManager).removeFactory(FACTORY_ID);
}
Also used : DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 7 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldBeAbleToUpdateFactory.

@Test
public void shouldBeAbleToUpdateFactory() throws Exception {
    final Factory existed = createFactory();
    final Factory update = createFactoryWithStorage(null, "git", "https://github.com/codenvy/platform-api1.git");
    when(factoryManager.getById(FACTORY_ID)).thenReturn(existed);
    when(factoryManager.updateFactory(any())).thenReturn(update);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(asDto(existed, user))).when().expect().statusCode(200).put(SERVICE_PATH + "/" + FACTORY_ID);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    verify(factoryManager, times(1)).updateFactory(any());
    assertEquals(result.withLinks(emptyList()), asDto(update, user));
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 8 with Factory

use of org.eclipse.che.api.core.model.factory.Factory 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 9 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryService method updateFactory.

@PUT
@Path("/{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update factory information by configuration and specified identifier", notes = "Update factory based on the factory id which is passed in a path parameter. " + "For perform this operation user needs respective rights")
@ApiResponses({ @ApiResponse(code = 200, message = "Factory successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "User does not have rights to update factory"), @ApiResponse(code = 404, message = "Factory to update not found"), @ApiResponse(code = 409, message = "Conflict error occurred during factory update" + "(e.g. Factory with such name and creator already exists)"), @ApiResponse(code = 500, message = "Internal server error") })
public FactoryDto updateFactory(@ApiParam(value = "Factory identifier") @PathParam("id") String factoryId, FactoryDto update) throws BadRequestException, NotFoundException, ServerException, ForbiddenException, ConflictException {
    requiredNotNull(update, "Factory configuration");
    update.setId(factoryId);
    final Factory existing = factoryManager.getById(factoryId);
    // check if the current user has enough access to edit the factory
    editValidator.validate(existing);
    factoryBuilder.checkValid(update, true);
    // validate the new content
    createValidator.validateOnCreate(update);
    return injectLinks(asDto(factoryManager.updateFactory(update)), factoryManager.getFactoryImages(factoryId));
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryListByNameAttribute.

@Test
public void shouldReturnFactoryListByNameAttribute() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.getByAttribute(1, 0, ImmutableList.of(Pair.of("factory.name", factory.getName())))).thenReturn(ImmutableList.of(factory));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).when().expect().statusCode(200).get(SERVICE_PATH + "/find?maxItems=1&skipCount=0&factory.name=" + factory.getName());
    final List<FactoryDto> res = unwrapDtoList(response, FactoryDto.class);
    assertEquals(res.size(), 1);
    assertEquals(res.get(0).withLinks(emptyList()), asDto(factory, user));
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Aggregations

Factory (org.eclipse.che.api.core.model.factory.Factory)14 DtoFactory (org.eclipse.che.dto.server.DtoFactory)14 Test (org.testng.annotations.Test)12 Response (com.jayway.restassured.response.Response)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)10 InputStream (java.io.InputStream)5 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 APPLICATION_JSON (javax.ws.rs.core.MediaType.APPLICATION_JSON)2 TEXT_PLAIN (javax.ws.rs.core.MediaType.TEXT_PLAIN)2 UriInfo (javax.ws.rs.core.UriInfo)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2