Search in sources :

Example 86 with PageRequest

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

the class DefaultSysProvisioningBreakConfigService method find.

@Override
public Page<SysProvisioningBreakConfigDto> find(SysProvisioningBreakConfigFilter filter, Pageable pageable, BasePermission... permission) {
    Page<SysProvisioningBreakConfigDto> configs = super.find(filter, pageable, permission);
    // if include global config and set systemId add global configurations
    if (filter != null && filter.isIncludeGlobalConfig() && filter.getSystemId() != null && configs.getTotalElements() != MAX_CONFIGS_FOR_SYSTEM) {
        List<SysProvisioningBreakConfigDto> configsList = addGlobalConfigs(configs.getContent(), filter.getSystemId());
        // 
        if (!configsList.isEmpty()) {
            PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), configsList.size(), pageable.getSort());
            Page<SysProvisioningBreakConfigDto> dtoPage = new PageImpl<>(configsList, pageRequest, configsList.size());
            return dtoPage;
        }
    }
    // 
    return configs;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)

Example 87 with PageRequest

use of org.springframework.data.domain.PageRequest 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 88 with PageRequest

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

the class TreeNodeAndTypeRestTest method changeType.

@Test
public void changeType() {
    IdmTreeType type = getIdmTreeType("TEST_TYPE_1", "TEST_TYPE_1");
    treeTypeRepository.save(type);
    IdmTreeType type2 = getIdmTreeType("TEST_TYPE_2", "TEST_TYPE_2");
    treeTypeRepository.save(type2);
    // save node trought rest
    Map<String, String> body = new HashMap<>();
    body.put("code", "TEST_NODE");
    body.put("name", "TEST_NODE");
    body.put("treeType", type.getId().toString());
    String jsonContent = toJson(body);
    int status = 0;
    Exception ex = null;
    // test save without privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(403, status);
    // test with privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(201, status);
    Page<IdmTreeNode> nodes = this.treeNodeRepository.findChildren(type.getId(), null, new PageRequest(0, 1));
    assertFalse(nodes.getContent().isEmpty());
    IdmTreeNode node = nodes.getContent().get(0);
    // change treeType
    body.put("id", node.getId().toString());
    body.put("name", node.getName() + "_update");
    body.put("treeType", type2.getId().toString());
    jsonContent = toJson(body);
    status = 0;
    ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes/").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertEquals(400, status);
    assertNull(ex);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) HashMap(java.util.HashMap) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 89 with PageRequest

use of org.springframework.data.domain.PageRequest 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 90 with PageRequest

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

the class ExecuteScriptTaskExecutorTest method testExeciteScriptWithResult.

@Test
public void testExeciteScriptWithResult() {
    // remove previous long running task
    List<IdmLongRunningTaskDto> tasks = longRunningTaskService.find(null).getContent();
    for (IdmLongRunningTaskDto task : tasks) {
        longRunningTaskService.delete(task);
    }
    IdmScriptDto scriptDto = new IdmScriptDto();
    scriptDto.setCode(TEST_SCRIPT_CODE + "_3");
    scriptDto.setName(TEST_SCRIPT_CODE + "_3");
    scriptDto.setCategory(IdmScriptCategory.SYSTEM);
    StringBuilder builder = new StringBuilder();
    builder.append("import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;\n");
    builder.append("task.setCounter(0l);\n");
    builder.append("task.setCount(5l);\n");
    builder.append("for (int index = 0; index < 5; index++) {\n");
    builder.append("    IdmIdentityDto dto = new IdmIdentityDto();\n");
    builder.append("    dto.setUsername('test-execute-' + index);\n");
    builder.append("    dto.setLastName('test-execute-' + index);\n");
    builder.append("    dto.setFirstName('' + index);\n");
    builder.append("    identityService.save(dto);\n");
    builder.append("    task.increaseCounter();\n");
    builder.append("    task.updateState();\n");
    builder.append("}\n");
    scriptDto.setScript(builder.toString());
    scriptDto = scriptService.save(scriptDto);
    prepareAuthForTestScript(scriptDto);
    IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.SERVICE);
    authDto.setClassName("eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService");
    authDto.setScript(scriptDto.getId());
    authDto.setService("identityService");
    scriptAuthorityService.save(authDto);
    authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.CLASS_NAME);
    authDto.setClassName("eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto");
    authDto.setScript(scriptDto.getId());
    scriptAuthorityService.save(authDto);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("scriptCode", TEST_SCRIPT_CODE + "_3");
    taskExecutor.init(parameters);
    LongRunningFutureTask<Boolean> futureTask = manager.execute(taskExecutor);
    try {
        assertEquals(Boolean.TRUE, futureTask.getFutureTask().get());
    } catch (InterruptedException | ExecutionException e) {
        fail(e.getMessage());
    }
    IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
    assertEquals(5, longRunningTask.getCount().longValue());
    assertEquals(5, longRunningTask.getCounter().longValue());
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setText("test-execute-");
    List<IdmIdentityDto> identities = identityService.find(identityFilter, new PageRequest(0, 20, new Sort(Direction.ASC, IdmIdentity_.firstName.getName()))).getContent();
    assertEquals(5, identities.size());
    for (int index = 0; index < 5; index++) {
        assertEquals(String.valueOf(index), identities.get(index).getFirstName());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) HashMap(java.util.HashMap) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) Sort(org.springframework.data.domain.Sort) ExecutionException(java.util.concurrent.ExecutionException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5