@Test public void variableReplacementShouldSuccess() throws ScriptException { prepareDatabase(); String newString = systemVariableService.variableReplacement("service-mgmt", "{{ALLOCATE_PORT}}:21000,{{BASE_MOUNT_PATH}}/service-mgmt/log:/log"); assertThat(newString).isEqualTo( "20000:21000,/data/service-mgmt/log:/log"); }
public String variableReplacement(String packageName, String originalString) { List<String> varList = StringUtilsEx.findSystemVariableString(originalString); for (int i = 0; i < varList.size(); i++) { String varValue = ""; String varString = varList.get(i); String varName = varString.substring(2, varString.length() - 2); List<SystemVariable> varObjects = getPluginSystemVariableByPackageNameAndName(packageName, varName); if (varObjects.size() == 0) { varObjects = getGlobalSystemVariableByName(varName); } if (varObjects.size() != 0) { SystemVariable varObject = varObjects.get(0); varValue = varObject.getValue() == null || varObject.getValue().isEmpty() ? (varObject.getDefaultValue() == null ? "" : varObject.getDefaultValue()) : varObject.getValue(); } originalString = originalString.replace(varString, varValue); } return originalString; }
SystemVariableService { public String variableReplacement(String packageName, String originalString) { List<String> varList = StringUtilsEx.findSystemVariableString(originalString); for (int i = 0; i < varList.size(); i++) { String varValue = ""; String varString = varList.get(i); String varName = varString.substring(2, varString.length() - 2); List<SystemVariable> varObjects = getPluginSystemVariableByPackageNameAndName(packageName, varName); if (varObjects.size() == 0) { varObjects = getGlobalSystemVariableByName(varName); } if (varObjects.size() != 0) { SystemVariable varObject = varObjects.get(0); varValue = varObject.getValue() == null || varObject.getValue().isEmpty() ? (varObject.getDefaultValue() == null ? "" : varObject.getDefaultValue()) : varObject.getValue(); } originalString = originalString.replace(varString, varValue); } return originalString; } }
SystemVariableService { public String variableReplacement(String packageName, String originalString) { List<String> varList = StringUtilsEx.findSystemVariableString(originalString); for (int i = 0; i < varList.size(); i++) { String varValue = ""; String varString = varList.get(i); String varName = varString.substring(2, varString.length() - 2); List<SystemVariable> varObjects = getPluginSystemVariableByPackageNameAndName(packageName, varName); if (varObjects.size() == 0) { varObjects = getGlobalSystemVariableByName(varName); } if (varObjects.size() != 0) { SystemVariable varObject = varObjects.get(0); varValue = varObject.getValue() == null || varObject.getValue().isEmpty() ? (varObject.getDefaultValue() == null ? "" : varObject.getDefaultValue()) : varObject.getValue(); } originalString = originalString.replace(varString, varValue); } return originalString; }  }
SystemVariableService { public String variableReplacement(String packageName, String originalString) { List<String> varList = StringUtilsEx.findSystemVariableString(originalString); for (int i = 0; i < varList.size(); i++) { String varValue = ""; String varString = varList.get(i); String varName = varString.substring(2, varString.length() - 2); List<SystemVariable> varObjects = getPluginSystemVariableByPackageNameAndName(packageName, varName); if (varObjects.size() == 0) { varObjects = getGlobalSystemVariableByName(varName); } if (varObjects.size() != 0) { SystemVariable varObject = varObjects.get(0); varValue = varObject.getValue() == null || varObject.getValue().isEmpty() ? (varObject.getDefaultValue() == null ? "" : varObject.getDefaultValue()) : varObject.getValue(); } originalString = originalString.replace(varString, varValue); } return originalString; }  QueryResponse<SystemVariableDto> retrieveSystemVariables(QueryRequest queryRequest); @Transactional List<SystemVariableDto> createSystemVariables(List<SystemVariableDto> resourceSystemVariables); @Transactional List<SystemVariableDto> updateSystemVariables(List<SystemVariableDto> resourceSystemVariables); @Transactional void deleteSystemVariables(List<SystemVariableDto> systemVariableDtos); SystemVariable toDomain(SystemVariableDto dto, SystemVariable existedSystemVariable); SystemVariable getSystemVariableById(String varId); SystemVariable getSystemVariableByPackageNameAndName(String packageName, String varName); List<SystemVariable> getPluginSystemVariableByPackageNameAndName(String packageName, String varName); List<SystemVariable> getGlobalSystemVariableByName(String varName); String variableReplacement(String packageName, String originalString); Iterable<SystemVariable> getAllSystemVariable(); List<SystemVariable> getPluginSystemVariableByPackageId(String packageId); List<String> retrieveSystemVariableScope(); void validatePermission(); }
SystemVariableService { public String variableReplacement(String packageName, String originalString) { List<String> varList = StringUtilsEx.findSystemVariableString(originalString); for (int i = 0; i < varList.size(); i++) { String varValue = ""; String varString = varList.get(i); String varName = varString.substring(2, varString.length() - 2); List<SystemVariable> varObjects = getPluginSystemVariableByPackageNameAndName(packageName, varName); if (varObjects.size() == 0) { varObjects = getGlobalSystemVariableByName(varName); } if (varObjects.size() != 0) { SystemVariable varObject = varObjects.get(0); varValue = varObject.getValue() == null || varObject.getValue().isEmpty() ? (varObject.getDefaultValue() == null ? "" : varObject.getDefaultValue()) : varObject.getValue(); } originalString = originalString.replace(varString, varValue); } return originalString; }  QueryResponse<SystemVariableDto> retrieveSystemVariables(QueryRequest queryRequest); @Transactional List<SystemVariableDto> createSystemVariables(List<SystemVariableDto> resourceSystemVariables); @Transactional List<SystemVariableDto> updateSystemVariables(List<SystemVariableDto> resourceSystemVariables); @Transactional void deleteSystemVariables(List<SystemVariableDto> systemVariableDtos); SystemVariable toDomain(SystemVariableDto dto, SystemVariable existedSystemVariable); SystemVariable getSystemVariableById(String varId); SystemVariable getSystemVariableByPackageNameAndName(String packageName, String varName); List<SystemVariable> getPluginSystemVariableByPackageNameAndName(String packageName, String varName); List<SystemVariable> getGlobalSystemVariableByName(String varName); String variableReplacement(String packageName, String originalString); Iterable<SystemVariable> getAllSystemVariable(); List<SystemVariable> getPluginSystemVariableByPackageId(String packageId); List<String> retrieveSystemVariableScope(); void validatePermission(); static final String MENU_CODE_ADMIN_SYSTEM_PARAMS; }