Search in sources :

Example 16 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method publish.

@Override
@Transactional
public EventContext<IdmIdentityProjectionDto> publish(EntityEvent<IdmIdentityProjectionDto> event, EntityEvent<?> parentEvent, BasePermission... permission) {
    Assert.notNull(event, "Event must be not null!");
    IdmIdentityProjectionDto dto = event.getContent();
    Assert.notNull(dto, "Content (dto) in event must be not null!");
    // check permissions - check access to filled form values
    event.setPermission(permission);
    // load previous projection
    IdmIdentityDto identity = dto.getIdentity();
    if (!identityService.isNew(identity)) {
        event.setOriginalSource(// UPDATE permission
        get(identity.getId(), PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.UPDATE));
    }
    // 
    return entityEventManager.process(event, parentEvent);
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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 18 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method saveIdentityRoles.

protected void saveIdentityRoles(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
    IdmIdentityContractDto contract = dto.getContract();
    IdmIdentityDto identity = dto.getIdentity();
    // 
    if (previousProjection == null) {
        List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(dto.getIdentityRoles().size());
        // 
        for (IdmIdentityRoleDto assignedRole : dto.getIdentityRoles()) {
            // create new identity role
            IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
            if (assignedRole.getIdentityContract() != null) {
                concept.setIdentityContract(assignedRole.getIdentityContract());
            } else if (contract != null) {
                concept.setIdentityContract(contract.getId());
            } else {
                throw new ForbiddenEntityException("contract", IdmBasePermission.READ);
            }
            concept.setRole(assignedRole.getRole());
            concept.setOperation(ConceptRoleRequestOperation.ADD);
            concept.setValidFrom(assignedRole.getValidFrom());
            concept.setValidTill(assignedRole.getValidTill());
            concept.setEavs(assignedRole.getEavs());
            // 
            concepts.add(concept);
        }
        if (!concepts.isEmpty()) {
            IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
            roleRequest.setState(RoleRequestState.CONCEPT);
            roleRequest.setExecuteImmediately(false);
            roleRequest.setApplicant(identity.getId());
            roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
            roleRequest = roleRequestService.save(roleRequest);
            // 
            for (IdmConceptRoleRequestDto concept : concepts) {
                concept.setRoleRequest(roleRequest.getId());
                // 
                conceptRoleRequestService.save(concept);
            }
            // 
            // start event with skip check authorities
            RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
            requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
            // frontend
            requestEvent.setPriority(event.getPriority());
            requestEvent.setParentId(event.getId());
            // prevent to start asynchronous event before previous update event is completed.
            requestEvent.setSuperOwnerId(identity.getId());
            // 
            roleRequestService.startRequestInternal(requestEvent);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

Example 19 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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)

Example 20 with IdmIdentityProjectionDto

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

IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)32 Transactional (org.springframework.transaction.annotation.Transactional)24 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)23 Test (org.junit.Test)23 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)22 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)22 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)21 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)18 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)15 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)8 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)7 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)7