Search in sources :

Example 6 with Codeable

use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.

the class DefaultRequestManager method initRequest.

/**
 * Init new request (without save)
 *
 * @param request
 * @param dto
 */
private <R extends Requestable> void initRequest(IdmRequestDto request, R dto) {
    request.setState(RequestState.CONCEPT);
    request.setOwnerId((UUID) dto.getId());
    request.setOwnerType(dto.getClass().getName());
    request.setExecuteImmediately(false);
    request.setRequestType(dto.getClass().getSimpleName());
    request.setResult(new OperationResultDto(OperationState.CREATED));
    if (dto instanceof Codeable && ((Codeable) dto).getCode() != null) {
        request.setName(((Codeable) dto).getCode());
    }
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto)

Example 7 with Codeable

use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.

the class AbstractProvisioningExecutor method accountManagement.

@Override
public boolean accountManagement(DTO dto) {
    SystemEntityType entityType = SystemEntityType.getByClass(dto.getClass());
    List<SysSystemMappingDto> systemMappings = findSystemMappingsForEntityType(dto, entityType);
    systemMappings.forEach(mapping -> {
        SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
        UUID systemId = schemaObjectClassDto.getSystem();
        UUID accountId = this.getAccountByEntity(dto.getId(), systemId);
        if (accountId != null) {
            // We already have account for this system -> next
            return;
        }
        SysSystemDto system = DtoUtils.getEmbedded(schemaObjectClassDto, SysSchemaObjectClass_.system);
        List<SysSystemAttributeMappingDto> mappedAttributes = attributeMappingService.findBySystemMapping(mapping);
        SysSystemAttributeMappingDto uidAttribute = attributeMappingService.getUidAttribute(mappedAttributes, system);
        String uid = attributeMappingService.generateUid(dto, uidAttribute);
        // Account management - can be the account created? - execute the script on the system mapping
        if (!this.canBeAccountCreated(uid, dto, mapping, system)) {
            String entityStr = dto.toString();
            if (dto instanceof Codeable) {
                entityStr = ((Codeable) dto).getCode();
            }
            LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", entityStr, entityType, system.getName()));
            return;
        }
        // Create AccAccount and relation between account and entity
        createEntityAccount(uid, dto.getId(), systemId);
    });
    return true;
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 8 with Codeable

use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.

the class AbstractReadWriteDtoControllerRestTest method testFindByCodeable.

/**
 * Test search by external identifier, if DTO implements {@link ExternalIdentifiable}
 *
 * @throws Exception
 */
@Test
public void testFindByCodeable() {
    if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
        LOG.warn("Controller [{}] doesn't support DataFilter. Find by codeable will not be tested.", getController().getClass());
        return;
    }
    // 
    DTO dto = prepareDto();
    if (!(dto instanceof Codeable)) {
        // ignore test
        return;
    }
    Codeable codeable = (Codeable) dto;
    if (StringUtils.isEmpty(codeable.getCode())) {
        throw new CoreException("Code has to be set by #prepareDto method, its required by default");
    }
    // 
    DTO createdDto = createDto(dto);
    // mock dto
    createDto(prepareDto());
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set(DataFilter.PARAMETER_CODEABLE_IDENTIFIER, codeable.getCode());
    // 
    List<DTO> results = find(parameters);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(createdDto.getId(), results.get(0).getId());
    // 
    if (supportsAutocomplete()) {
        results = autocomplete(parameters);
        // 
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(createdDto.getId(), results.get(0).getId());
    } else {
        LOG.info("Controller [{}] doesn't support autocomplete method. Method will not be tested.", getController().getClass());
    }
    // 
    Assert.assertEquals(1, count(parameters));
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) ExternalCodeable(eu.bcvsolutions.idm.core.api.domain.ExternalCodeable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 9 with Codeable

use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.

the class IdmAuditListener method changeRevisionDto.

private void changeRevisionDto(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAuditDto revisionEntity, RevisionType revisionType) {
    // List<String> changedColumns;
    // name of entity class - full name.
    revisionEntity.setType(entityName);
    // revision type - MOD, DEL, ADD
    revisionEntity.setModification(revisionType.name());
    // action executer identity
    AbstractAuthentication authentication = securityService.getAuthentication();
    IdmIdentityDto currentModifierIdentity = authentication == null ? null : authentication.getCurrentIdentity();
    IdmIdentityDto originalModifierIdentity = authentication == null ? null : authentication.getOriginalIdentity();
    // 
    revisionEntity.setModifier(securityService.getUsername());
    revisionEntity.setModifierId(currentModifierIdentity == null ? null : currentModifierIdentity.getId());
    // original action executer identity (before switch)
    revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
    revisionEntity.setOriginalModifierId(originalModifierIdentity == null ? null : originalModifierIdentity.getId());
    // entity id
    revisionEntity.setEntityId((UUID) entityId);
    // 
    // get entity in new transaction if revision type is delete
    AbstractEntity currentEntity = null;
    if (revisionType == RevisionType.DEL) {
        currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
    } else {
        currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
    }
    // 
    if (currentEntity instanceof AuditSearchable) {
        AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
        revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
        revisionEntity.setOwnerId(searchableEntity.getOwnerId());
        revisionEntity.setOwnerType(searchableEntity.getOwnerType());
        revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
        revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
        revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
    } else if (currentEntity instanceof Codeable) {
        revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
    }
    // transaction id
    revisionEntity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
Also used : AuditSearchable(eu.bcvsolutions.idm.core.api.domain.AuditSearchable) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 10 with Codeable

use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.

the class DefaultCommonFormServiceIntegrationTest method testCreateForm.

@Test
@Transactional
public void testCreateForm() {
    Codeable owner = helper.createIdentity();
    IdmFormAttributeDto attribute = createDefinition();
    IdmFormValueDto formValue = new IdmFormValueDto(attribute);
    formValue.setValue("testOne");
    IdmFormDto formOne = new IdmFormDto();
    formOne.setName("test");
    formOne.setFormDefinition(attribute.getFormDefinition());
    formOne.setValues(Lists.newArrayList(formValue));
    formOne.setOwnerCode(owner.getCode());
    // 
    commonFormService.saveForm(owner, formOne);
    formOne = commonFormService.getForms(owner).get(0);
    // 
    Assert.assertNotNull(formOne.getId());
    Assert.assertEquals(owner.getCode(), formOne.getOwnerCode());
    Assert.assertEquals(lookupService.lookupEntity(owner.getClass(), owner.getId()).getClass().getCanonicalName(), formOne.getOwnerType());
    Assert.assertEquals(owner.getId(), formOne.getOwnerId());
    Assert.assertEquals(formValue.getValue(), formOne.getValues().get(0).getValue());
    // 
    commonFormService.deleteForms(owner);
    Assert.assertTrue(commonFormService.getForms(owner).isEmpty());
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 UUID (java.util.UUID)4 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)3 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)2 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)2 AuditSearchable (eu.bcvsolutions.idm.core.api.domain.AuditSearchable)2 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)2 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)2 AbstractEntity (eu.bcvsolutions.idm.core.api.entity.AbstractEntity)2 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)2