use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testProjectionDontSaveOtherContractsAndPositions.
@Test
@Transactional
public void testProjectionDontSaveOtherContractsAndPositions() {
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection = projectionService.save(formProjection);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
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.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.assertTrue(createdProjection.getOtherContracts().isEmpty());
// other position
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto 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.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testLoadAssignedRoles.
@Test
@Transactional
public void testLoadAssignedRoles() {
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection = projectionService.save(projection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(projection.getId());
identity = identityService.save(identity);
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
getHelper().createIdentityRole(primeContract, getHelper().createRole());
//
IdmIdentityProjectionDto identityProjection = manager.get(identity.getId());
Assert.assertFalse(identityProjection.getIdentityRoles().isEmpty());
//
projection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
projectionService.save(projection);
identityProjection = manager.get(identity.getId());
Assert.assertTrue(identityProjection.getIdentityRoles().isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdmFormProjectionControllerRestTest method prepareDto.
@Override
protected IdmFormProjectionDto prepareDto() {
IdmFormProjectionDto dto = new IdmFormProjectionDto();
dto.setCode(getHelper().createName());
dto.setOwnerType(getHelper().createName());
//
return dto;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method updateIdentityWithUserTypeTest.
@Test
public void updateIdentityWithUserTypeTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.LINK);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// Create projection
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setOwnerType(IdmIdentity.class.getCanonicalName());
projection.setCode(getHelper().createName());
projection.setDisabled(false);
projection = formProjectionService.save(projection);
SysSchemaAttributeDto someSchemaAttribute = schemaAttributeService.find(schemaAttributeFilter, null).getContent().get(0);
Assert.assertNotNull(someSchemaAttribute);
// Create attribute returns code of projection.
SysSystemAttributeMappingDto projectionAttribute = new SysSystemAttributeMappingDto();
projectionAttribute.setIdmPropertyName(IdmIdentity_.formProjection.getName());
projectionAttribute.setEntityAttribute(true);
projectionAttribute.setExtendedAttribute(false);
projectionAttribute.setName(IdmIdentity_.formProjection.getName());
projectionAttribute.setSchemaAttribute(someSchemaAttribute.getId());
projectionAttribute.setSystemMapping(config.getSystemMapping());
projectionAttribute.setTransformFromResourceScript(MessageFormat.format("return \"{0}\";", projection.getCode()));
projectionAttribute = schemaAttributeMappingService.save(projectionAttribute);
IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
Assert.assertEquals(1, roles.size());
Assert.assertEquals(defaultRole.getId(), roles.get(0).getRole());
identityOne = identityService.get(identityOne.getId());
// Identity must have sets projection.
Assert.assertNotNull(identityOne);
Assert.assertNotNull(identityOne.getFormProjection());
Assert.assertEquals(projection.getId(), identityOne.getFormProjection());
// Delete log
syncLogService.delete(log);
// Delete projection attribute and projection.
schemaAttributeMappingService.delete(projectionAttribute);
formProjectionService.delete(projection);
}
Aggregations