use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityAddContractGuaranteeBulkActionTest 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 withoutPermissionDeleteGuarantee.
@Test
@Transactional
public void withoutPermissionDeleteGuarantee() {
List<IdmIdentityDto> guarantees = this.createIdentities(1);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
Assert.assertEquals(0, getGuaranteesForContract(contract1.getId()).size());
// init guarantee to delete
createContractGuarantees(contract1, guarantees);
Assert.assertEquals(guarantees.size(), getGuaranteesForContract(contract1.getId()).size());
Assert.assertTrue(isContractGuarantee(contract1, guarantees).isEmpty());
// Log as user without delete permission
IdmIdentityDto identityForLogin = getHelper().createIdentity();
IdmRoleDto permissionRole = getHelper().createRole();
getHelper().createBasePolicy(permissionRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.COUNT);
getHelper().createIdentityRole(identityForLogin, permissionRole);
loginAsNoAdmin(identityForLogin.getUsername());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRemoveContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
List<String> uuidStrings = guarantees.stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, uuidStrings);
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, null, 0l, 1l);
// test guarantes on all contracts
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(guarantees.size(), assigned.size());
Assert.assertTrue(isContractGuarantee(contract1, guarantees).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeDeleteProvisioningProcessor method process.
@Override
public EventResult<IdmContractGuaranteeDto> process(EntityEvent<IdmContractGuaranteeDto> event) {
IdmContractGuaranteeDto contractGuarantee = event.getContent();
UUID contractId = contractGuarantee.getIdentityContract();
IdmIdentityContractDto contract = identityContractService.get(contractId);
if (contract == null) {
LOG.debug("Contract [{}] was already deleted, duplicate provisioning will be skipped.", contractId);
//
return new DefaultEventResult<>(event, this);
}
//
LOG.debug("Publish change for identity [{}], contract guarantee will be added.", contract.getIdentity());
//
entityEventManager.changedEntity(IdmIdentityDto.class, contract.getIdentity(), event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveProvisioningProcessor method process.
@Override
public EventResult<IdmContractGuaranteeDto> process(EntityEvent<IdmContractGuaranteeDto> event) {
IdmContractGuaranteeDto contractGuarantee = event.getContent();
UUID contractId = contractGuarantee.getIdentityContract();
IdmIdentityContractDto contract = identityContractService.get(contractId);
if (contract == null) {
LOG.debug("Contract [{}] was already deleted, duplicate provisioning will be skipped.", contractId);
//
return new DefaultEventResult<>(event, this);
}
//
LOG.debug("Publish change for identity [{}], contract guarantee will be added.", contract.getIdentity());
//
entityEventManager.changedEntity(IdmIdentityDto.class, contract.getIdentity(), event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testCreateGuaranteeOfContractWithSlice.
@Test
public void testCreateGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
// guarantee can't be created directly
try {
getHelper().createContractGuarantee(contractId, sliceGuarantee.getId());
fail("Contract guarantee can't be created directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_MODIFIED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
// contract slice guarantee can be created
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());
// applying slice with guarantee causes creating of contract guarantee which is correct
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());
}
Aggregations