Search in sources :

Example 1 with FileProperty

use of com.liferay.imex.core.api.configuration.model.FileProperty in project liferay-imex by jpdacunha.

the class ImexCoreServiceImpl method mergeConfiguration.

private void mergeConfiguration(Map<String, Properties> props, String entryKey, Bundle bundle) {
    // Loading relevant configuration to apply (this configuration contain all properties to apply)
    String bundleSymbolicName = bundle.getSymbolicName();
    try {
        // Configuration file does not exists
        File overridedPropsFile = configurationService.getConfigurationOverrideFileName(bundle);
        if (overridedPropsFile == null || (overridedPropsFile != null && !overridedPropsFile.exists())) {
            // Writing file with default datas
            configurationService.loadDefaultConfigurationInFile(bundle, overridedPropsFile);
            reportService.getOK(_log, entryKey, overridedPropsFile.getName(), overridedPropsFile, ImexOperationEnum.CREATE);
        } else {
            // Configuration file exists executing merge
            String tempFilesPrefix = ImExCorePropsKeys.IMEX_PREFIX + StringPool.MINUS + bundleSymbolicName + StringPool.MINUS;
            // Loading default configuration and saving it in temp file
            String defaultPropsFileName = tempFilesPrefix + "default" + StringPool.MINUS;
            File defaultTempPropsFile = File.createTempFile(defaultPropsFileName, FileUtil.PROPERTIES_EXTENSION, getImexTempDir());
            configurationService.loadDefaultConfigurationInFile(bundle, defaultTempPropsFile);
            if (defaultTempPropsFile != null && defaultTempPropsFile.exists()) {
                // To file Property convertion
                OrderedProperties defaultOrderedProperty = new OrderedProperties();
                defaultOrderedProperty.load(defaultTempPropsFile);
                FileProperty defaultFileProperties = new FileProperty(defaultTempPropsFile, defaultOrderedProperty);
                // Loading relevant properties merged (embbeded in jar + default)
                Properties toApplyProperties = props.get(bundleSymbolicName);
                // Creating temp File with content to merge
                String tempFileName = tempFilesPrefix + "overrided" + StringPool.MINUS;
                File toApplyPropertiesTempFile = File.createTempFile(tempFileName, FileUtil.PROPERTIES_EXTENSION, getImexTempDir());
                FileUtil.loadPropertiesInFile(toApplyPropertiesTempFile, toApplyProperties);
                OrderedProperties toApplyOrderedProperty = new OrderedProperties();
                toApplyOrderedProperty.load(toApplyPropertiesTempFile);
                FileProperty toApplyFileProperties = new FileProperty(toApplyPropertiesTempFile, toApplyOrderedProperty);
                // Call merge method Property merger
                propertyMergerService.merge(defaultFileProperties, toApplyFileProperties, overridedPropsFile);
                // Cleaning
                if (toApplyPropertiesTempFile.exists()) {
                    toApplyPropertiesTempFile.delete();
                }
                if (defaultTempPropsFile.exists()) {
                    defaultTempPropsFile.delete();
                }
            } else {
                reportService.getDNE(_log, defaultTempPropsFile);
            }
            reportService.getOK(_log, entryKey, overridedPropsFile.getName(), overridedPropsFile, ImexOperationEnum.UPDATE);
        }
    } catch (IOException e) {
        _log.error(e, e);
    }
}
Also used : FileProperty(com.liferay.imex.core.api.configuration.model.FileProperty) OrderedProperties(com.liferay.imex.core.api.configuration.model.OrderedProperties) IOException(java.io.IOException) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) OrderedProperties(com.liferay.imex.core.api.configuration.model.OrderedProperties) File(java.io.File)

Aggregations

FileProperty (com.liferay.imex.core.api.configuration.model.FileProperty)1 ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)1 OrderedProperties (com.liferay.imex.core.api.configuration.model.OrderedProperties)1 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1