Search in sources :

Example 91 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, String module, List<IdmFormAttributeDto> formAttributes, BasePermission... permission) {
    Assert.hasLength(type, "Form definition type is required.");
    // 
    // create definition
    IdmFormDefinitionDto formDefinition = new IdmFormDefinitionDto();
    formDefinition.setType(type);
    formDefinition.setCode(code);
    formDefinition.setModule(module);
    formDefinition = formDefinitionService.save(formDefinition, permission);
    UUID definitionId = formDefinition.getId();
    // and their attributes
    if (CollectionUtils.isNotEmpty(formAttributes)) {
        Short seq = 0;
        for (IdmFormAttributeDto formAttribute : formAttributes) {
            // default attribute order
            if (formAttribute.getSeq() == null) {
                formAttribute.setSeq(seq);
                seq++;
            }
            formAttribute.setFormDefinition(definitionId);
            formAttribute = formAttributeService.save(formAttribute, permission);
        }
    }
    // fill whole cache again (cache is evicted, after definition or attribute is saved)
    formDefinition = getCachedDefinitions(formDefinition.getType()).getById(definitionId);
    // 
    return formDefinition;
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 92 with IdmFormDefinitionDto

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

the class DefaultIdmFormDefinitionService method updateDefinition.

@Override
@Transactional
public IdmFormDefinitionDto updateDefinition(Class<? extends Identifiable> ownerType, String definitionCode, List<IdmFormAttributeDto> attributes) {
    Assert.notNull(ownerType, "Owner type is required.");
    // 
    IdmFormDefinitionDto definition = new IdmFormDefinitionDto();
    definition.setType(getOwnerType(ownerType));
    definition.setModule(EntityUtils.getModule(ownerType));
    definition.setCode(definitionCode);
    definition.setFormAttributes(attributes);
    // 
    return updateDefinition(definition);
}
Also used : IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with IdmFormDefinitionDto

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

the class DefaultIdmFormDefinitionService method updateDefinition.

@Override
@Transactional
public IdmFormDefinitionDto updateDefinition(String definitionType, String definitionCode, List<IdmFormAttributeDto> attributes) {
    Assert.notNull(definitionType, "Definition type is required.");
    // 
    IdmFormDefinitionDto definition = new IdmFormDefinitionDto();
    definition.setType(definitionType);
    definition.setCode(definitionCode);
    definition.setFormAttributes(attributes);
    // 
    return updateDefinition(definition);
}
Also used : IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 94 with IdmFormDefinitionDto

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

the class DefaultIdmFormDefinitionService method saveInternal.

/**
 * Fill default definition code and name, if no code / name is given.
 */
@Override
@Transactional
public IdmFormDefinitionDto saveInternal(IdmFormDefinitionDto dto) {
    if (StringUtils.isEmpty(dto.getCode())) {
        dto.setMain(true);
        dto.setCode(DEFAULT_DEFINITION_CODE);
    }
    if (StringUtils.isEmpty(dto.getName())) {
        dto.setName(dto.getCode());
    }
    if (dto.isMain()) {
        IdmFormDefinitionDto mainDefinition = findOneByMain(dto.getType());
        if (mainDefinition != null && !mainDefinition.getId().equals(dto.getId())) {
            mainDefinition.setMain(false);
            // 
            FormDefinitionEvent formDefinitionEvent = new FormDefinitionEvent(FormDefinitionEventType.UPDATE, mainDefinition);
            // We don't need validation - main definition is set in the same transaction bellow.
            formDefinitionEvent.getProperties().put(FormService.SKIP_EAV_VALIDATION, Boolean.TRUE);
            // 
            publish(formDefinitionEvent);
        }
    }
    // 
    return super.saveInternal(dto);
}
Also used : FormDefinitionEvent(eu.bcvsolutions.idm.core.eav.api.event.FormDefinitionEvent) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with IdmFormDefinitionDto

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

the class DefaultIdmFormDefinitionService method updateDefinition.

@Override
@Transactional
public IdmFormDefinitionDto updateDefinition(IdmFormDefinitionDto definition) {
    Assert.notNull(definition, "Form definition is required.");
    Assert.notNull(definition.getType(), "Form definition type is required.");
    Assert.notNull(definition.getCode(), "Form definition code is required.");
    // 
    IdmFormDefinitionDto formDefinition = findOneByTypeAndCode(definition.getType(), definition.getCode());
    if (formDefinition == null) {
        formDefinition = new IdmFormDefinitionDto();
        formDefinition.setType(definition.getType());
        formDefinition.setCode(definition.getCode());
        formDefinition.setName(definition.getName());
        formDefinition.setDescription(definition.getDescription());
        formDefinition.setModule(definition.getModule());
        // 
        formDefinition = save(formDefinition);
    } else if (!Objects.equals(formDefinition.getModule(), definition.getModule())) {
        formDefinition.setModule(definition.getModule());
        // 
        formDefinition = save(formDefinition);
    }
    // 
    List<IdmFormAttributeDto> attributes = definition.getFormAttributes();
    if (attributes == null || attributes.isEmpty()) {
        // change script has to be provided
        return formDefinition;
    }
    // upgrade definition
    boolean changed = false;
    Short seq = 0;
    for (IdmFormAttributeDto attribute : attributes) {
        // update seq - attributes can be simply given in different order
        if (attribute.getSeq() == null) {
            attribute.setSeq(seq);
        }
        IdmFormAttributeDto savedAttribute = formAttributeService.findAttribute(formDefinition.getType(), formDefinition.getCode(), attribute.getCode());
        if (savedAttribute == null) {
            savedAttribute = attribute;
            savedAttribute.setFormDefinition(formDefinition.getId());
            if (savedAttribute.getSeq() == null) {
                savedAttribute.setSeq(seq);
            }
            // 
            formAttributeService.save(savedAttribute);
            changed = true;
        } else {
            // throw exception, if incompatible change was found
            checkIncompatibleChanges(formDefinition, savedAttribute, attribute);
            // save compatible changes
            if (compareCompatibleChanges(savedAttribute, attribute) != 0) {
                // update attribute - compatible changes
                savedAttribute.setSeq(attribute.getSeq());
                savedAttribute.setName(attribute.getName());
                savedAttribute.setFaceType(attribute.getFaceType());
                savedAttribute.setReadonly(attribute.isReadonly());
                savedAttribute.setRequired(attribute.isRequired());
                savedAttribute.setDefaultValue(attribute.getDefaultValue());
                savedAttribute.setDescription(attribute.getDescription());
                savedAttribute.setMultiple(attribute.isMultiple());
                savedAttribute.setPlaceholder(attribute.getPlaceholder());
                savedAttribute.setUnmodifiable(attribute.isUnmodifiable());
                formAttributeService.save(savedAttribute);
                changed = true;
            }
        }
        seq++;
    }
    if (changed) {
        formDefinition = get(formDefinition.getId());
    }
    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)

Aggregations

IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)398 Test (org.junit.Test)230 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)224 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)190 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)165 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)123 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)119 List (java.util.List)109 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)108 UUID (java.util.UUID)102 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)98 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)83 Autowired (org.springframework.beans.factory.annotation.Autowired)83 ArrayList (java.util.ArrayList)82 Transactional (org.springframework.transaction.annotation.Transactional)80 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)77 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)71 Serializable (java.io.Serializable)68 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)65 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)61