use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel 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.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class RoleAccountManagementBulkAction 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(roleId -> {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleId);
IdmRoleDto role = getService().get(roleId);
long count = identityRoleService.find(identityRoleFilter, PageRequest.of(0, 1)).getTotalElements();
if (count > 0) {
models.put(new DefaultResultModel(AccResultCode.ROLE_ACM_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
}
});
boolean someIdentitiesFound = //
models.values().stream().filter(//
count -> count > 0).findFirst().isPresent();
if (!someIdentitiesFound) {
result.addInfo(new DefaultResultModel(AccResultCode.ROLE_ACM_BULK_ACTION_NONE_IDENTITIES));
} else {
// Sort by count
List<Entry<ResultModel, Long>> collect = //
models.entrySet().stream().sorted(//
Collections.reverseOrder(Map.Entry.comparingByValue())).limit(//
5).collect(//
Collectors.toList());
collect.forEach(entry -> {
result.addInfo(entry.getKey());
});
}
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManager method generateUniformPassword.
@Override
@Transactional
public GuardedString generateUniformPassword(UUID entityIdentifier, Class<? extends AbstractDto> entityType, UUID transactionId) {
Assert.notNull(transactionId, "Transaction cannot be null!");
Assert.notNull(entityIdentifier, "Entity identifier cannot be null!");
Assert.notNull(entityType, "Entity type cannot be null!");
IdmEntityStateDto entityStateDto = this.getEntityState(entityIdentifier, entityType, transactionId);
if (entityStateDto != null) {
GuardedString password = getPassword(entityStateDto);
if (password == null || password.getValue().length == 0) {
// TODO: how to generate password for all system policies.
password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
confidentialStorage.saveGuardedString(entityStateDto, UNIFORM_PASSWORD_KEY, password);
}
// The uniform password was used, we need to mark it.
Map<String, Object> parameters = entityStateDto.getResult().getModel().getParameters();
HashMap<String, Object> newParameters = Maps.newHashMap(parameters);
newParameters.put(PASSWORD_USED, Boolean.TRUE);
entityStateDto.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
entityStateManager.saveState(null, entityStateDto);
return password;
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractExportBulkAction method addAttachmentMetadata.
/**
* Adds attachment metadata to the operation result (for download attachment
* directly from bulk action modal dialog).
*
* @param result
*/
private void addAttachmentMetadata(OperationResult result) {
IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId());
OperationResult taskResult = task.getResult();
if (OperationState.EXECUTED == taskResult.getState()) {
ResultModel model = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD, //
ImmutableMap.of(AttachableEntity.PARAMETER_DOWNLOAD_URL, MessageFormat.format("export-imports/{0}/download", batch.getId()), //
AttachableEntity.PARAMETER_OWNER_ID, //
batch.getId(), //
AttachableEntity.PARAMETER_OWNER_TYPE, //
batch.getClass().getName()));
//
taskResult.setModel(model);
getLongRunningTaskService().save(task);
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractBulkAction method createPermissionFailedLog.
/**
* Create failed log for given dto with exception for insufficient permission
*
* @param dto
*/
protected void createPermissionFailedLog(DTO dto) {
String entityCode = "";
if (dto instanceof Codeable) {
entityCode = ((Codeable) dto).getCode();
}
DefaultResultModel model = new DefaultResultModel(CoreResultCode.BULK_ACTION_INSUFFICIENT_PERMISSION, ImmutableMap.of("bulkAction", this.getAction().getName(), "entityId", dto.getId(), "entityCode", entityCode));
//
this.logItemProcessed(dto, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
}
Aggregations