use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetSimpleIdentity.
@Test
@Transactional
public void testSaveAndGetSimpleIdentity() {
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
Assert.assertNull(createdProjection.getContract());
Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeRequiredFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeRequiredFailed() 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);
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.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testSaveProjectionWithoutContractAuthority.
@Transactional
@Test(expected = ForbiddenEntityException.class)
public void testSaveProjectionWithoutContractAuthority() {
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.CREATE, IdmBasePermission.UPDATE);
getHelper().createIdentityRole(identityLogged, role);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(new IdmIdentityContractDto());
//
try {
// empty property => disable default role
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
//
getHelper().login(identityLogged);
//
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection), IdmBasePermission.CREATE).getContent();
} finally {
logout();
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
}
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeMaxFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeMaxFailed() 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.TEN);
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("aabbaabbaabbcc");
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.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeMinFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeMinFailed() 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.TEN);
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("abc");
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);
}
Aggregations