use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeIsDeleted.
@Test
@Transactional
public void testValidateExtendedAttributeIsDeleted() throws Exception {
// prepare projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
//
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setCode(getHelper().createName());
attributeDefinitionTwo.setName(attributeDefinitionOne.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne, attributeDefinitionTwo));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
attributeDefinitionTwo = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionTwo.getCode());
//
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
attribute.setId(attributeDefinitionOne.getId());
attribute.setPersistentType(attributeDefinitionOne.getPersistentType());
attribute.setFormDefinition(attributeDefinitionOne.getFormDefinition());
attribute.setCode(attributeDefinitionOne.getCode());
attribute.setRequired(true);
attribute.setLabel("overriden");
attribute.setPlaceholder("overriden");
attribute.setMin(BigDecimal.TEN);
attribute.setMax(BigDecimal.TEN);
attribute.setRegex("[abc]");
attribute.setValidationMessage("Test validation failed.");
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attribute)));
formProjection = projectionService.save(formProjection);
//
formService.deleteAttribute(attributeDefinitionOne);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName(getHelper().createName());
identity.setFormProjection(formProjection.getId());
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueTwo = new IdmFormValueDto(attributeDefinitionTwo);
valueTwo.setValue("aabbaabbcc");
instanceOne.setValues(Lists.newArrayList(valueTwo));
identity.setEavs(Lists.newArrayList(instanceOne));
//
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
IdmIdentityProjectionDto createdProjection = manager.publish(identityProjectionEvent).getContent();
//
Assert.assertEquals(valueTwo.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeDefinitionTwo.getCode()));
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeRegexFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeRegexFailed() throws Exception {
// prepare projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
//
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
attribute.setId(attributeDefinitionOne.getId());
attribute.setPersistentType(attributeDefinitionOne.getPersistentType());
attribute.setFormDefinition(attributeDefinitionOne.getFormDefinition());
attribute.setCode(attributeDefinitionOne.getCode());
attribute.setRequired(true);
attribute.setLabel("overriden");
attribute.setPlaceholder("overriden");
attribute.setMin(BigDecimal.ONE);
attribute.setMax(BigDecimal.TEN);
attribute.setRegex("[abc]");
attribute.setValidationMessage("Test validation failed.");
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attribute)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName(getHelper().createName());
identity.setFormProjection(formProjection.getId());
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueOne = new IdmFormValueDto(attribute);
valueOne.setValue("abcd");
instanceOne.setValues(Lists.newArrayList(valueOne));
identity.setEavs(Lists.newArrayList(instanceOne));
//
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
manager.publish(identityProjectionEvent);
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityEav.
@Test
public void testAssignAutomaticRoleIdentityEav() 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);
//
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
//
// prepare identity projection with two contract
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
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());
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.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());
//
// 4 roles on each contract (2x role + sub) => role is assigned to each contract
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(createdProjection.getIdentity().getId());
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 4;
});
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(4, 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());
//
// 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().isEmpty();
});
//
identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertTrue(identityRoles.isEmpty());
} 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 testLoadProjectionDefinedEavsOnly.
@Test
@Transactional
public void testLoadProjectionDefinedEavsOnly() throws Exception {
//
// create definition with two attributes
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeTwo = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne, formAttributeTwo));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
formAttributeTwo = formDefinition.getMappedAttributeByCode(formAttributeTwo.getCode());
//
// create projection with one attribute
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(formAttributeOne.getId());
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes)));
projection = projectionService.save(projection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(projection.getId());
identity = identityService.save(identity);
//
// save some values
IdmFormValueDto formValueOne = new IdmFormValueDto(formAttributeOne);
formValueOne.setValue(getHelper().createName());
IdmFormValueDto formValueTwo = new IdmFormValueDto(formAttributeTwo);
formValueTwo.setValue(getHelper().createName());
List<IdmFormValueDto> formValues = Lists.newArrayList(formValueOne, formValueTwo);
identity.setEavs(Lists.newArrayList(new IdmFormInstanceDto(identity, formDefinition, formValues)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, new IdmIdentityProjectionDto(identity)));
//
IdmIdentityProjectionDto identityProjection = manager.get(identity.getId());
//
Assert.assertEquals(1, identityProjection.getIdentity().getEavs().size());
Assert.assertEquals(1, identityProjection.getIdentity().getEavs().get(0).getValues().size());
Assert.assertEquals(formValueOne.getValue(), identityProjection.getIdentity().getEavs().get(0).getValues().get(0).getValue());
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateBasicFieldsIdentityFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateBasicFieldsIdentityFailed() throws Exception {
// prepare projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
IdmFormAttributeDto attributeExternalCode = new IdmFormAttributeDto();
attributeExternalCode.setId(UUID.randomUUID());
attributeExternalCode.setCode(IdmIdentity_.externalCode.getName());
attributeExternalCode.setName(String.format("%s.%s", IdmIdentity.class.getSimpleName(), IdmIdentity_.externalCode.getName()));
attributeExternalCode.setRequired(true);
IdmFormAttributeDto attributeLastName = new IdmFormAttributeDto();
attributeLastName.setId(UUID.randomUUID());
attributeLastName.setCode(IdmIdentity_.lastName.getName());
attributeLastName.setMax(BigDecimal.valueOf(3));
IdmFormAttributeDto attributeValidTill = new IdmFormAttributeDto();
attributeValidTill.setId(UUID.randomUUID());
attributeValidTill.setCode(IdmIdentityContract_.validTill.getName());
attributeValidTill.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.validTill.getName()));
attributeValidTill.setRequired(true);
attributeValidTill.setMax(BigDecimal.valueOf(3));
attributeValidTill.setLabel("Custom label");
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attributeExternalCode, attributeLastName, attributeValidTill)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName("xxxx");
identity.setFormProjection(formProjection.getId());
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.setValidTill(LocalDate.now().plus(3l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
manager.publish(identityProjectionEvent);
}
Aggregations