use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityAndContractEav.
@Test
public void testAssignAutomaticRoleIdentityAndContractEav() throws Exception {
UUID identityId = null;
try {
getHelper().enableAsynchronousProcessing();
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmRoleDto roleContract = getHelper().createRole();
IdmRoleDto subRoleContract = getHelper().createRole();
getHelper().createRoleComposition(roleContract, subRoleContract);
//
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
//
IdmFormAttributeDto formAttributeContract = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(formAttributeContract));
formAttributeContract = formDefinitionContract.getMappedAttributeByCode(formAttributeContract.getCode());
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
// form projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(formAttributeOne.getId());
FormDefinitionAttributes attributesContract = new FormDefinitionAttributes();
attributesContract.setDefinition(formDefinitionContract.getId());
attributesContract.getAttributes().add(formAttributeContract.getId());
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes, attributesContract)));
formProjection = projectionService.save(formProjection);
//
// prepare identity projection with two contract
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(formProjection.getId());
IdmFormValueDto formValue = new IdmFormValueDto(formAttributeOne);
formValue.setValue("mockOne");
identity.getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
contractOne.setPosition(getHelper().createName());
IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
contractTwo.setPosition(getHelper().createName());
IdmFormValueDto formValueContract = new IdmFormValueDto(formAttributeContract);
formValueContract.setValue("mockContract");
contractTwo.getEavs().add(new IdmFormInstanceDto(contractTwo, formDefinitionContract, Lists.newArrayList(formValueContract)));
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(contractOne);
projection.setOtherContracts(Lists.newArrayList(contractTwo));
//
// create by projection
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
identityId = createdProjection.getIdentity().getId();
Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
IdmIdentityContractDto primeContract = createdProjection.getContract();
Assert.assertNotNull(primeContract);
Assert.assertEquals(contractOne.getPosition(), primeContract.getPosition());
Assert.assertEquals(1, createdProjection.getOtherContracts().size());
IdmIdentityContractDto otherContract = createdProjection.getOtherContracts().get(0);
Assert.assertEquals(contractTwo.getPosition(), otherContract.getPosition());
//
// 6 roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(createdProjection.getIdentity().getId());
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 6;
});
List<IdmIdentityRoleDto> identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(6, identityRoles.size());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(role.getId())).count());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(subRole.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
//
// change eav value => remove all automatic roles
formValue.setValue("mockUpdate");
createdProjection.getIdentity().getEavs().clear();
createdProjection.getIdentity().getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 2;
});
//
identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(2, identityRoles.size());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
} finally {
getHelper().disableAsynchronousProcessing();
getHelper().deleteIdentity(identityId);
}
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testGetProjectionEavReadOnly.
@Test
@Transactional
public void testGetProjectionEavReadOnly() {
// create identity with read permission only
// with password
IdmIdentityDto identityLogged = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
// read all
getHelper().createBasePolicy(role.getId(), // form definition autocomplete is required
IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
getHelper().createIdentityRole(identityLogged, role);
//
// 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));
//
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
getHelper().login(identityLogged);
try {
IdmIdentityProjectionDto createdProjection = manager.get(projection, IdmBasePermission.READ);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
Assert.assertTrue(createdProjection.getIdentity().getEavs().stream().allMatch(i -> {
return i.getFormDefinition().getFormAttributes().stream().allMatch(IdmFormAttributeDto::isReadonly);
}));
// 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 eavs
Assert.assertTrue(createdProjection.getContract().getEavs().stream().allMatch(i -> {
return i.getFormDefinition().getFormAttributes().stream().allMatch(IdmFormAttributeDto::isReadonly);
}));
Assert.assertEquals(valueContract.getValue(), createdProjection.getContract().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionContract.getId())).findFirst().get().toSinglePersistentValue(attributeContract.getCode()));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testGetProjectionWithoutContractAuthority.
@Test
@Transactional
public void testGetProjectionWithoutContractAuthority() {
String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
// create identity with update identity permission only
// with password
IdmIdentityDto identityLogged = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
// read all
getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.UPDATE);
getHelper().createIdentityRole(identityLogged, role);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// 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);
//
// 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));
//
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// assigned roles
getHelper().createIdentityRole(projection.getIdentity(), role);
try {
// empty property => disable default role
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
//
getHelper().login(identityLogged);
IdmIdentityProjectionDto createdProjection = manager.get(projection, IdmBasePermission.READ);
//
Assert.assertNotNull(createdProjection);
Assert.assertNull(createdProjection.getContract());
Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
//
createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getContract());
Assert.assertFalse(createdProjection.getOtherContracts().isEmpty());
Assert.assertFalse(createdProjection.getOtherPositions().isEmpty());
Assert.assertFalse(createdProjection.getIdentityRoles().isEmpty());
} finally {
logout();
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
}
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testDeleteOtherContractAndPosition.
@Test
@Transactional
public void testDeleteOtherContractAndPosition() {
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// 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);
//
// 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));
IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// 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(createdProjection.getContract().getId());
}));
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
//
// remove contract and position
createdProjection.getOtherContracts().removeIf(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
});
createdProjection.getOtherPositions().removeIf(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdProjection.getContract().getId());
});
IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
// other contract
Assert.assertEquals(1, updatedProjection.getOtherContracts().size());
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());
}));
// other position
Assert.assertEquals(1, updatedProjection.getOtherPositions().size());
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
}
Aggregations