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);
}
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));
}
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;
}
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));
}
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));
}
Aggregations