use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdentityRemoveRoleBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
List<IdmIdentityContractDto> contracts = new ArrayList<>();
if (this.isPrimaryContract()) {
IdmIdentityContractDto contract = identityContractService.getPrimeValidContract(identity.getId());
if (contract != null) {
contracts.add(contract);
}
} else {
contracts.addAll(identityContractService.findAllByIdentity(identity.getId()));
}
// contract empty return not processed
if (contracts.isEmpty()) {
LOG.warn("For identity id: [{}] username: [{}] wasn't found contranct.", identity.getId(), identity.getUsername());
return new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_CONTRACT_NOT_FOUND, //
ImmutableMap.of("identity", identity.getId()))).build();
}
boolean approve = isApprove();
List<IdmRoleDto> roles = getRoles();
Set<UUID> rolesIds = roles.stream().map(IdmRoleDto::getId).collect(Collectors.toSet());
//
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
for (IdmIdentityContractDto contract : contracts) {
if (!checkPermissionForContract(contract)) {
LOG.warn("Insufficient permissions for asign role for contract [{}]", contract.getId());
//
logItemProcessed(contract, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_NOT_AUTHORIZED_ASSING_ROLE_FOR_CONTRACT, ImmutableMap.of("contractId", contract.getId()))).build());
//
continue;
}
// check if contract has role
List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contract.getId());
Set<UUID> roleIdsSet = allByContract.stream().map(IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
if (Collections.disjoint(roleIdsSet, rolesIds)) {
// contract hasn't assigned the roles
continue;
}
//
for (IdmRoleDto role : roles) {
List<IdmIdentityRoleDto> identityRoles = allByContract.stream().filter(ir -> ir.getRole().equals(role.getId())).filter(// direct role
ir -> ir.getDirectRole() == null).filter(// not automatic
ir -> ir.getAutomaticRole() == null).collect(Collectors.toList());
if (identityRoles.isEmpty()) {
continue;
}
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRole(role.getId());
concept.setIdentityContract(contract.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
}
}
}
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(identity.getId());
roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
roleRequest.setLog("Request was created by bulk action.");
// if set approve, dont execute immediately
roleRequest.setExecuteImmediately(!approve);
roleRequest = roleRequestService.save(roleRequest, IdmBasePermission.CREATE);
//
for (IdmConceptRoleRequestDto concept : concepts) {
concept.setRoleRequest(roleRequest.getId());
concept = conceptRoleRequestService.save(concept, IdmBasePermission.CREATE);
}
//
Map<String, Serializable> properties = new HashMap<>();
properties.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.TRUE);
RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest, properties);
event.setPriority(PriorityType.HIGH);
roleRequest = roleRequestService.startRequestInternal(event);
//
if (roleRequest.getState() == RoleRequestState.EXECUTED) {
return new OperationResult.Builder(OperationState.EXECUTED).build();
} else {
return new OperationResult.Builder(OperationState.CREATED).build();
}
}
//
LOG.warn("For identity id: [{}] username: [{}] wasn't found roles to removal." + " Roles not found or cannot be removed (its automatic role, business role or for insufficient permissions).", identity.getId(), identity.getUsername());
return new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_IDENTITY_REMOVE_ROLE_FAILED, //
ImmutableMap.of("identity", identity.getId()))).build();
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkAction 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;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class FormValueDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<IdmFormValueDto> values = getValues(action, null);
ResultModels result = new ResultModels();
Map<UUID, IdmFormAttributeDto> attributes = new HashMap<>();
Map<UUID, Long> requiredAttributes = new HashMap<>();
values.forEach(value -> {
IdmFormAttributeDto attribute;
UUID attributeId = value.getFormAttribute();
if (attributes.containsKey(attributeId)) {
attribute = attributes.get(attributeId);
} else {
attribute = getAttribute(value);
// prevent to load attributes repetitively, if is not given in dto embedded
attributes.put(attribute.getId(), attribute);
}
if (attribute.isRequired()) {
Long count;
if (requiredAttributes.containsKey(attributeId)) {
count = requiredAttributes.get(attributeId) + 1;
} else {
count = 1L;
}
requiredAttributes.put(attributeId, count);
}
});
// Sort by count
//
requiredAttributes.entrySet().stream().sorted(//
Collections.reverseOrder(Map.Entry.comparingByValue())).forEach(entry -> {
IdmFormAttributeDto attribute = attributes.get(entry.getKey());
ResultModel model = new DefaultResultModel(CoreResultCode.FORM_VALUE_DELETE_FAILED_IS_REQUIRED, ImmutableMap.of("count", entry.getValue(), "attribute", attribute.getCode()));
//
result.addInfo(model);
});
//
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ManualWorkflowTaskDelegationBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
ResultModels result = new ResultModels();
IdmIdentityDto delegator = this.findDelegator();
if (delegator == null) {
result.addInfo(new DefaultResultModel(CoreResultCode.MANUAL_TASK_DELEGATION_DELEGATOR_MISSING));
}
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class RoleCatalogueDeleteBulkAction 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(roleCatalogueId -> {
IdmRoleCatalogueFilter filter = new IdmRoleCatalogueFilter();
filter.setParent(roleCatalogueId);
filter.setRecursively(true);
IdmRoleCatalogueDto roleCatalogue = getService().get(roleCatalogueId);
long count = roleCatalogueService.count(filter);
if (count > 0) {
if (securityService.hasAnyAuthority(CoreGroupPermission.ROLECATALOGUE_ADMIN)) {
models.put(new DefaultResultModel(CoreResultCode.ROLE_CATALOGUE_FORCE_DELETE_HAS_CHILDREN, ImmutableMap.of("roleCatalogue", roleCatalogue.getCode(), "count", count)), count);
} else {
models.put(new DefaultResultModel(CoreResultCode.ROLE_CATALOGUE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("roleCatalogue", roleCatalogue.getCode(), "count", count)), count);
}
}
});
//
// 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;
}
Aggregations