private void saveConfiguration(final ConfigGroup configGroup, final Path filePath, final CommentedOption commentedOption) { try { ioService.startBatch(filePath.getFileSystem()); ioService.write(filePath, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } } }
private List<ConfigGroup> getConfiguration(final Path dir, final ConfigType type) { final List<ConfigGroup> configGroups = new ArrayList<>(); if (!ioService.exists(dir)) { return configGroups; } final DirectoryStream<Path> foundConfigs = getDirectoryStreamForFilesWithParticularExtension(dir, type.getExt()); //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); } return configGroups; } return null; }
@Before public void setup() throws IOException { fileSystemTestingUtils.setup(); when(systemRepository.getUri()).thenReturn("git://amend-repo-test"); marshaller = new ConfigGroupMarshaller(); configurationFactory = new MigrationConfigurationFactoryImpl(new DefaultPasswordServiceImpl()); ioService = mockIoService(); configurationService = new MigrationConfigurationServiceImpl(systemRepository, marshaller, identity, ioService, repoChangedEvent, spaceChangedEvent, changedEvent, fileSystemTestingUtils.getFileSystem()); }
@Before public void setup() throws IOException { fileSystemTestingUtils.setup(); when(systemRepository.getUri()).thenReturn("git://amend-repo-test"); marshaller = new ConfigGroupMarshaller(); configurationFactory = new ConfigurationFactoryImpl(new DefaultPasswordServiceImpl()); ioService = mockIoService(); configurationService = new ConfigurationServiceImpl(systemRepository, marshaller, identity, ioService, repoChangedEvent, spaceChangedEvent, changedEvent, fileSystemTestingUtils.getFileSystem()); }
@Override public boolean updateConfiguration(ConfigGroup configGroup) { String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt()); final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Updated config " + filePath.getFileName()); try { ioService.startBatch(filePath.getFileSystem()); ioService.write(filePath, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } //Invalidate cache if a new item has been created; otherwise cached value is stale configuration.remove(configGroup.getType()); return true; }
while (it.hasNext()) { final String content = ioService.readAllString(it.next()); final ConfigGroup configGroup = marshaller.unmarshall(content); configGroups.add(configGroup);
@Before public void setup() throws IOException { fileSystemTestingUtils.setup(); when(systemRepository.getUri()).thenReturn("git://amend-repo-test"); marshaller = new ConfigGroupMarshaller(); configurationFactory = new ConfigurationFactoryImpl(new DefaultPasswordServiceImpl()); ioService = mockIoService(); configurationService = new ConfigurationServiceImpl(systemRepository, marshaller, identity, ioService, repoChangedEvent, spaceChangedEvent, changedEvent, fileSystemTestingUtils.getFileSystem()); }
private boolean saveConfiguration(final ConfigGroup configGroup, final Path path, final String commitMessage, final boolean isNew) { // avoid duplicated writes to not cause cyclic cluster sync if (isNew && ioService.exists(path)) { return true; } final CommentedOption commentedOption = new CommentedOption(getIdentityName(), commitMessage); try { ioService.startBatch(path.getFileSystem()); ioService.write(path, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } invalidateCacheAfterUpdatingConfigGroup(configGroup); return true; }
@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; }
@Override public boolean addConfiguration(final ConfigGroup configGroup) { String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_"); final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt()); // avoid duplicated writes to not cause cyclic cluster sync if (ioService.exists(filePath)) { return true; } final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Created config " + filePath.getFileName()); try { ioService.startBatch(filePath.getFileSystem()); ioService.write(filePath, marshaller.marshall(configGroup), commentedOption); updateLastModified(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { ioService.endBatch(); } //Invalidate cache if a new item has been created; otherwise cached value is stale configuration.remove(configGroup.getType()); return true; }