Search in sources :

Example 6 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class XmEntitySpecService method extendDataForm.

@SneakyThrows
private void extendDataForm(TypeSpec type, TypeSpec parentType, String tenant) {
    XmEntityTenantConfig entityTenantConfig = this.tenantConfigService.getXmEntityTenantConfig(tenant);
    Boolean isInheritanceEnabled = entityTenantConfig.getEntitySpec().getEnableDataFromInheritance();
    if (isFeatureEnabled(isInheritanceEnabled, type.getDataFormInheritance()) && hasDataForm(type, parentType)) {
        ObjectMapper objectMapper = new ObjectMapper();
        var defaults = objectMapper.readValue(parentType.getDataForm(), Map.class);
        ObjectReader updater = objectMapper.readerForUpdating(defaults);
        Map<String, Object> merged = updater.readValue(type.getDataForm());
        String mergedJson = objectMapper.writeValueAsString(merged);
        type.setDataForm(mergedJson);
    } else {
        type.setDataForm(type.getDataForm() != null ? type.getDataForm() : parentType.getDataForm());
    }
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig) SneakyThrows(lombok.SneakyThrows)

Example 7 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class XmEntitySpecServiceUnitTest method setExtendsFormAndSpec.

private void setExtendsFormAndSpec(Boolean value) {
    XmEntityTenantConfig config = new XmEntityTenantConfig();
    config.getEntitySpec().setEnableDataFromInheritance(value);
    config.getEntitySpec().setEnableDataSpecInheritance(value);
    when(tenantConfig.getXmEntityTenantConfig("RESINTTEST")).thenReturn(config);
}
Also used : XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)

Aggregations

XmEntityTenantConfig (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SneakyThrows (lombok.SneakyThrows)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 Configuration (com.icthh.xm.commons.config.domain.Configuration)1 IgnoreLogginAspect (com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)1 XmEntityTenantConfigService (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService)1 DynamicPermissionCheckService (com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService)1 FunctionContextService (com.icthh.xm.ms.entity.service.FunctionContextService)1 FunctionExecutorService (com.icthh.xm.ms.entity.service.FunctionExecutorService)1 JsonValidationService (com.icthh.xm.ms.entity.service.JsonValidationService)1 XmEntityService (com.icthh.xm.ms.entity.service.XmEntityService)1 XmEntitySpecService (com.icthh.xm.ms.entity.service.XmEntitySpecService)1 HashMap (java.util.HashMap)1