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