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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations