use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteGuaranteeOfContractWithSlice.
@Test
public void testDeleteGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(1, sliceGuarantees.size());
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, contractGuarantees.size());
IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
try {
contractGuaranteeService.delete(contractGuarantees.get(0));
fail("Contract guarantee can't be deleted directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
// guarantee can be still deleted via contract slice operation
contractSliceGuaranteeService.delete(sliceGuarantees.get(0));
sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(0, sliceGuarantees.size());
contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkActionTest method isContractGuarantee.
/**
* Tests if there are all identities contract guarantees
* If some of them are not contract guarantees, they are returned
* Empty returned List means that there are all identities contract guarantees
*
* @param contract
* @param guarantees
* @return
*/
private List<IdmIdentityDto> isContractGuarantee(IdmIdentityContractDto contract, List<IdmIdentityDto> guarantees) {
IdmContractGuaranteeFilter filt = new IdmContractGuaranteeFilter();
filt.setIdentityContractId(contract.getId());
Set<UUID> cgUUIDs = contractGuaranteeService.find(filt, null).getContent().stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
return guarantees.stream().filter(ident -> !cgUUIDs.contains(ident.getId())).collect(Collectors.toList());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkActionTest 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();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
Assert.notNull(identityId, "Identity ID is required!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// delete contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setIdentity(identityId);
contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
contractSliceService.delete(guarantee);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteeFilter.setGuaranteeId(identityId);
contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
contractSliceGuaranteeService.delete(guarantee);
});
//
// contracts
identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
// when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
Map<String, Serializable> properties = new HashMap<>();
properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
// propagate force attribute
properties.put(PROPERTY_FORCE_DELETE, forceDelete);
// prepare event
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
contractEvent.setPriority(PriorityType.HIGH);
//
identityContractService.publish(contractEvent);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identityId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// remove role guarantee
IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
roleGuaranteeFilter.setGuarantee(identityId);
roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
roleGuaranteeService.delete(roleGuarantee);
});
// remove password
passwordProcessor.deletePassword(identity);
// delete password history for identity
passwordHistoryService.deleteAllByIdentity(identityId);
// disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
tokenManager.disableTokens(identity);
//
// delete all identity's profiles
IdmProfileFilter profileFilter = new IdmProfileFilter();
profileFilter.setIdentityId(identityId);
profileService.find(profileFilter, null).forEach(profile -> {
profileService.delete(profile);
});
// remove all IdentityRoleValidRequest for this identity
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
identityRoleValidRequestService.deleteAll(validRequests);
//
// delete all identity's delegations - delegate
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegateId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
//
// delete all identity's delegations - delegator
delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// deletes identity
if (forceDelete) {
LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
//
// 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(identity, stateDeleted);
//
// set disabled (automatically)
identity.setState(IdentityState.DISABLED);
service.saveInternal(identity);
} else {
// delete all role requests where is this identity applicant
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identityId);
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
//
service.deleteInternal(identity);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityServiceIntegrationTest method testReferentialIntegrity.
@Test
@Transactional
public void testReferentialIntegrity() {
IdmIdentityDto identity = getHelper().createIdentity();
String username = identity.getUsername();
// eav
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_PASSWORD));
value1.setValue("one");
formService.saveValues(identity.getId(), IdmIdentity.class, formDefinition, Lists.newArrayList(value1));
// role with guarantee
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleGuarantee(role, identity);
// contract
IdmIdentityContractDto contract = getHelper().createContract(identity);
// contract guarantee
IdmIdentityContractDto contract2 = getHelper().createContract(identityService.getByUsername(InitTestDataProcessor.TEST_USER_1));
contractGuaranteeService.save(new IdmContractGuaranteeDto(contract2.getId(), identity.getId()));
// assigned role
getHelper().createIdentityRole(contract, role);
IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
identityRolefilter.setIdentityId(identity.getId());
// profile
getHelper().createProfile(identity);
// token
IdmTokenDto token = new IdmTokenDto();
token.setToken("token");
token.setTokenType("test");
token = tokenManager.saveToken(identity, token);
//
Assert.assertNotNull(tokenManager.getToken(token.getId()));
Assert.assertNotNull(profileService.findOneByIdentity(identity.getId()));
Assert.assertNotNull(identityService.getByUsername(username));
Assert.assertNotNull(passwordService.findOneByIdentity(identity.getId()));
Assert.assertEquals(1, formService.getValues(identity).size());
Assert.assertEquals(identity.getId(), roleGuaranteeService.findByRole(role.getId(), null).getContent().get(0).getGuarantee());
Assert.assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
// + default contract is created
Assert.assertEquals(2, identityContractService.findAllByIdentity(identity.getId()).size());
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract2.getId());
List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
Assert.assertEquals(1, guarantees.size());
Assert.assertEquals(identity.getId(), guarantees.get(0).getGuarantee());
//
identityService.delete(identity);
role = roleService.get(role.getId());
//
Assert.assertEquals(0L, roleGuaranteeService.findByRole(role.getId(), null).getTotalElements());
Assert.assertNull(identityService.getByUsername(username));
Assert.assertNull(passwordService.findOneByIdentity(identity.getId()));
Assert.assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
Assert.assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
Assert.assertEquals(0, contractGuaranteeService.find(filter, null).getTotalElements());
Assert.assertNull(profileService.findOneByIdentity(identity.getId()));
Assert.assertTrue(tokenManager.getToken(token.getId()).isDisabled());
}
Aggregations