| | |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.EnumSet; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The plugin types {@code check-references} needs: the references are checked in these hooks. */ |
| | | private static final Set<PluginCfgDefn.PluginType> CHECK_REFERENCES_PLUGIN_TYPES = Collections.unmodifiableSet( |
| | | EnumSet.of(PluginCfgDefn.PluginType.PREOPERATIONADD, PluginCfgDefn.PluginType.PREOPERATIONMODIFY)); |
| | | |
| | | |
| | | /** Current plugin configuration. */ |
| | |
| | | pluginCfg.addReferentialIntegrityChangeListener(this); |
| | | LinkedList<LocalizableMessage> unacceptableReasons = new LinkedList<>(); |
| | | |
| | | if (!isConfigurationAcceptable(pluginCfg, unacceptableReasons)) |
| | | if (!isConfigurationAcceptableIgnoringCheckReferencesPluginTypes(pluginCfg, unacceptableReasons)) |
| | | { |
| | | throw new ConfigException(unacceptableReasons.getFirst()); |
| | | } |
| | | |
| | | // Enabling the plugin or changing its configuration is refused without these types, but a configuration |
| | | // already stored without them (the entry shipped before issue #1118) is loaded with a warning: refusing |
| | | // it would also stop the delete and modify DN clean-up, which does not need them. |
| | | for (PluginCfgDefn.PluginType t : getMissingCheckReferencesPluginTypes(pluginCfg)) |
| | | { |
| | | logger.warn(WARN_PLUGIN_REFERENT_CHECK_REFERENCES_WITHOUT_PLUGIN_TYPE.get(pluginCfg.dn(), t, t)); |
| | | } |
| | | |
| | | applyConfigurationChange(pluginCfg); |
| | | |
| | | // Set up log file. Note: it is not allowed to change once the plugin is active. |
| | |
| | | public boolean isConfigurationAcceptable(PluginCfg configuration, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | | { |
| | | boolean isAcceptable = true; |
| | | ReferentialIntegrityPluginCfg pluginCfg = |
| | | (ReferentialIntegrityPluginCfg) configuration; |
| | | boolean isAcceptable = isConfigurationAcceptableIgnoringCheckReferencesPluginTypes(pluginCfg, unacceptableReasons); |
| | | |
| | | for (PluginCfgDefn.PluginType t : getMissingCheckReferencesPluginTypes(pluginCfg)) |
| | | { |
| | | isAcceptable = false; |
| | | unacceptableReasons.add(ERR_PLUGIN_REFERENT_CHECK_REFERENCES_WITHOUT_PLUGIN_TYPE.get(t, t)); |
| | | } |
| | | return isAcceptable; |
| | | } |
| | | |
| | | /** |
| | | * Returns the plugin types {@code check-references} needs that the configuration does not list. The references |
| | | * are checked in the pre-operation add and modify hooks, which the plugin manager only calls for the plugin types |
| | | * listed in the configuration. |
| | | */ |
| | | private static Set<PluginCfgDefn.PluginType> getMissingCheckReferencesPluginTypes( |
| | | ReferentialIntegrityPluginCfg pluginCfg) |
| | | { |
| | | if (!pluginCfg.isCheckReferences()) |
| | | { |
| | | return Collections.emptySet(); |
| | | } |
| | | Set<PluginCfgDefn.PluginType> missing = EnumSet.copyOf(CHECK_REFERENCES_PLUGIN_TYPES); |
| | | missing.removeAll(pluginCfg.getPluginType()); |
| | | return missing; |
| | | } |
| | | |
| | | private boolean isConfigurationAcceptableIgnoringCheckReferencesPluginTypes( |
| | | ReferentialIntegrityPluginCfg pluginCfg, List<LocalizableMessage> unacceptableReasons) |
| | | { |
| | | boolean isAcceptable = true; |
| | | |
| | | for (PluginCfgDefn.PluginType t : pluginCfg.getPluginType()) |
| | | { |