Search in sources :

Example 1 with ConfigType

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;
}
Also used : Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType)

Example 2 with ConfigType

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."));
            }
        }
    }
}
Also used : CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType)

Example 3 with ConfigType

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));
}
Also used : ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType) Test(org.junit.Test)

Example 4 with ConfigType

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());
}
Also used : ArrayList(java.util.ArrayList) ConfigItem(org.guvnor.structure.server.config.ConfigItem) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType) Test(org.junit.Test)

Aggregations

ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)4 ConfigType (org.guvnor.structure.server.config.ConfigType)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ConfigItem (org.guvnor.structure.server.config.ConfigItem)1 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)1 Path (org.uberfire.java.nio.file.Path)1