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