use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project che-server by eclipse-che.
the class ResourceManager method getResourceDetails.
/**
* Returns detailed information about resources which given account can use.
*
* @param accountId account id
* @return detailed information about resources which can be used by given account
* @throws NotFoundException when account with specified id was not found
* @throws ServerException when some exception occurs
*/
public ResourcesDetails getResourceDetails(String accountId) throws NotFoundException, ServerException {
final List<ProvidedResources> resources = new ArrayList<>();
for (ResourcesProvider resourcesProvider : resourcesProviders) {
resources.addAll(resourcesProvider.getResources(accountId));
}
final List<Resource> allResources = resources.stream().flatMap(providedResources -> providedResources.getResources().stream()).collect(Collectors.toList());
return new ResourcesDetailsImpl(accountId, resources, new ArrayList<>(resourceAggregator.aggregateByType(allResources).values()));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project che-server by eclipse-che.
the class ResourceServiceTest method testGetsResourceDetails.
@Test
public void testGetsResourceDetails() throws Exception {
// given
final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
// when
when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
// then
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
assertEquals(response.statusCode(), 200);
final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
assertEquals(resourceDetailsDto, toFetch);
verify(resourceManager).getResourceDetails("account123");
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project devspaces-images by redhat-developer.
the class ResourceManager method getResourceDetails.
/**
* Returns detailed information about resources which given account can use.
*
* @param accountId account id
* @return detailed information about resources which can be used by given account
* @throws NotFoundException when account with specified id was not found
* @throws ServerException when some exception occurs
*/
public ResourcesDetails getResourceDetails(String accountId) throws NotFoundException, ServerException {
final List<ProvidedResources> resources = new ArrayList<>();
for (ResourcesProvider resourcesProvider : resourcesProviders) {
resources.addAll(resourcesProvider.getResources(accountId));
}
final List<Resource> allResources = resources.stream().flatMap(providedResources -> providedResources.getResources().stream()).collect(Collectors.toList());
return new ResourcesDetailsImpl(accountId, resources, new ArrayList<>(resourceAggregator.aggregateByType(allResources).values()));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project devspaces-images by redhat-developer.
the class ResourceServiceTest method testGetsResourceDetails.
@Test
public void testGetsResourceDetails() throws Exception {
// given
final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
// when
when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
// then
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
assertEquals(response.statusCode(), 200);
final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
assertEquals(resourceDetailsDto, toFetch);
verify(resourceManager).getResourceDetails("account123");
}
Aggregations