use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteContractGuaranteeWithoutProvisioning.
@Test
public void testDeleteContractGuaranteeWithoutProvisioning() {
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmIdentityDto guarantee = testHelper.createIdentity();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
IdmContractGuaranteeDto contractGuarantee = testHelper.createContractGuarantee(primeContract.getId(), guarantee.getId());
// delete
contractGuaranteeService.delete(contractGuarantee);
//
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(identity.getId());
List<SysProvisioningArchiveDto> content = provisioningArchiveService.find(filter, null).getContent();
assertEquals(0, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto 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.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkActionTest method ifMultipleSameGuaranteesRemoveAll.
@Test
public void ifMultipleSameGuaranteesRemoveAll() {
List<IdmIdentityDto> guarantees = this.createIdentities(4);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
createContractGuarantees(contract1, guarantees.subList(0, guarantees.size()));
// first guarantee assigned twice - possible from UI
createContractGuarantees(contract1, guarantees.subList(0, 1));
Assert.assertEquals(guarantees.size() + 1, getGuaranteesForContract(contract1.getId()).size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRemoveContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
// selected identityDtos
List<String> uuidStrings = guarantees.subList(0, guarantees.size() - 1).stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, uuidStrings);
bulkAction.setProperties(properties);
bulkActionManager.processAction(bulkAction);
// test that there remains only one guarantee
// both instances of the twice added guarantee were removed
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(1, assigned.size());
Assert.assertEquals(guarantees.get(guarantees.size() - 1).getId(), assigned.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto 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.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkActionTest method processByIdsRemoveSelected.
@Test
public void processByIdsRemoveSelected() {
List<IdmIdentityDto> guarantees = this.createIdentities(4);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
IdmIdentityContractDto contract2 = getHelper().createContract(employee);
createContractGuarantees(contract1, guarantees.subList(0, guarantees.size() - 1));
createContractGuarantees(contract2, guarantees.subList(1, guarantees.size()));
Assert.assertTrue(isContractGuarantee(contract1, guarantees.subList(0, guarantees.size() - 1)).isEmpty());
Assert.assertTrue(isContractGuarantee(contract2, guarantees.subList(1, guarantees.size())).isEmpty());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRemoveContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
// selected identityDtos
List<String> uuidStrings = guarantees.subList(1, 3).stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, uuidStrings);
bulkAction.setProperties(properties);
bulkActionManager.processAction(bulkAction);
// test that there remains on both contracts only one guarantee
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(1, assigned.size());
Assert.assertEquals(guarantees.get(0).getId(), assigned.get(0).getGuarantee());
assigned = getGuaranteesForContract(contract2.getId());
Assert.assertEquals(1, assigned.size());
Assert.assertEquals(guarantees.get(3).getId(), assigned.get(0).getGuarantee());
}
Aggregations