Search in sources :

Example 21 with IdmFormProjectionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityControllerRestTest method createProjection.

protected IdmFormProjectionDto createProjection() {
    IdmFormProjectionDto dto = new IdmFormProjectionDto();
    dto.setCode(getHelper().createName());
    dto.setOwnerType(IdmIdentity.class.getCanonicalName());
    // 
    return formProjectionService.save(dto);
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 22 with IdmFormProjectionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method getIdentityRoles.

/**
 * Load assigned roles.
 *
 * @param dto
 * @param permission
 * @return
 */
protected List<IdmIdentityRoleDto> getIdentityRoles(IdmIdentityProjectionDto dto, BasePermission... permission) {
    // check all assigned roles has to be loaded
    IdmIdentityDto identity = dto.getIdentity();
    if (identity.getFormProjection() != null) {
        IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
        ConfigurationMap properties = formProjection.getProperties();
        // 
        if (// backward compatible
        properties.containsKey(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES) && !properties.getBooleanValue(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES)) {
            LOG.debug("Projection [{}] does not load all assigned roles.", formProjection.getCode());
            // 
            return Lists.newArrayList();
        }
    }
    // 
    // load all assigned identity roles
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    // 
    return Lists.newArrayList(identityRoleService.find(filter, null, permission).getContent());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)

Example 23 with IdmFormProjectionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method saveIdentity.

protected IdmIdentityDto saveIdentity(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdentityEventType eventType = IdentityEventType.CREATE;
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityDto identity = dto.getIdentity();
    IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
    // 
    if (previousProjection != null) {
        eventType = IdentityEventType.UPDATE;
        identity.setState(previousProjection.getIdentity().getState());
    } else {
        identity.setState(IdentityState.CREATED);
    }
    // 
    EntityEvent<IdmIdentityDto> identityEvent = new IdentityEvent(eventType, identity);
    // disable default contract creation
    identityEvent.getProperties().put(IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION, Boolean.TRUE);
    // if contract is saved with identity => automatic roles for identity has to be skipped,
    // will be recount with contract together
    // check contract has to be saved
    IdmIdentityContractDto contract = dto.getContract();
    if (contract != null) {
        if (identity.getFormProjection() == null) {
            LOG.debug("Automatic roles will be recount with contract together. Projection s not defined.");
            // 
            identityEvent.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
        } else {
            IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
            if (formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS) || formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_PRIME_CONTRACT)) {
                LOG.debug("Automatic roles will be recount with contract together. Projection [{}] saves contracts.", formProjection.getCode());
                // 
                identityEvent.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
            }
        }
    }
    // publish
    return identityService.publish(identityEvent, event, permission).getContent();
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) 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)

Example 24 with IdmFormProjectionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method setAddEavMetadata.

/**
 * Load extended attributes, if needed by projection.
 *
 * @param context
 * @param identity
 */
protected void setAddEavMetadata(FormableFilter context, IdmIdentityDto identity) {
    if (identity.getFormProjection() == null) {
        // load all form instances => ~ full form projection as default, when no projection is specified
        context.setAddEavMetadata(Boolean.TRUE);
        return;
    }
    // 
    IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(identity, IdmIdentity_.formProjection);
    String formDefinitions = formProjection.getFormDefinitions();
    if (StringUtils.isEmpty(formDefinitions)) {
        // form instances are not needed - not configured in this projection
        return;
    }
    // 
    try {
        List<FormDefinitionAttributes> attributes = mapper.readValue(formDefinitions, new TypeReference<List<FormDefinitionAttributes>>() {
        });
        if (!attributes.isEmpty()) {
            context.setFormDefinitionAttributes(attributes);
        } else {
            LOG.debug("Extended attribute values is not needed by form projection [{}], will not be loaded.");
        }
    } catch (IOException ex) {
        LOG.warn("Form projection [{}] is wrongly configured. Fix configured form definitions. " + "All eav attributes will be loaded as default.", formProjection.getCode(), ex);
        context.setAddEavMetadata(Boolean.TRUE);
    }
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)

Example 25 with IdmFormProjectionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto 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);
}
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)

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