Search in sources :

Example 46 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class ExceptionUtilsUnitTest method testLogModelLevelDebug.

@Test
public void testLogModelLevelDebug() {
    ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.ACCEPTED), new CoreException("mock"));
    // error is logged without model is specified
    verify(LOG).debug(any(String.class), any(Exception.class));
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 47 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultFormService method convertConfigurationToFormDefinition.

/**
 * Create instance form definition from the given configuration class
 *
 * @param configurationClass
 * @return
 */
@Override
public IdmFormDefinitionDto convertConfigurationToFormDefinition(Class<? extends ConfigurationClass> configurationClass) {
    Assert.notNull(configurationClass, "Class with the configuration is required.");
    try {
        ConfigurationClass configurationClassInstance = configurationClass.getDeclaredConstructor().newInstance();
        List<IdmFormAttributeDto> properties = new ArrayList<>();
        PropertyDescriptor[] descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
        Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
            Method readMethod = descriptor.getReadMethod();
            String propertyName = descriptor.getName();
            ConfigurationClassProperty property = readMethod.getAnnotation(ConfigurationClassProperty.class);
            if (property != null) {
                IdmFormAttributeDto formAttribute = this.convertConfigurationProperty(property);
                formAttribute.setCode(propertyName);
                // TODO: Better convertors  (move from IC and ACC module to the Core)!
                initPersistentType(readMethod, formAttribute);
                try {
                    formAttribute.setDefaultValue(this.convertDefaultValue(readMethod.invoke(configurationClassInstance), formAttribute.isMultiple()));
                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    throw new CoreException("Cannot read value of connector configuration property!", e);
                }
                properties.add(formAttribute);
            }
        });
        IdmFormDefinitionDto definition = new IdmFormDefinitionDto();
        definition.setFormAttributes(properties);
        return definition;
    } catch (ReflectiveOperationException | IntrospectionException ex) {
        throw new CoreException("Cannot read configuration property!", ex);
    }
}
Also used : ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationClassProperty(eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)

Example 48 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class ApproveRoleByManagerDelegationType method findDelegation.

@Override
public List<IdmDelegationDefinitionDto> findDelegation(UUID delegatorId, UUID contractId, BaseDto owner) {
    Assert.isTrue(owner instanceof WorkflowTaskInstanceDto, "Owner must be workflow task for this delegation type!");
    WorkflowTaskInstanceDto task = (WorkflowTaskInstanceDto) owner;
    Object conceptRoleObj = taskInstanceService.getProcessVariable(task.getId(), ROLE_CONCEPT_PROPERTY);
    if (conceptRoleObj instanceof VariableInstance) {
        VariableInstance variableInstance = (VariableInstance) conceptRoleObj;
        conceptRoleObj = variableInstance.getValue();
    }
    if (!(conceptRoleObj instanceof IdmConceptRoleRequestDto)) {
        throw new CoreException(MessageFormat.format("For this delegation type [{0}], must workflow task contains '{1}' [WorkflowTaskInstanceDto] variable", NAME, ROLE_CONCEPT_PROPERTY));
    }
    IdmConceptRoleRequestDto conceptRole = (IdmConceptRoleRequestDto) conceptRoleObj;
    UUID contractFromRequest = conceptRole.getIdentityContract();
    Assert.notNull(contractFromRequest, "Contract ID from the concept of the request cannot be null!");
    // Filtering managers contracts by subordinates contract.
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(delegatorId);
    contractFilter.setManagersByContract(contractFromRequest);
    List<IdmIdentityContractDto> managersContracts = identityContractService.find(contractFilter, null).getContent();
    if (managersContracts.isEmpty()) {
        return null;
    }
    Set<IdmDelegationDefinitionDto> resultDelegations = Sets.newHashSet();
    // Find all valid delegation definitions for manager's contract.
    managersContracts.stream().map((managersContract) -> super.findDelegation(delegatorId, managersContract.getId(), owner)).filter((delegations) -> (!CollectionUtils.isEmpty(delegations))).forEachOrdered((delegations) -> {
        resultDelegations.addAll(delegations);
    });
    return Lists.newArrayList(resultDelegations);
}
Also used : IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) UUID(java.util.UUID) Assert(org.modelmapper.internal.util.Assert) Sets(com.google.common.collect.Sets) MessageFormat(java.text.MessageFormat) List(java.util.List) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) AbstractDelegationType(eu.bcvsolutions.idm.core.eav.api.service.AbstractDelegationType) CollectionUtils(org.apache.commons.collections.CollectionUtils) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 49 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleRequestService method startRequest.

