use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testMergeParameters.
@Test
public void testMergeParameters() {
ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR, ImmutableMap.of("one", "one", "two", "two"));
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).addParameter("one", "OneUpdated").addParameter("three", "three").build();
Assert.assertEquals("OneUpdated", message.getParameters().get("one"));
Assert.assertEquals("two", message.getParameters().get("two"));
Assert.assertEquals("three", message.getParameters().get("three"));
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class RoleRequestCheckSystemStateProcessor method process.
@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
IdmRoleRequestDto request = event.getContent();
IdmRoleRequestDto currentRequest = event.getOriginalSource();
Assert.notNull(request, "Request is required.");
Assert.notNull(request.getId(), "Request identifier is required.");
SysProvisioningOperationFilter provisioningOperationFilter = new SysProvisioningOperationFilter();
provisioningOperationFilter.setRoleRequestId(request.getId());
// Some active operation for that request has state CREATED -> we will wait for execution of all operations!
provisioningOperationFilter.setResultState(OperationState.CREATED);
long countCreatedOperations = provisioningOperationService.count(provisioningOperationFilter);
if (countCreatedOperations > 0) {
request.setSystemState(new OperationResultDto(OperationState.RUNNING));
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
return result;
}
provisioningOperationFilter.setResultState(null);
long countOperations = provisioningOperationService.count(provisioningOperationFilter);
long countArchives = provisioningArchiveService.count(provisioningOperationFilter);
long allOperations = countOperations + countArchives;
// Everything was done (in provisioning)
if (countOperations == 0 && countArchives > 0) {
List<IdmConceptRoleRequestDto> concepts = null;
List<SysProvisioningArchiveDto> canceledOperations = Lists.newArrayList();
// We want to mark canceled (archives with exception state) concepts
canceledOperations.addAll(findCanceledArchiveOperations(request, OperationState.EXCEPTION));
// We want to mark canceled (archives with blocked state) concepts
canceledOperations.addAll(findCanceledArchiveOperations(request, OperationState.BLOCKED));
// We want to mark canceled (archives with not executed state) concepts
canceledOperations.addAll(findCanceledArchiveOperations(request, OperationState.NOT_EXECUTED));
if (canceledOperations.size() > 0) {
concepts = loadConcepts(request, concepts);
Set<SysSystemDto> systems = canceledOperations.stream().map(archive -> {
return provisioningArchiveService.getSystem(archive);
}).distinct().collect(Collectors.toSet());
for (SysSystemDto system : systems) {
List<IdmConceptRoleRequestDto> canceledConcepts = roleSystemService.getConceptsForSystem(concepts, system.getId());
// This concepts should have system-state set to CANCELED
//
canceledConcepts.stream().filter(concept -> !(concept.getSystemState() != null && //
OperationState.CANCELED == concept.getSystemState().getState())).forEach(concept -> {
//
OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.CANCELED).setModel(new DefaultResultModel(AccResultCode.ROLE_REQUEST_OPERATION_CANCELED, ImmutableMap.of("system", system.getCode()))).build();
concept.setSystemState(systemResult);
// Save role concept
conceptRoleRequestService.save(concept);
});
}
}
// Change state for all concepts with exception to null
OperationResultDto beforeSystemState = currentRequest.getSystemState();
if (beforeSystemState != null && OperationState.EXCEPTION == beforeSystemState.getState() && (AccResultCode.ROLE_REQUEST_ALL_OPERATIONS_FAILED.getCode().equals(beforeSystemState.getCode()) || AccResultCode.ROLE_REQUEST_OPERATION_FAILED.getCode().equals(beforeSystemState.getCode()) || AccResultCode.ROLE_REQUEST_SOME_OPERATIONS_FAILED.getCode().equals(beforeSystemState.getCode()))) {
// Now is request executed (without exceptions), we will set all concepts with
// exception to null
concepts = loadConcepts(request, concepts);
// Find concepts with provisioning exception and set them system state to null
concepts.stream().filter(concept -> concept.getSystemState() != null && OperationState.EXCEPTION == concept.getSystemState().getState() && AccResultCode.ROLE_REQUEST_OPERATION_FAILED.getCode().equals(concept.getSystemState().getCode())).forEach(concept -> {
concept.setSystemState(null);
// Save role concept
conceptRoleRequestService.save(concept);
});
}
request.setSystemState(new OperationResultDto(OperationState.EXECUTED));
return new DefaultEventResult<>(event, this);
}
// Nothing was done
if (countOperations == 0 && countArchives == 0) {
request.setSystemState(null);
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
return result;
}
provisioningOperationFilter.setResultState(OperationState.EXCEPTION);
long countFailedOperations = provisioningOperationService.count(provisioningOperationFilter);
if (countFailedOperations == allOperations) {
// All operations failed
return createResult(//
event, //
request, //
OperationState.EXCEPTION, //
AccResultCode.ROLE_REQUEST_ALL_OPERATIONS_FAILED, //
ImmutableMap.of("requestId", request.getId()), null);
} else if (countFailedOperations > 0) {
// Some operations failed
List<SysProvisioningOperationDto> failedOperations = provisioningOperationService.find(provisioningOperationFilter, null).getContent();
List<IdmConceptRoleRequestDto> concepts = loadConcepts(request, null);
failedOperations.forEach(operation -> {
Assert.notNull(operation.getSystem(), "System is required.");
UUID systemId = operation.getSystem();
List<IdmConceptRoleRequestDto> failedConcepts = roleSystemService.getConceptsForSystem(concepts, systemId);
failedConcepts.forEach(concept -> {
OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(AccResultCode.ROLE_REQUEST_OPERATION_FAILED, ImmutableMap.of("system", provisioningOperationService.getSystem(operation).getCode()))).build();
concept.setSystemState(systemResult);
// Save role concept
conceptRoleRequestService.save(concept);
});
});
String failedSystems = getSystems(failedOperations);
if (failedOperations.size() == 1) {
// Exist only one failed operation -> we can add exception
return createResult(//
event, //
request, //
OperationState.EXCEPTION, //
AccResultCode.ROLE_REQUEST_OPERATION_FAILED, //
ImmutableMap.of("system", failedSystems), failedOperations.get(0).getResult().getCause());
} else {
return createResult(//
event, //
request, //
OperationState.EXCEPTION, //
AccResultCode.ROLE_REQUEST_SOME_OPERATIONS_FAILED, //
ImmutableMap.of("systems", failedSystems), null);
}
}
provisioningOperationFilter.setResultState(OperationState.BLOCKED);
long countBlockedOperations = provisioningOperationService.count(provisioningOperationFilter);
if (countBlockedOperations > 0) {
// Some operations are blocked
List<SysProvisioningOperationDto> blockedOperations = provisioningOperationService.find(provisioningOperationFilter, null).getContent();
String blockedSystems = getSystems(blockedOperations);
return createResult(//
event, //
request, //
OperationState.BLOCKED, //
AccResultCode.ROLE_REQUEST_SOME_OPERATIONS_BLOCKED, //
ImmutableMap.of("systems", blockedSystems), null);
}
// Some operations are not-executed
provisioningOperationFilter.setResultState(OperationState.NOT_EXECUTED);
long countNotExecutedOperations = provisioningOperationService.count(provisioningOperationFilter);
if (countNotExecutedOperations > 0) {
request.setSystemState(new OperationResultDto(OperationState.NOT_EXECUTED));
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
return result;
}
// Some operation are running
provisioningOperationFilter.setResultState(OperationState.RUNNING);
long countRunningOperations = provisioningOperationService.count(provisioningOperationFilter);
if (countRunningOperations > 0) {
request.setSystemState(new OperationResultDto(OperationState.RUNNING));
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
return result;
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class NotificationTemplateDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<UUID> entities = getEntities(action, new StringBuilder());
ResultModels results = new ResultModels();
IdmNotificationTemplateFilter templateFilter = new IdmNotificationTemplateFilter();
templateFilter.setUnmodifiable(Boolean.TRUE);
List<IdmNotificationTemplateDto> unmodifiable = notificationService.find(templateFilter, null).getContent();
List<IdmNotificationTemplateDto> templatesToWarn = unmodifiable.stream().filter(dto -> {
return entities.contains(dto.getId());
}).collect(Collectors.toList());
for (IdmNotificationTemplateDto item : templatesToWarn) {
results.addInfo(new DefaultResultModel(CoreResultCode.NOTIFICATION_SYSTEM_TEMPLATE_DELETE_FAILED, ImmutableMap.of("template", item.getCode())));
}
return results;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class RoleDeleteBulkAction 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.count(identityRoleFilter);
if (count > 0) {
if (securityService.hasAnyAuthority(CoreGroupPermission.ROLE_ADMIN)) {
models.put(new DefaultResultModel(CoreResultCode.ROLE_FORCE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
} else {
models.put(new DefaultResultModel(CoreResultCode.ROLE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
}
}
});
long conceptsToModify = //
entities.stream().map(roleId -> {
IdmConceptRoleRequestFilter roleRequestFilter = new IdmConceptRoleRequestFilter();
roleRequestFilter.setRoleId(roleId);
return conceptRoleRequestService.count(roleRequestFilter);
}).reduce(0L, Long::sum);
ResultModel conceptCountResult = null;
if (conceptsToModify > 0) {
conceptCountResult = new DefaultResultModel(CoreResultCode.ROLE_DELETE_BULK_ACTION_CONCEPTS_TO_MODIFY, ImmutableMap.of("conceptCount", conceptsToModify));
}
// 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());
});
if (conceptCountResult != null) {
result.addInfo(conceptCountResult);
}
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkAction method prevalidate.
/**
* If no guarantee for selected identities exists,
* return the info in the result model.
*/
@Override
public ResultModels prevalidate() {
ResultModels result = new ResultModels();
IdmBulkActionDto action = getAction();
try {
List<UUID> guarantees = getContractGuaranteeIdentities(action);
if (guarantees.isEmpty()) {
result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_NO_CONTRACT_GUARANTEE_EXISTS));
}
if (guarantees.size() > 45) {
// this is because during autocomplete all IDs are put into the URL
// which has a max length of 2048
// the user will be shown all identities without the added filtering
result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_TOO_MANY_CONTRACT_GUARANTEE_EXIST));
}
} catch (FilterSizeExceededException e) {
result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_TOO_MANY_USERS_SELECTED, Map.of("maximum", e.getMaximum())));
}
return result;
}
Aggregations