Search in sources :

Example 1 with AppPropertyEntity

use of com.haulmont.cuba.core.config.AppPropertyEntity in project cuba by cuba-platform.

the class AppPropertiesDatasourceTest method testTree.

@Test
public void testTree() throws Exception {
    AppPropertiesDatasource datasource = new AppPropertiesDatasource();
    AppPropertyEntity e1 = new AppPropertyEntity();
    e1.setName("cuba.email.smtpHost");
    AppPropertyEntity e2 = new AppPropertyEntity();
    e2.setName("cuba.email.smtpPort");
    AppPropertyEntity e3 = new AppPropertyEntity();
    e3.setName("cuba.someProp");
    AppPropertyEntity e4 = new AppPropertyEntity();
    e4.setName("someOtherProp");
    List<AppPropertyEntity> list = datasource.createEntitiesTree(Arrays.asList(e1, e2, e3, e4));
    AppPropertyEntity cuba = list.stream().filter(e -> e.getName().equals("cuba")).findFirst().get();
    assertNull(cuba.getParent());
    AppPropertyEntity cubaEmail = list.stream().filter(e -> e.getName().equals("email")).findFirst().get();
    assertTrue(cubaEmail.getParent().equals(cuba));
    AppPropertyEntity cubaEmailSmtpHost = list.stream().filter(e -> e.getName().equals("cuba.email.smtpHost")).findFirst().get();
    assertTrue(cubaEmailSmtpHost.getParent() == cubaEmail);
    AppPropertyEntity cubaEmailSmtpPort = list.stream().filter(e -> e.getName().equals("cuba.email.smtpPort")).findFirst().get();
    assertTrue(cubaEmailSmtpPort.getParent() == cubaEmail);
    AppPropertyEntity cubaSomeProp = list.stream().filter(e -> e.getName().equals("cuba.someProp")).findFirst().get();
    assertTrue(cubaSomeProp.getParent() == cuba);
    AppPropertyEntity someOtherProp = list.stream().filter(e -> e.getName().equals("someOtherProp")).findFirst().get();
    assertNull(someOtherProp.getParent());
}
Also used : AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity) Test(org.junit.Test)

Example 2 with AppPropertyEntity

use of com.haulmont.cuba.core.config.AppPropertyEntity in project cuba by cuba-platform.

the class AppPropertiesDatasourceTest method test_pl_9104.

@Test
public void test_pl_9104() throws Exception {
    AppPropertiesDatasource datasource = new AppPropertiesDatasource();
    AppPropertyEntity e1 = new AppPropertyEntity();
    e1.setName("cuba.cat1.ui.prop1");
    AppPropertyEntity e2 = new AppPropertyEntity();
    e2.setName("cuba.cat2.ui.prop2");
    AppPropertyEntity e3 = new AppPropertyEntity();
    e3.setName("cuba.cat2.ui.prop3");
    List<AppPropertyEntity> list = datasource.createEntitiesTree(Arrays.asList(e1, e2, e3));
    /*
         cuba
           cat1
             ui
               prop1
           cat2
             ui
               prop2
               prop3
*/
    assertEquals(8, list.size());
    assertEquals(2, list.stream().filter(e -> e.getName().equals("ui")).count());
}
Also used : AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity) Test(org.junit.Test)

Example 3 with AppPropertyEntity

use of com.haulmont.cuba.core.config.AppPropertyEntity in project cuba by cuba-platform.

the class AppPropertiesBrowse method editValue.

public void editValue() {
    AppPropertiesEdit editor = (AppPropertiesEdit) openWindow("appPropertyEditor", OpenType.DIALOG, ParamsMap.of("item", paramsDs.getItem()));
    editor.addCloseWithCommitListener(() -> {
        List<AppPropertyEntity> entities = paramsDs.loadAppPropertyEntities();
        for (AppPropertyEntity entity : entities) {
            if (entity.getName().equals(paramsDs.getItem().getName())) {
                paramsDs.getItem().setCurrentValue(entity.getCurrentValue());
                paramsDs.getItem().setUpdateTs(entity.getUpdateTs());
                paramsDs.getItem().setUpdatedBy(entity.getUpdatedBy());
                break;
            }
        }
    });
}
Also used : AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity)

Example 4 with AppPropertyEntity

use of com.haulmont.cuba.core.config.AppPropertyEntity in project cuba by cuba-platform.

the class AppPropertiesDatasource method nameParts.

private List<String> nameParts(AppPropertyEntity entity) {
    List<String> list = new ArrayList<>();
    AppPropertyEntity e = entity;
    while (e != null) {
        list.add(e.getName());
        e = e.getParent();
    }
    Collections.reverse(list);
    return list;
}
Also used : AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity)

Example 5 with AppPropertyEntity

use of com.haulmont.cuba.core.config.AppPropertyEntity in project cuba by cuba-platform.

the class AppPropertiesDatasource method createEntitiesTree.

List<AppPropertyEntity> createEntitiesTree(List<AppPropertyEntity> entities) {
    List<AppPropertyEntity> resultList = new ArrayList<>();
    for (AppPropertyEntity entity : entities) {
        String[] parts = entity.getName().split("\\.");
        AppPropertyEntity parent = null;
        for (int i = 0; i < parts.length; i++) {
            String[] currParts = Arrays.copyOfRange(parts, 0, i + 1);
            String part = parts[i];
            if (i < parts.length - 1) {
                Optional<AppPropertyEntity> parentOpt = resultList.stream().filter(e -> {
                    return e.getCategory() && nameEquals(currParts, e);
                }).findFirst();
                if (parentOpt.isPresent()) {
                    parent = parentOpt.get();
                } else {
                    AppPropertyEntity categoryEntity = new AppPropertyEntity();
                    categoryEntity.setParent(parent);
                    categoryEntity.setName(part);
                    resultList.add(categoryEntity);
                    parent = categoryEntity;
                }
            } else {
                entity.setParent(parent);
                entity.setCategory(false);
                resultList.add(entity);
            }
        }
    }
    // remove duplicates from global configs
    for (Iterator<AppPropertyEntity> iter = resultList.iterator(); iter.hasNext(); ) {
        AppPropertyEntity entity = iter.next();
        resultList.stream().filter(e -> e != entity && nameParts(e).equals(nameParts(entity))).findFirst().ifPresent(e -> iter.remove());
    }
    return resultList;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) AppBeans(com.haulmont.cuba.core.global.AppBeans) Collectors(java.util.stream.Collectors) AppPropertiesLocator(com.haulmont.cuba.core.config.AppPropertiesLocator) CustomHierarchicalDatasource(com.haulmont.cuba.gui.data.impl.CustomHierarchicalDatasource) AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity)

Aggregations

AppPropertyEntity (com.haulmont.cuba.core.config.AppPropertyEntity)9 ConfigStorageService (com.haulmont.cuba.core.app.ConfigStorageService)3 AppPropertiesLocator (com.haulmont.cuba.core.config.AppPropertiesLocator)2 Test (org.junit.Test)2 ConfigurationClientImpl (com.haulmont.cuba.client.sys.ConfigurationClientImpl)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 CustomHierarchicalDatasource (com.haulmont.cuba.gui.data.impl.CustomHierarchicalDatasource)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1