Search in sources :

Example 16 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorController method find.

@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_READ + "')")
@ApiOperation(value = "Find all processors", nickname = "findAllEntityEventProcessors", tags = { EntityEventProcessorController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }) }, notes = "Returns all registered entity event processors with state properties (disabled, order)")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Resources<?> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters) {
    List<EntityEventProcessorDto> records = entityEventManager.find(toFilter(parameters));
    PageImpl page = new PageImpl(records, new PageRequest(0, records.size() == 0 ? 10 : records.size()), records.size());
    if (page.getContent().isEmpty()) {
        return pagedResourcesAssembler.toEmptyResource(page, EntityEventProcessorDto.class, null);
    }
    return pagedResourcesAssembler.toResource(page);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorUnitTest method testProcess.

@Test
public void testProcess() {
    IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
    scheduledTask.setId(UUID.randomUUID());
    IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
    // 
    IdmIdentityDto dto1 = getTestIdentityDto();
    IdmIdentityDto dto2 = getTestIdentityDto();
    IdmIdentityDto dto3 = getTestIdentityDto();
    // stubs
    doReturn(Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build())).when(executor).processItem(any(IdmIdentityDto.class));
    doReturn(false).when(executor).isInProcessedQueue(any(IdmIdentityDto.class));
    doNothing().when(itemService).deleteInternal(any(IdmProcessedTaskItemDto.class));
    doReturn(Lists.newArrayList(UUID.randomUUID(), UUID.randomUUID())).when(executor).getProcessedItemRefsFromQueue();
    doReturn(scheduledTask.getId()).when(executor).getScheduledTaskId();
    // matchers
    when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
    when(scheduledTaskService.get(any(UUID.class))).thenReturn(scheduledTask);
    when(executor.getItemsToProcess(any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(dto1, dto2), new PageRequest(0, 2), 6)).thenReturn(new PageImpl<>(Lists.newArrayList(dto3), new PageRequest(0, 2), 6)).thenReturn(new PageImpl<>(Lists.newArrayList()));
    when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
    when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(new IdmProcessedTaskItemDto())));
    // 
    // 
    Boolean processingResult = executor.process();
    assertTrue(processingResult);
    // 
    // 
    verify(scheduledTaskService, times(3)).get(any(UUID.class));
    verify(longRunningTaskService, times(6)).get(any(UUID.class));
    // 
    verify(executor, times(3)).getItemsToProcess(any(Pageable.class));
    verify(executor, times(1)).isInProcessedQueue(dto1);
    verify(executor, times(1)).isInProcessedQueue(dto2);
    verify(executor, times(1)).isInProcessedQueue(dto3);
    verify(executor, times(1)).getProcessedItemRefsFromQueue();
    verify(executor, times(2)).removeFromProcessedQueue(any(UUID.class));
    verify(executor, times(3)).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
    verify(executor, times(3)).logItemProcessed(any(IdmIdentityDto.class), any(OperationResult.class));
    // 6x addToProcessQueue, 2x removeItemFromQueue, 2x stubbed
    verify(executor, times(10)).getScheduledTaskId();
    verify(executor, times(3)).processItem(any(IdmIdentityDto.class));
    // 3x addToProcessQueue, 3x logItemProcessed
    verify(itemService, times(2)).deleteInternal(any(IdmProcessedTaskItemDto.class));
    verify(itemService, times(3)).createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class));
    verify(itemService, times(3)).createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class));
    // 2x from removeFromProcessedQueue, other invocations are stubbed
    verify(itemService, times(2)).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 18 with PageImpl

use of org.springframework.data.domain.PageImpl in project uplace.es by Uplace.

the class PaginationUtilUnitTest method generatePaginationHttpHeadersTest.

@Test
public void generatePaginationHttpHeadersTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content, new PageRequest(6, 50), 400L);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\"," + "</api/_search/example?page=5&size=50>; rel=\"prev\"," + "</api/_search/example?page=7&size=50>; rel=\"last\"," + "</api/_search/example?page=0&size=50>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) HttpHeaders(org.springframework.http.HttpHeaders) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

PageImpl (org.springframework.data.domain.PageImpl)18 ArrayList (java.util.ArrayList)9 PageRequest (org.springframework.data.domain.PageRequest)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 List (java.util.List)4 Test (org.junit.Test)4 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)3 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)3 UUID (java.util.UUID)3 Page (org.springframework.data.domain.Page)3 Pageable (org.springframework.data.domain.Pageable)3 Sort (org.springframework.data.domain.Sort)3 Order (org.springframework.data.domain.Sort.Order)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)2 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)2 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)2 Collectors (java.util.stream.Collectors)2 Resources (org.springframework.hateoas.Resources)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Lists (com.google.common.collect.Lists)1