use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationBulkActionTest method testSevenManuallyOneContract.
@Test
public void testSevenManuallyOneContract() {
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto two = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto three = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto four = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto five = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto six = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto seven = getHelper().createIdentityRole(identity, role);
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(7, roles.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRoleByIdentityDeduplicationBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(identity.getId()));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
IdmLongRunningTaskDto longRunningTask = checkResultLrt(processAction, 1l, null, null);
Assert.assertEquals(OperationState.EXECUTED, longRunningTask.getResultState());
// item
List<IdmProcessedTaskItemDto> processedItems = processedTaskItemService.findLogItems(longRunningTask, null).getContent();
Assert.assertEquals(1, processedItems.size());
// background request
IdmRoleRequestFilter requestFilter = new IdmRoleRequestFilter();
requestFilter.setApplicantId(identity.getId());
List<IdmRoleRequestDto> requests = roleRequestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
Assert.assertEquals(RoleRequestState.EXECUTED, requests.get(0).getState());
Assert.assertEquals(OperationState.EXECUTED, processedItems.get(0).getOperationResult().getState());
roles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, roles.size());
IdmIdentityRoleDto actual = roles.get(0);
assertEquals(one.getId(), actual.getId());
assertNotEquals(two.getId(), actual.getId());
assertNotEquals(three.getId(), actual.getId());
assertNotEquals(four.getId(), actual.getId());
assertNotEquals(five.getId(), actual.getId());
assertNotEquals(six.getId(), actual.getId());
assertNotEquals(seven.getId(), actual.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetFullProjectionGreenLine.
@Test
@Transactional
public void testSaveAndGetFullProjectionGreenLine() {
// role request implementer is needed
loginAsAdmin();
Assert.assertFalse(eventConfiguration.isAsynchronous());
//
try {
// prepare eav definition
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName());
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName());
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
attributeOne = formDefinitionOne.getMappedAttributeByCode(attributeOne.getCode());
attributeTwo = formDefinitionOne.getMappedAttributeByCode(attributeTwo.getCode());
IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(getHelper().createName());
attributeThree.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeThree));
attributeThree = formDefinitionTwo.getMappedAttributeByCode(attributeThree.getCode());
IdmFormAttributeDto attributeContract = new IdmFormAttributeDto(getHelper().createName());
attributeContract.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(attributeContract));
attributeContract = formDefinitionContract.getMappedAttributeByCode(attributeContract.getCode());
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
valueOne.setValue(getHelper().createName());
IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
valueTwo.setValue(getHelper().createName());
instanceOne.setValues(Lists.newArrayList(valueOne, valueTwo));
IdmFormInstanceDto instanceTwo = new IdmFormInstanceDto();
instanceTwo.setFormDefinition(formDefinitionTwo);
IdmFormValueDto valueThree = new IdmFormValueDto(attributeThree);
valueThree.setValue(getHelper().createName());
instanceTwo.setValues(Lists.newArrayList(valueThree));
identity.setEavs(Lists.newArrayList(instanceOne, instanceTwo));
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
projection.setContract(primeContract);
IdmFormInstanceDto instanceContract = new IdmFormInstanceDto();
instanceContract.setFormDefinition(formDefinitionContract);
IdmFormValueDto valueContract = new IdmFormValueDto(attributeContract);
valueContract.setValue(getHelper().createName());
instanceContract.setValues(Lists.newArrayList(valueContract));
primeContract.setEavs(Lists.newArrayList(instanceContract));
//
// set other contract
IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
otherContractOne.setPosition(getHelper().createName());
// preset uuid
IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
otherContractTwo.setPosition(getHelper().createName());
projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
//
// set other contract position
IdmContractPositionDto positionOne = new IdmContractPositionDto();
positionOne.setWorkPosition(getHelper().createTreeNode().getId());
positionOne.setPosition(getHelper().createName());
IdmContractPositionDto positionTwo = new IdmContractPositionDto();
positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
positionTwo.setPosition(getHelper().createName());
positionTwo.setIdentityContract(otherContractTwo.getId());
projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
//
// set assigned roles
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmIdentityRoleDto identityRoleOne = new IdmIdentityRoleDto();
identityRoleOne.setRole(roleOne.getId());
identityRoleOne.setValidFrom(LocalDate.now().plus(2l, ChronoUnit.DAYS));
IdmIdentityRoleDto identityRoleTwo = new IdmIdentityRoleDto();
identityRoleTwo.setRole(roleTwo.getId());
identityRoleTwo.setIdentityContract(otherContractTwo.getId());
projection.setIdentityRoles(Lists.newArrayList(identityRoleOne, identityRoleTwo));
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
projection = manager.publish(identityProjectionEvent).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
// eavs
Assert.assertEquals(valueOne.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
Assert.assertEquals(valueTwo.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
Assert.assertEquals(valueThree.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
// prime contract
IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
// eavs
Assert.assertEquals(valueContract.getValue(), createdProjection.getContract().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionContract.getId())).findFirst().get().toSinglePersistentValue(attributeContract.getCode()));
// other contract
Assert.assertEquals(2, createdProjection.getOtherContracts().size());
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
}));
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
// other position
Assert.assertEquals(2, createdProjection.getOtherPositions().size());
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
// assigned roles
// check directly by service
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(createdProjection.getIdentity().getId());
List<IdmRoleRequestDto> roleRequests = roleRequestService.find(roleRequestFilter, null).getContent();
Assert.assertFalse(roleRequests.isEmpty());
Assert.assertTrue(roleRequests.stream().allMatch(r -> r.getState() == RoleRequestState.EXECUTED));
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(createdProjection.getIdentity().getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
// check by projection
Assert.assertEquals(2, createdProjection.getIdentityRoles().size());
Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
//
// simple update
String newUsername = getHelper().createName();
createdProjection.getIdentity().setUsername(newUsername);
//
IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
// IdmIdentityProjectionDto updatedProjection = manager.get(projection);
//
Assert.assertNotNull(updatedProjection);
Assert.assertNotNull(updatedProjection.getId());
Assert.assertEquals(createdProjection.getId(), updatedProjection.getIdentity().getId());
Assert.assertEquals(newUsername, updatedProjection.getIdentity().getUsername());
// eavs
Assert.assertEquals(valueOne.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
Assert.assertEquals(valueTwo.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
Assert.assertEquals(valueThree.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
// prime contract
IdmIdentityContractDto updatedPrimeContract = updatedProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), updatedPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), updatedPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), updatedPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), updatedPrimeContract.getValidTill());
Assert.assertEquals(updatedProjection.getIdentity().getId(), updatedPrimeContract.getIdentity());
Assert.assertFalse(updatedPrimeContract.getControlledBySlices());
// other contract
Assert.assertEquals(2, updatedProjection.getOtherContracts().size());
Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
}));
Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
Assert.assertTrue(updatedProjection.getOtherContracts().stream().allMatch(c -> {
return !c.getControlledBySlices();
}));
// other position
Assert.assertEquals(2, updatedProjection.getOtherPositions().size());
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(updatedPrimeContract.getId());
}));
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
// assigned roles
Assert.assertEquals(2, updatedProjection.getIdentityRoles().size());
Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(updatedPrimeContract.getId());
}));
Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUniqueConceptValidation.
@Test(expected = InvalidFormException.class)
public void testUniqueConceptValidation() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes(true);
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Delete IP attribute from the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> roleFormAttributeService.delete(roleFormAttributeDto));
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(1, formAttributeSubdefinition.getFormAttributes().size());
Assert.assertEquals(NUMBER_OF_FINGERS, formAttributeSubdefinition.getFormAttributes().get(0).getCode());
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(0, identityRoles.size());
// Create request identity-role
IdmRequestIdentityRoleDto createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
IdmFormAttributeDto attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
IdmFormValueDto formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(5);
List<IdmFormValueDto> values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
List<IdmFormInstanceDto> forms = Lists.newArrayList(formInstanceDto);
createdRequestIdentityRole.setEavs(forms);
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Execute a role-request.
getHelper().executeRequest(request, false, true);
IdmRequestIdentityRoleFilter filterRequestIdentityRole = new IdmRequestIdentityRoleFilter();
filterRequestIdentityRole.setIdentityId(identity.getId());
filterRequestIdentityRole.setRoleRequestId(request.getId());
// Include EAV attributes
filterRequestIdentityRole.setIncludeEav(true);
// Check EAV value in the request-identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filterRequestIdentityRole, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(role.getId(), requestIdentityRoles.get(0).getRole());
Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().size());
IdmFormInstanceDto formInstance = requestIdentityRoles.get(0).getEavs().get(0);
Assert.assertEquals(1, formInstance.getValues().size());
IdmFormValueDto formValue = formInstance.getValues().get(0);
Serializable value = formValue.getValue();
Assert.assertEquals(((BigDecimal) formValueDto.getValue()).longValue(), ((BigDecimal) value).longValue());
IdmFormAttributeDto mappedAttribute = formInstance.getMappedAttribute(formValue.getFormAttribute());
Assert.assertNotNull(mappedAttribute);
Assert.assertNull(formInstance.getValidationErrors());
identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
// Create request identity-role
createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
formInstanceDto = new IdmFormInstanceDto();
attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(5);
values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
forms = Lists.newArrayList(formInstanceDto);
createdRequestIdentityRole.setEavs(forms);
requestIdentityRoleService.save(createdRequestIdentityRole);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateUpdatingConcept.
@Test
@Transactional
public void testUpdateUpdatingConcept() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
this.getHelper().createIdentityRole(contract, role, LocalDate.now().minusDays(1), null);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
// Create request for updated identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setIdentityRole(identityRoles.get(0).getId());
dto.setId(dto.getIdentityRole());
dto.setValidFrom(LocalDate.now().plusDays(5));
dto.setValidTill(LocalDate.now().minusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertEquals(LocalDate.now().plusDays(5), createdRequestIdentityRole.getValidFrom());
Assert.assertEquals(LocalDate.now().minusDays(10), createdRequestIdentityRole.getValidTill());
// We want to update created concept -> update validity
createdRequestIdentityRole.setValidFrom(LocalDate.now().minusDays(1));
createdRequestIdentityRole.setValidTill(LocalDate.now().plusDays(10));
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(ConceptRoleRequestOperation.UPDATE, concept.getOperation());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
this.getHelper().executeRequest(request, false, true);
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(LocalDate.now().minusDays(1), identityRoles.get(0).getValidFrom());
Assert.assertEquals(LocalDate.now().plusDays(10), identityRoles.get(0).getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testRemoveAddingConcept.
@Test
@Transactional
public void testRemoveAddingConcept() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
dto.setValidFrom(LocalDate.now().minusDays(1));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
// Delete adding concept
requestIdentityRoleService.deleteRequestIdentityRole(createdRequestIdentityRole);
request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are empty now
Assert.assertEquals(0, request.getConceptRoles().size());
}
Aggregations