use of org.guvnor.structure.server.config.ConfigType in project kie-wb-common by kiegroup.
the class MigrationConfigurationServiceImpl method getConfiguration.
@Override
public List<ConfigGroup> getConfiguration(ConfigType configType) {
if (ConfigType.SPACE.equals(configType)) {
configType = ConfigType.ORGANIZATIONAL_UNIT;
}
final ConfigType type = configType;
final List<ConfigGroup> configGroups = new ArrayList<>();
final DirectoryStream<Path> foundConfigs = ioService.newDirectoryStream(ioService.get(systemRepository.getUri()), entry -> {
if (!Files.isDirectory(entry) && !entry.getFileName().toString().startsWith(".") && entry.getFileName().toString().endsWith(type.getExt())) {
return true;
}
return false;
});
// Only load and cache if a file was found!
final Iterator<Path> it = foundConfigs.iterator();
if (it.hasNext()) {
while (it.hasNext()) {
final String content = ioService.readAllString(it.next());
final ConfigGroup configGroup = marshaller.unmarshall(content);
configGroups.add(configGroup);
}
configGroupsByTypeWithoutNamespace.put(type, configGroups);
}
return configGroups;
}
use of org.guvnor.structure.server.config.ConfigType in project kie-wb-common by kiegroup.
the class ConfigGroupsMigrationService method groupConfigGroupsByType.
private void groupConfigGroupsByType() {
final org.uberfire.java.nio.file.Path systemDir = ioService.get(systemRepository.getUri());
for (ConfigType oldType : ConfigType.values()) {
final String oldExt = oldType.getExt();
final DirectoryStream<org.uberfire.java.nio.file.Path> foundConfigs = getDirectoryStreamForFilesWithParticularExtension(systemDir, oldExt);
final ConfigType newType = getNewType(oldType);
final org.uberfire.java.nio.file.Path newTypeDir = systemDir.resolve(newType.getDir());
if (!ioService.exists(newTypeDir)) {
ioService.createDirectory(newTypeDir);
}
final Iterator<org.uberfire.java.nio.file.Path> it = foundConfigs.iterator();
while (it.hasNext()) {
final org.uberfire.java.nio.file.Path oldPath = it.next();
final String newExt = newType.getExt();
final String oldFileName = Paths.convert(oldPath).getFileName();
final String newFileName = FileNameUtil.removeExtension(oldFileName, oldExt.substring(1)) + newExt;
final org.uberfire.java.nio.file.Path newPath = newTypeDir.resolve(newFileName);
ioService.move(oldPath, newPath);
if (!newType.equals(oldType)) {
final String content = ioService.readAllString(newPath);
final ConfigGroup configGroup = marshaller.unmarshall(content);
configGroup.setType(newType);
ioService.write(newPath, marshaller.marshall(configGroup), new CommentedOption(getIdentityName(), "Updated configuration type."));
}
}
}
}
use of org.guvnor.structure.server.config.ConfigType in project kie-wb-common by kiegroup.
the class BaseAppSetupTest method setupUndefinedConfigurationGroupTest.
@Test
public void setupUndefinedConfigurationGroupTest() {
doReturn(new ArrayList<>()).when(configurationService).getConfiguration(eq(ConfigType.GLOBAL));
final ConfigType configType = ConfigType.GLOBAL;
final String configGroupName = BaseAppSetup.GLOBAL_SETTINGS;
final ConfigGroup configGroup = setupPredefinedGlobalConfiguration();
baseAppSetup.setupConfigurationGroup(configType, configGroupName, configGroup);
verify(configurationService).addConfiguration(any(ConfigGroup.class));
verify(configurationService, never()).updateConfiguration(any(ConfigGroup.class));
}
use of org.guvnor.structure.server.config.ConfigType in project kie-wb-common by kiegroup.
the class BaseAppSetupTest method setupDefinedConfigurationGroupTest.
@Test
public void setupDefinedConfigurationGroupTest() {
final ConfigType configType = ConfigType.GLOBAL;
final String configGroupName = BaseAppSetup.GLOBAL_SETTINGS;
// Existent configs to be checked
final ConfigGroup existentConfigGroup = setupPredefinedGlobalConfiguration();
List<ConfigGroup> definedConfigGroups = new ArrayList<>(1);
definedConfigGroups.add(existentConfigGroup);
doReturn(definedConfigGroups).when(configurationService).getConfiguration(eq(ConfigType.GLOBAL));
final ConfigItem<String> existentDroolsDefaultLanguageConfigItem = configItemsByName.get("drools.defaultlanguage");
final ConfigItem<String> existentSupportRuntimeDeployConfigItem = configItemsByName.get("support.runtime.deploy");
// To update
final ConfigItem<String> droolsDefaultLanguageConfigItem = new ConfigItem<>();
droolsDefaultLanguageConfigItem.setName("drools.defaultlanguage");
droolsDefaultLanguageConfigItem.setValue("en");
// To create
final ConfigItem<String> droolsDefaultCountryConfigItem = new ConfigItem<>();
droolsDefaultCountryConfigItem.setName("drools.defaultcountry");
droolsDefaultCountryConfigItem.setValue("US");
// To do nothing
final ConfigItem<String> supportRuntimeDeployConfigItem = new ConfigItem<>();
supportRuntimeDeployConfigItem.setName("support.runtime.deploy");
supportRuntimeDeployConfigItem.setValue("true");
baseAppSetup.setupConfigurationGroup(configType, configGroupName, null, droolsDefaultLanguageConfigItem, droolsDefaultCountryConfigItem, supportRuntimeDeployConfigItem);
verify(configurationService, never()).addConfiguration(any(ConfigGroup.class));
verify(configurationService, times(2)).updateConfiguration(existentConfigGroup);
verify(existentConfigGroup, never()).addConfigItem(droolsDefaultLanguageConfigItem);
// new config item
verify(existentConfigGroup).addConfigItem(droolsDefaultCountryConfigItem);
verify(existentConfigGroup, never()).addConfigItem(supportRuntimeDeployConfigItem);
// updated config item
verify(existentDroolsDefaultLanguageConfigItem).setValue(droolsDefaultLanguageConfigItem.getValue());
verify(existentSupportRuntimeDeployConfigItem, never()).setValue(anyString());
}
Aggregations