use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class InitTestData method init.
protected void init() {
// we are reusing demo data in tests as well
initDemoData.init();
//
securityService.setSystemAuthentication();
//
try {
IdmRoleDto superAdminRole = this.roleService.getByCode(InitApplicationData.ADMIN_ROLE);
IdmTreeNodeDto rootOrganization = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1)).getContent().get(0);
//
if (!configurationService.getBooleanValue(PARAMETER_TEST_DATA_CREATED, false)) {
log.info("Creating test data ...");
//
IdmRoleDto role1 = new IdmRoleDto();
role1.setName(TEST_USER_ROLE);
role1 = this.roleService.save(role1);
log.info(MessageFormat.format("Test role created [id: {0}]", role1.getId()));
//
IdmRoleDto role2 = new IdmRoleDto();
role2.setName(TEST_CUSTOM_ROLE);
List<IdmRoleCompositionDto> subRoles = new ArrayList<>();
subRoles.add(new IdmRoleCompositionDto(role2.getId(), superAdminRole.getId()));
role2.setSubRoles(subRoles);
role2 = this.roleService.save(role2);
log.info(MessageFormat.format("Test role created [id: {0}]", role2.getId()));
//
// Users for JUnit testing
IdmIdentityDto testUser1 = new IdmIdentityDto();
testUser1.setUsername(TEST_USER_1);
testUser1.setPassword(new GuardedString("heslo"));
testUser1.setFirstName("Test");
testUser1.setLastName("First User");
testUser1.setEmail("test1@bscsolutions.eu");
testUser1 = this.identityService.save(testUser1);
log.info(MessageFormat.format("Identity created [id: {0}]", testUser1.getId()));
IdmIdentityDto testUser2 = new IdmIdentityDto();
testUser2.setUsername(TEST_USER_2);
testUser2.setPassword(new GuardedString("heslo"));
testUser2.setFirstName("Test");
testUser2.setLastName("Second User");
testUser2.setEmail("test2@bscsolutions.eu");
testUser2 = this.identityService.save(testUser2);
log.info(MessageFormat.format("Identity created [id: {0}]", testUser2.getId()));
IdmTreeTypeDto type = this.treeTypeService.get(rootOrganization.getTreeType());
IdmTreeNodeDto organization = new IdmTreeNodeDto();
organization.setCode("test");
organization.setName("Organization Test");
organization.setCreator("ja");
organization.setParent(rootOrganization.getId());
organization.setTreeType(type.getId());
organization = this.treeNodeService.save(organization);
IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
identityWorkPosition2.setIdentity(testUser1.getId());
identityWorkPosition2.setWorkPosition(organization.getId());
identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
contractGuarantee.setGuarantee(testUser2.getId());
contractGuaranteeService.save(contractGuarantee);
//
log.info("Test data was created.");
//
configurationService.setBooleanValue(PARAMETER_TEST_DATA_CREATED, true);
}
//
} finally {
SecurityContextHolder.clearContext();
}
}
use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class RemoveOldLogsTaskExecutor method process.
@Override
public Boolean process() {
if (days == null) {
LOG.warn("Parameter {} is not filled. This task will be skipped.", PARAMETER_DAYS);
return Boolean.TRUE;
}
//
IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
filter.setTill(DateTime.now().minusDays(days.intValue()));
Page<IdmLoggingEventDto> loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
//
Long exceptionCounter = 0l;
boolean canContinue = true;
this.count = loggingEvents.getTotalElements();
this.setCounter(0l);
//
while (canContinue) {
for (IdmLoggingEventDto event : loggingEvents) {
Long eventId = Long.valueOf(event.getId().toString());
//
LOG.debug("Event id: [{}] will be removed", event.getId());
loggingEventExceptionService.deleteByEventId(eventId);
loggingEventPropertyService.deleteAllByEventId(eventId);
loggingEventService.deleteAllById(eventId);
this.increaseCounter();
//
canContinue = updateState();
if (!canContinue) {
break;
}
}
//
loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
//
if (loggingEvents.getContent().isEmpty()) {
break;
}
}
//
LOG.info("Removed logs older than [{}] days was successfully completed. Removed logs: [{}] and their exceptions [{}].", days, this.counter, exceptionCounter);
//
return Boolean.TRUE;
}
use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormAttributeService method deleteInternal.
@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
Assert.notNull(dto);
// attribute with filled values cannot be deleted
IdmFormValueFilter filter = new IdmFormValueFilter();
filter.setAttributeId(dto.getId());
formValueServices.getPlugins().forEach(formValueService -> {
if (formValueService.find(filter, new PageRequest(0, 1)).getTotalElements() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
}
});
// delete all values
// TODO: add some force delete parameter => rewrite service to event usage
/* formValueServices.getPlugins().forEach(formValueService -> {
formValueService.find(filter, null).getContent().forEach(formValue -> {
formValueService.delete((IdmFormValueDto) formValue);
});
});*/
//
// check rules for automatic role attributes
IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
automaticRoleRuleFilter.setFormAttributeId(dto.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic roles use this attribute
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
}
//
// Check rules requests for automatic role attributes. Deletes relation on this form attribute.
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
ruleRequests.forEach(rule -> {
rule.setFormAttribute(null);
automaticRoleAttributeRequestService.save(rule);
});
//
super.deleteInternal(dto);
}
use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormDefinitionService method toDto.
@Override
protected IdmFormDefinitionDto toDto(IdmFormDefinition entity, IdmFormDefinitionDto dto) {
dto = super.toDto(entity, dto);
if (dto != null && !dto.isTrimmed()) {
// set mapped attributes
IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
filter.setDefinitionId(dto.getId());
dto.setFormAttributes(formAttributeService.find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
}
return dto;
}
use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManager method getAttachmentVersions.
@Override
@Transactional
public List<IdmAttachmentDto> getAttachmentVersions(UUID attachmentId, BasePermission... permission) {
Assert.notNull(attachmentId);
//
IdmAttachmentFilter filter = new IdmAttachmentFilter();
filter.setVersionsFor(attachmentId);
//
return find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(Direction.DESC, IdmAttachment_.versionNumber.getName())), permission).getContent();
}
Aggregations