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; } } }); }
public void exportAsSql() { List<AppPropertyEntity> exported = paramsTable.getSelected().stream() .filter(appPropertyEntity -> !appPropertyEntity.getCategory()) .collect(Collectors.toList()); if (!exported.isEmpty()) { openWindow("appPropertiesExport", OpenType.DIALOG, ParamsMap.of("exported", exported)); } }
private boolean nameEquals(String[] nameParts, AppPropertyEntity entity) { AppPropertyEntity e = entity; for (int i = nameParts.length - 1; i >= 0; i--) { String name = nameParts[i]; if (!e.getName().equals(name)) return false; if (i > 0) { e = e.getParent(); if (e == null) return false; } } return true; }
AppPropertyEntity entity = new AppPropertyEntity(); entity.setName(name); entity.setDefaultValue(getDefaultValue(method)); entity.setCurrentValue(getCurrentValue(method, entry.getValue())); entity.setOverridden(StringUtils.isNotEmpty(AppContext.getProperty(name))); entity.setSecret(method.getAnnotation(Secret.class) != null); if (!entity.getOverridden()) { assignLastUpdated(entity, dbContent);
@Override public void init(Map<String, Object> params) { cannotEditValueLabel.setVisible(item.getOverridden()); Datatype datatype = item.getEnumValues() != null ? datatypeRegistry.getNN(String.class) : datatypeRegistry.get(item.getDataTypeName()); if (item.getOverridden()) { TextField<String> textField = uiComponents.create(TextField.NAME); textField.setValue(item.getDisplayedCurrentValue()); textField.setEditable(false); return textField; if (item.getEnumValues() != null) { return createLookupField(Arrays.asList(item.getEnumValues().split(",")), item.getCurrentValue()); } else { if (datatype instanceof BooleanDatatype) { return createLookupField(Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString()), item.getCurrentValue()); } else { if (Boolean.TRUE.equals(item.getSecret())) { PasswordField passwordField = uiComponents.create(PasswordField.class); passwordField.setValue(item.getCurrentValue()); passwordField.addValueChangeListener(e -> { appPropertyDs.getItem().setCurrentValue(e.getValue()); }); return passwordField; } else { TextField<Object> textField = uiComponents.create(TextField.NAME); textField.setValue(item.getCurrentValue());
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++) { Optional<AppPropertyEntity> parentOpt = resultList.stream() .filter(e -> { return e.getCategory() && nameEquals(currParts, e); }) .findFirst(); parent = parentOpt.get(); } else { AppPropertyEntity categoryEntity = new AppPropertyEntity(); categoryEntity.setParent(parent); categoryEntity.setName(part); resultList.add(categoryEntity); parent = categoryEntity; entity.setParent(parent); entity.setCategory(false); resultList.add(entity);
if (returnType.isPrimitive()) { if (returnType == boolean.class) entity.setDataTypeName(datatypes.getIdByJavaClass(Boolean.class)); if (returnType == int.class) entity.setDataTypeName(datatypes.getIdByJavaClass(Integer.class)); if (returnType == long.class) entity.setDataTypeName(datatypes.getIdByJavaClass(Long.class)); if (returnType == double.class || returnType == float.class) entity.setDataTypeName(datatypes.getIdByJavaClass(Double.class)); } else if (returnType.isEnum()) { entity.setDataTypeName("enum"); EnumStore enumStoreAnn = method.getAnnotation(EnumStore.class); if (enumStoreAnn != null && enumStoreAnn.value() == EnumStoreMode.ID) { entity.setEnumValues(Arrays.stream(enumeration.getEnumConstants()) .map(ec -> String.valueOf(ec.getId())) .collect(Collectors.joining(","))); } else { entity.setEnumValues(Arrays.stream(returnType.getEnumConstants()) .map(Object::toString) .collect(Collectors.joining(","))); Datatype<?> datatype = datatypes.get(returnType); if (datatype != null) entity.setDataTypeName(datatypes.getId(datatype)); else entity.setDataTypeName(datatypes.getIdByJavaClass(String.class)); String dataTypeName = entity.getDataTypeName();
protected void assignLastUpdated(AppPropertyEntity entity, List<com.haulmont.cuba.core.entity.Config> dbContent) { dbContent.stream() .filter(config -> config.getName().equals(entity.getName())) .findFirst() .ifPresent(config -> { entity.setUpdateTs(config.getUpdateTs() != null ? config.getUpdateTs() : config.getCreateTs()); entity.setUpdatedBy(config.getUpdatedBy() != null ? config.getUpdatedBy() : config.getCreatedBy()); }); }
@Override public void init(Map<String, Object> params) { getDialogOptions().setHeight("400px"); StringBuilder sb = new StringBuilder(); for (AppPropertyEntity entity : exported) { sb.append("insert into SYS_CONFIG (ID, CREATE_TS, CREATED_BY, VERSION, NAME, VALUE_)\n"); sb.append("values ('").append(entity.getId()) .append("', current_timestamp, '") .append(uss.getUserSession().getUser().getLogin()) .append("', 0, '") .append(entity.getName()) .append("', '") .append(entity.getCurrentValue()).append("');\n\n"); } scriptArea.setValue(sb.toString()); } }
public void ok() { AppPropertyEntity appPropertyEntity = appPropertyDs.getItem(); // Save property through the client-side cache to ensure it is updated in the cache immediately Configuration configuration = AppBeans.get(Configuration.class); ConfigStorageService configStorageService = ((ConfigurationClientImpl) configuration).getConfigStorageService(); configStorageService.setDbProperty(appPropertyEntity.getName(), appPropertyEntity.getCurrentValue()); close(COMMIT_ACTION_ID); }
@Override public void init(Map<String, Object> params) { paramsDs.addItemChangeListener(e -> { boolean enabled = e.getItem() != null && !e.getItem().getCategory(); editValueAction.setEnabled(enabled); exportBtn.setEnabled(enabled); if (entity.getName().equals(lastSelected.getName())) { paramsTable.expand(entity.getId()); paramsTable.setSelected(entity);
@Override protected Collection<AppPropertyEntity> getEntities(Map<String, Object> params) { List<AppPropertyEntity> entities = loadAppPropertyEntities(); String name = (String) params.get("name"); if (StringUtils.isNotEmpty(name)) { entities = entities.stream() .filter(it -> it.getName().toLowerCase().contains(name.toLowerCase())) .collect(Collectors.toList()); } return createEntitiesTree(entities); }
private Component createLookupField(List<String> values, String currentValue) { LookupField<String> lookupField = uiComponents.create(LookupField.NAME); lookupField.setOptionsList(values); lookupField.setValue(currentValue); lookupField.addValueChangeListener(e -> { appPropertyDs.getItem().setCurrentValue(e.getValue()); }); return lookupField; }