@Override public List<ConfigGroup> getConfiguration(final ConfigType type, final String namespace) { if (!type.hasNamespace() && namespace != null && !namespace.isEmpty()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } if (configGroupsByTypeWithNamespace.containsKey(type)) { final Map<String, List<ConfigGroup>> configGroupsByNamespace = configGroupsByTypeWithNamespace.get(type); if (configGroupsByNamespace.containsKey(namespace)) { return configGroupsByNamespace.get(namespace); } } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); final Path namespaceDir = typeDir.resolve(namespace); final List<ConfigGroup> configGroups = getConfiguration(namespaceDir, type); if (configGroups != null) { if (!configGroupsByTypeWithNamespace.containsKey(type)) { configGroupsByTypeWithNamespace.put(type, new ConcurrentHashMap<>()); } final Map<String, List<ConfigGroup>> configGroupsByNamespace = configGroupsByTypeWithNamespace.get(type); configGroupsByNamespace.put(namespace, configGroups); } else { return Collections.emptyList(); } return configGroups; }
@Override public List<ConfigGroup> getConfiguration(final ConfigType type) { if (type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } if (configGroupsByTypeWithoutNamespace.containsKey(type)) { return configGroupsByTypeWithoutNamespace.get(type); } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); final List<ConfigGroup> configGroups = getConfiguration(typeDir, type); if (configGroups != null) { configGroupsByTypeWithoutNamespace.put(type, configGroups); } else { return Collections.emptyList(); } return configGroups; }
private Path resolveConfigGroupPath(final ConfigGroup configGroup) { final ConfigType type = configGroup.getType(); final String namespace = configGroup.getNamespace(); if (type.hasNamespace() && (namespace == null || namespace.isEmpty())) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } else if (!type.hasNamespace() && namespace != null && !namespace.isEmpty()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } final String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); Path path = ioService.get(systemRepository.getUri()).resolve(type.getDir()); if (type.hasNamespace()) { path = path.resolve(namespace); } return path.resolve(filename + type.getExt()); }
@Override public ConfigGroup newConfigGroup(final ConfigType type, final String namespace, final String name, final String description) { if (!type.hasNamespace() && namespace != null && !namespace.isEmpty()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setNamespace(namespace); configGroup.setEnabled(true); return configGroup; }
@Override public ConfigGroup newConfigGroup(final ConfigType type, final String name, final String description) { if (type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setEnabled(true); return configGroup; }
@Override public Map<String, List<ConfigGroup>> getConfigurationByNamespace(final ConfigType type) { if (!type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } final Path typeDir = ioService.get(systemRepository.getUri()).resolve(type.getDir()); if (!ioService.exists(typeDir)) { return Collections.emptyMap(); } final DirectoryStream<Path> foundNamespaces = getDirectoryStreamForDirectories(typeDir); // Force cache update for all namespaces in that type final Iterator<Path> it = foundNamespaces.iterator(); while (it.hasNext()) { final String namespace = Paths.convert(it.next()).getFileName(); getConfiguration(type, namespace); } // Return the updated cache return configGroupsByTypeWithNamespace.get(type); }