Search in sources :

Example 46 with IdmFormDefinitionDto

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

the class DefaultFormService method createDefinition.

@Override
@Transactional
public IdmFormDefinitionDto createDefinition(String type, String code, List<IdmFormAttributeDto> formAttributes) {
    Assert.hasLength(type);
    // 
    // create definition
    IdmFormDefinitionDto formDefinition = new IdmFormDefinitionDto();
    formDefinition.setType(type);
    formDefinition.setCode(code);
    formDefinition = formDefinitionService.save(formDefinition);
    // and their attributes
    if (formAttributes != null) {
        Short seq = 0;
        for (IdmFormAttributeDto formAttribute : formAttributes) {
            // default attribute order
            if (formAttribute.getSeq() == null) {
                formAttribute.setSeq(seq);
                seq++;
            }
            formAttribute.setFormDefinition(formDefinition.getId());
            formAttribute = formAttributeService.save(formAttribute);
            formDefinition.addFormAttribute(formAttribute);
        }
    }
    return formDefinition;
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with IdmFormDefinitionDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto 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.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 (IntrospectionException | InstantiationException | IllegalAccessException e) {
        throw new CoreException("Cannot read configuration property!", e);
    }
}
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 IdmFormDefinitionDto

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

the class DefaultFormDefinitionIntegrationTest method testUpdateDefinitionConfidential.

@Test(expected = ResultCodeException.class)
@Transactional
public void testUpdateDefinitionConfidential() {
    IdmFormAttributeDto attribute = new IdmFormAttributeDto("code", "Code", PersistentType.TEXT);
    IdmFormDefinitionDto formDefinition = formDefinitionService.updateDefinition(IdmIdentityDto.class, helper.createName(), Lists.newArrayList(attribute));
    Assert.assertEquals(1, formDefinition.getFormAttributes().size());
    // 
    // update
    attribute.setConfidential(true);
    formDefinitionService.updateDefinition(IdmIdentityDto.class, formDefinition.getCode(), Lists.newArrayList(attribute));
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with IdmFormDefinitionDto

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

the class DefaultFormDefinitionIntegrationTest method createDefinition.

/**
 * Creates definition
 *
 * @param name
 * @param randomAttributes with random count of attributes
 */
private ResultHolder createDefinition(String code, boolean randomAttributes, boolean log) {
    ResultHolder result = new ResultHolder();
    IdmFormDefinitionDto formDefinition = new IdmFormDefinitionDto();
    formDefinition.setType("test_type");
    formDefinition.setCode(code);
    if (log) {
        LOG.info("Before definition save [{}]", code);
    }
    long startTime = System.currentTimeMillis();
    formDefinition = formDefinitionService.save(formDefinition);
    if (log) {
        result.createTime = System.currentTimeMillis() - startTime;
        LOG.info("--- {}ms:  After definition save [{}]", result.createTime, code);
    }
    int attributeCount = r.nextInt(40);
    if (log) {
        LOG.info("Before definition [{}] attributes save, attributes count [{}]", code, attributeCount);
    }
    startTime = System.currentTimeMillis();
    for (int i = 0; i < attributeCount; i++) {
        IdmFormAttributeDto attributeDefinition = new IdmFormAttributeDto();
        attributeDefinition.setFormDefinition(formDefinition.getId());
        attributeDefinition.setCode("name_" + i);
        attributeDefinition.setName(attributeDefinition.getCode());
        attributeDefinition.setPersistentType(PersistentType.TEXT);
        attributeDefinition = formAttributeService.save(attributeDefinition);
    }
    if (log) {
        result.childrenCreateTime = (double) System.currentTimeMillis() - startTime;
        LOG.info("--- {}ms:  After definition [{}] attributes save, attributes count [{}]", result.childrenCreateTime, code, attributeCount);
        if (attributeCount > 0) {
            result.childrenCreateTime = result.childrenCreateTime / attributeCount;
        }
        startTime = System.currentTimeMillis();
        int realAttributeCount = formAttributeRepository.findByFormDefinition_IdOrderBySeq(formDefinition.getId()).size();
        assertEquals(attributeCount, realAttributeCount);
        result.childrenLoadTime = System.currentTimeMillis() - startTime;
        LOG.info("--- {}ms:  After definition [{}] attributes load, attributes count [{}]", result.childrenLoadTime, code, realAttributeCount);
    }
    result.formDefinition = formDefinition;
    return result;
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 50 with IdmFormDefinitionDto

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

the class DefaultFormDefinitionIntegrationTest method testDeleteDefinitionWithAttributes.

@Test
@Transactional
public void testDeleteDefinitionWithAttributes() {
    IdmFormDefinitionDto formDefinition = createDefinition("one", true, true).formDefinition;
    formDefinitionService.delete(formDefinition);
    assertEquals(0, formAttributeRepository.findByFormDefinition_IdOrderBySeq(formDefinition.getId()).size());
}
Also used : IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)71 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)35 Test (org.junit.Test)35 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)33 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)23 Transactional (org.springframework.transaction.annotation.Transactional)18 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)16 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)13 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 ArrayList (java.util.ArrayList)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 List (java.util.List)7 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 Serializable (java.io.Serializable)6