Search in sources :

Example 11 with IdmFormProjectionDto

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());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IdmFormProjectionDto

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);
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with IdmFormProjectionDto

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());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with IdmFormProjectionDto

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;
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)

Example 15 with IdmFormProjectionDto

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);
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Aggregations

IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)36 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)21 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)17 Transactional (org.springframework.transaction.annotation.Transactional)16 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)13 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)12 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)12 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)12 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)10 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)6 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 UUID (java.util.UUID)4 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)3