use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method save.
/**
* Save entity
*
* @param entity
* @param skipProvisioning
* @return
*/
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning) {
if (entity.getIdentity() == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
// We do not want execute HR processes for every contract. We need start
// them for every identity only once.
// For this we skip them now. HR processes must be start after whole
// sync finished (by using dependent scheduled task)!
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
//
// We don't want recalculate automatic role by attribute recalculation for every contract.
// Recalculation will be started only once.
event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, Boolean.TRUE);
IdmIdentityContractDto contract = contractService.publish(event).getContent();
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
// Search guarantees to delete
List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
}).collect(Collectors.toList());
// Search guarantees to add
List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
return !currentGuarantees.stream().filter(currentGuarrantee -> {
return identity.getId().equals(currentGuarrantee.getGuarantee());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Delete guarantees
guaranteesToDelete.forEach(guarantee -> {
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
// Create new guarantees
guaranteesToAdd.forEach(identity -> {
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(contract.getId());
guarantee.setGuarantee(identity.getId());
//
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
}
return contract;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testLinkAndUpdateContract.
@Test
public void testLinkAndUpdateContract() {
String position1 = "test-link-update-1-" + System.currentTimeMillis();
String position2 = "test-link-update-2-" + System.currentTimeMillis();
String position3 = "test-link-update-3-" + System.currentTimeMillis();
IdmIdentityDto leader = helper.createIdentity();
IdmTreeNodeDto workPosition = helper.createTreeNode();
SysSystemDto system = initData();
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
this.getBean().deleteAllResourceData();
config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
IdmIdentityDto identity1 = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityContractDto contrac1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto contrac2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto contrac3 = helper.getPrimeContract(identity3.getId());
contrac1.setPosition(position1);
contrac1.setDescription(position1);
contrac2.setPosition(position2);
contrac2.setDescription(position2);
contrac3.setPosition(position3);
contrac3.setDescription(position3);
contrac1 = contractService.save(contrac1);
contrac2 = contractService.save(contrac2);
contrac3 = contractService.save(contrac3);
// check empty guarantee
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contrac1.getId());
List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
assertNull(contrac1.getState());
assertNull(contrac2.getState());
assertNull(contrac3.getState());
this.getBean().createContractData(position1, identity1.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position2, identity2.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position3, identity3.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
// Start sync
helper.startSynchronization(config);
contractService.findAllByIdentity(identity1.getId());
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityContractDto updatedContract1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto updatedContract2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto updatedContract3 = helper.getPrimeContract(identity3.getId());
assertNotEquals(updatedContract1.getModified(), contrac1.getModified());
assertNotEquals(updatedContract2.getModified(), contrac2.getModified());
assertNotEquals(updatedContract3.getModified(), contrac3.getModified());
assertNotEquals(updatedContract1.getState(), contrac1.getState());
assertNotEquals(updatedContract2.getState(), contrac2.getState());
assertNotEquals(updatedContract3.getState(), contrac3.getState());
assertEquals(ContractState.EXCLUDED, updatedContract1.getState());
assertEquals(ContractState.EXCLUDED, updatedContract2.getState());
assertEquals(ContractState.EXCLUDED, updatedContract3.getState());
assertEquals(contrac1.getId(), updatedContract1.getId());
assertEquals(contrac2.getId(), updatedContract2.getId());
assertEquals(contrac3.getId(), updatedContract3.getId());
guaranteeFilter.setIdentityContractId(contrac1.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testDifferentSyncChangeGuarantee.
@Test
public void testDifferentSyncChangeGuarantee() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmIdentityDto defaultLeader = helper.createIdentity(CONTRACT_LEADER_TWO);
// Set default leader to sync configuration
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultLeader(defaultLeader.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Enable different sync.
config.setDifferentialSync(true);
config = syncConfigService.save(config);
Assert.assertTrue(config.isDifferentialSync());
// Start sync with enable different sync - no change was made on
// identity, so only ignore update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 3, OperationResultType.IGNORE);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractsOne.get(0).getId());
List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, gurantees.size());
IdmIdentityDto guarantee = DtoUtils.getEmbedded(gurantees.get(0), IdmContractGuarantee_.guarantee);
// Direct leader from resource
Assert.assertEquals(CONTRACT_LEADER_ONE, guarantee.getUsername());
guaranteeService.delete(gurantees.get(0));
// Start sync with enable different sync - guarantee was deleted
// so standard update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractDeleteProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
UUID contractId = contract.getId();
Assert.notNull(contractId, "Contract must have a ID!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// check contract can be deleted - cannot be deleted, when is controlled by slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(contractId);
if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
// Cannot be enforced => contract cannot be deleted at all.
throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_CANNOT_BE_DELETED, ImmutableMap.of("contractId", contractId));
}
//
// Find all concepts and remove relation on contract
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityContractId(contractId);
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contractId, concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contractId);
// Cancel concept and WF
concept = conceptRequestService.cancel(concept);
}
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
//
// delete referenced roles
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
identityRoleService.findAllByContract(contractId).forEach(identityRole -> {
// but automatic roles has to be removed in the same request.
if (identityRole.getDirectRole() == null) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
// ignore not found
conceptRoleRequest.setIdentityContract(contractId);
//
concepts.add(conceptRoleRequest);
}
});
if (forceDelete) {
// ~ async with force
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(contract.getIdentity());
roleRequest.setConceptRoles(concepts);
//
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.setPriority(PriorityType.HIGH);
//
roleRequestService.startConcepts(requestEvent, event);
} else {
// ~ sync
roleRequestService.executeConceptsImmediate(contract.getIdentity(), concepts);
}
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contractId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// delete contract positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contractId);
contractPositionService.find(positionFilter, null).forEach(position -> {
contractPositionService.delete(position);
});
//
// delete all contract's delegations
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorContractId(contractId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// delete identity contract
if (forceDelete) {
LOG.debug("Contract [{}] should be deleted by caller after all asynchronus processes are completed.", contractId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(contract, stateDeleted);
//
// set disabled
contract.setState(ContractState.DISABLED);
service.saveInternal(contract);
} else {
service.deleteInternal(contract);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityAddContractGuaranteeBulkActionTest method getGuaranteesForContract.
/**
* Gets all contractGuarantees for contract
* @param contract
* @return
*/
private List<IdmContractGuaranteeDto> getGuaranteesForContract(UUID contract) {
IdmContractGuaranteeFilter filt = new IdmContractGuaranteeFilter();
filt.setIdentityContractId(contract);
return contractGuaranteeService.find(filt, null).getContent();
}
Aggregations