@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
    IdmAutomaticRoleRequestDto request = get(requestId);
    Assert.notNull(request, "Request is required!");
    // Validation on exist some rule
    if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
        IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
        ruleFilter.setRoleRequestId(requestId);
        List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
        if (ruleConcepts.isEmpty()) {
            throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
        }
    }
    try {
        IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
        if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
            throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
        }
        return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
    } catch (Exception ex) {
        LOG.error(ex.getLocalizedMessage(), ex);
        request = get(requestId);
        Throwable exceptionToLog = ExceptionUtils.resolveException(ex);
        // TODO: I set only cause of exception, not code and properties. If are
        // properties set, then request cannot be save!
        request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
        request.setState(RequestState.EXCEPTION);
        return save(request);
    }
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class IdentityProvisioningTest method testAttachment.

@Test
public void testAttachment() {
    SysSystemDto systemDto = helper.createTestResourceSystem(true);
    SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(systemDto.getId());
    List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
    SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
    SysSystemAttributeMappingDto attributeByte = new SysSystemAttributeMappingDto();
    attributeByte.setUid(false);
    attributeByte.setEntityAttribute(false);
    attributeByte.setExtendedAttribute(true);
    attributeByte.setIdmPropertyName(getHelper().createName());
    attributeByte.setName(descriptionSchemaAttribute.getName());
    attributeByte.setSchemaAttribute(descriptionSchemaAttribute.getId());
    attributeByte.setSystemMapping(defaultMapping.getId());
    // Transformation data to string
    attributeByte.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " return new String(attributeValue.getData());");
    schemaAttributeMappingService.save(attributeByte);
    IdmRoleDto roleWithSystem = helper.createRole();
    helper.createRoleSystem(roleWithSystem, systemDto);
    // Set type of attribute to attachment
    IdmFormAttributeDto eavAttributeByte = formService.getAttribute(IdmIdentityDto.class, attributeByte.getIdmPropertyName());
    eavAttributeByte.setPersistentType(PersistentType.ATTACHMENT);
    eavAttributeByte = formService.saveAttribute(eavAttributeByte);
    // Create attachment with content
    String originalContent = getHelper().createName();
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setName("test.txt");
    attachment.setMimetype("text/plain");
    attachment.setInputData(IOUtils.toInputStream(originalContent));
    attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachment = attachmentManager.saveAttachment(null, attachment);
    InputStream inputStream = attachmentManager.getAttachmentData(attachment.getId());
    try {
        String content = IOUtils.toString(inputStream);
        assertEquals(originalContent, content);
        // Create form value with attachment
        IdmIdentityDto identity = helper.createIdentity();
        formService.saveValues(identity, eavAttributeByte, Lists.newArrayList(attachment.getId()));
        // Assign the system
        helper.createIdentityRole(identity, roleWithSystem, null, null);
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setIdentityId(identity.getId());
        TestResource resource = helper.findResource(identity.getUsername());
        assertNotNull(resource);
        String valueOnResource = resource.getDescrip();
        InputStream is = attachmentManager.getAttachmentData(attachment.getId());
        try {
            String data = new String(IOUtils.toByteArray(is));
            assertEquals(data, valueOnResource);
        } finally {
            IOUtils.closeQuietly(is);
        }
    } catch (IOException e) {
        throw new CoreException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) InputStream(java.io.InputStream) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IOException(java.io.IOException) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6