use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// get system related configuration
MultiValueMap<String, UUID> configuration = parseAttributeConfig(report);
SysSystemDto systemDto = getSystemById(configuration.getFirst(PARAMETER_SYSTEM));
SysSystemMappingDto systemMapping = getSystemMappingById(configuration.getFirst(PARAMETER_SYSTEM_MAPPING));
List<SysSystemAttributeMappingDto> attributes = getAttributesById(configuration.get(PARAMETER_MAPPING_ATTRIBUTES), systemMapping);
List<String> selectedAttributeNames = getSelectedAttributeNames(attributes).stream().sorted().collect(Collectors.toList());
// list of identities to report
Set<UUID> identities = getReportedIdentities(report);
boolean skipUnchangedMultivalue = getSkipUnchangedValues(report);
AccAccountFilter filterAccount = new AccAccountFilter();
filterAccount.setSystemId(systemDto.getId());
filterAccount.setEntityType(SystemEntityType.IDENTITY);
File temp = getAttachmentManager().createTempFile();
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// start of root object
jGenerator.writeStartObject();
// write attribute names
jGenerator.writeFieldName(ATTRIBUTE_NAME_JSON_KEY);
getMapper().writeValue(jGenerator, selectedAttributeNames);
// create and write records
jGenerator.writeFieldName(RECORDS_JSON_KEY);
jGenerator.writeStartArray();
createReportData(jGenerator, filterAccount, identities, systemDto.getId(), selectedAttributeNames, skipUnchangedMultivalue);
jGenerator.writeEndArray();
// end of root object
jGenerator.writeEndObject();
} finally {
jGenerator.close();
}
return createAttachment(report, new FileInputStream(temp));
} catch (IOException e) {
throw new ReportGenerateException(report.getName(), e);
} finally {
FileUtils.deleteQuietly(temp);
}
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class SystemDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<UUID> entities = getEntities(action, new StringBuilder());
ResultModels result = new ResultModels();
Map<ResultModel, Long> models = new HashMap<>();
entities.forEach(systemId -> {
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSystemId(systemId);
SysSystemDto system = getService().get(systemId);
long count = accountService.count(accountFilter);
if (count > 0) {
models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_ACCOUNTS, ImmutableMap.of("system", system.getCode(), "count", count)), count);
}
SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
operationFilter.setSystemId(system.getId());
long countEntities = provisioningOperationService.count(operationFilter);
if (countEntities > 0) {
models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_PROVISIONINGS, ImmutableMap.of("system", system.getCode(), "count", countEntities)), countEntities);
}
});
// Sort by count
List<Entry<ResultModel, Long>> collect = //
models.entrySet().stream().sorted(//
Collections.reverseOrder(Map.Entry.comparingByValue())).collect(//
Collectors.toList());
collect.forEach(entry -> {
result.addInfo(entry.getKey());
});
return result;
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class RoleSynchronizationExecutor method assignMissingIdentityRoles.
/**
* Assign missing identity roles.
*/
private void assignMissingIdentityRoles(IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, List<IdmIdentityRoleDto> existsIdentityRoleDtos, Set<UUID> membersContractIds, SysSystemDto userSystemDto, int[] count, String uid, SynchronizationContext context) {
// On every 20th item will be hibernate flushed and check if sync was not ended.
if (count[0] % 20 == 0 && count[0] > 0) {
if (!checkForCancelAndFlush(config)) {
return;
}
}
count[0]++;
// Need to find account using SysSystemEntityDto uid, because uid of AccAccountDto can be different.
SysSystemEntityFilter entityFilter = new SysSystemEntityFilter();
entityFilter.setEntityType(SystemEntityType.IDENTITY);
entityFilter.setSystemId(userSystemDto.getId());
entityFilter.setUid(uid);
SysSystemEntityDto systemEntity = systemEntityService.find(entityFilter, null).stream().findFirst().orElse(null);
if (systemEntity == null) {
return;
}
AccAccountFilter accAccountFilter = new AccAccountFilter();
accAccountFilter.setSystemEntityId(systemEntity.getId());
final UUID accAccountId = accountService.findIds(accAccountFilter, null).stream().findFirst().orElse(null);
if (accAccountId == null) {
return;
}
AccIdentityAccountFilter identityAccountWithoutRelationFilter = new AccIdentityAccountFilter();
identityAccountWithoutRelationFilter.setAccountId(accAccountId);
AccIdentityAccountDto identityAccountDto = identityAccountService.find(identityAccountWithoutRelationFilter, null).getContent().stream().findFirst().orElse(null);
if (identityAccountDto == null) {
return;
}
UUID identityId = identityAccountDto.getIdentity();
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identityId);
if (primeContract == null) {
addToItemLog(logItem, MessageFormat.format("!!Role was not assigned to the user [{0}], because primary contract was not found!!", uid));
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, context.getLog(), context.getActionLogs());
return;
}
membersContractIds.add(primeContract.getId());
IdmIdentityRoleDto existIdentityRoleDto = existsIdentityRoleDtos.stream().filter(identityRole -> primeContract.getId().equals(identityRole.getIdentityContract())).findFirst().orElse(null);
if (existIdentityRoleDto != null) {
// Identity already has the role.
return;
}
addToItemLog(logItem, MessageFormat.format("Role is not assigned for user [{0}] and contract [{1}]. Role request for add role will be created.", uid, primeContract.getId()));
// Get cache with role-requests by identity-contract.
Map<UUID, UUID> roleRequestCache = getRoleRequestCache();
// Get role-request for the primary contract from a cache. If no request is present, then create one.
initRoleRequest(primeContract, roleRequestCache, config);
UUID roleRequestId = roleRequestCache.get(primeContract.getId());
IdmRoleRequestDto mockRoleRequest = new IdmRoleRequestDto();
mockRoleRequest.setId(roleRequestId);
// Create a concept for assign a role to primary contract.
roleRequestService.createConcept(mockRoleRequest, primeContract, null, roleDto.getId(), ConceptRoleRequestOperation.ADD);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemEntityService method deleteInternal.
@Override
@Transactional
public void deleteInternal(SysSystemEntityDto systemEntity) {
Assert.notNull(systemEntity, "System entity is required.");
//
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(systemEntity.getSystem());
filter.setEntityType(systemEntity.getEntityType());
filter.setSystemEntity(systemEntity.getId());
// TODO: transform this behavior to events
if (provisioningOperationService.count(filter) > 0) {
SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system);
throw new ResultCodeException(AccResultCode.SYSTEM_ENTITY_DELETE_FAILED_HAS_OPERATIONS, ImmutableMap.of("uid", systemEntity.getUid(), "system", system.getName()));
}
//
// clear accounts - only link, can be rebuild
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSystemEntityId(systemEntity.getId());
accountService.find(accountFilter, null).forEach(account -> {
account.setSystemEntity(null);
accountService.save(account);
});
//
// clear batches
SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
if (batch != null) {
batchService.delete(batch);
}
//
super.deleteInternal(systemEntity);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class AbstractPasswordFilterIntegrationTest method getAccount.
protected AccAccountDto getAccount(IdmIdentityDto identity, SysSystemDto system) {
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setIdentityId(identity.getId());
accountFilter.setSystemId(system.getId());
accountFilter.setIncludeEcho(Boolean.TRUE);
List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
if (CollectionUtils.isEmpty(accounts)) {
return null;
}
assertEquals(1, accounts.size());
return accounts.get(0);
}
Aggregations