@Test public void testLoadConfiguration() { final ScopePathBuilderFactory factory = getConfigService().getScopePathBuilderFactory(TestConfiguration.class); final ScopePath path = factory.annotatedPath().create(); final ComplexConfigDTO configuration = createTestConfigDTO(path); persister.saveConfiguration(configuration); final ComplexConfigDTO result = persister.loadConfiguration(path); Assert.assertEquals(configuration, result); }
@Override public ComplexConfigDTO loadConfiguration(final ScopePath scopePath) { Assert.paramNotNull(scopePath, "scopePath"); final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(scopePath) + File.separator + gen.createName(scopePath) + fileExtension); FileInputStream in = null; try { in = FileUtils.openInputStream(configFile); final ComplexConfigDTO configDTO = marshaller.unmarshal(in); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + scopePath + "'!"); } configDTO.setDefiningScopePath(scopePath); return configDTO; } catch (final FileNotFoundException e) { return null; } catch (final IOException e) { throw new StoreConfigException("Error while loading configuration for the scope Path '" + scopePath + "'!", e); } finally { try { if (in != null) { in.close(); } } catch (final IOException e) { LOG.warn("Error while closing inputStream for configuration with scopepath '" + scopePath + "'!", e); } } }
FileConfigPersister implements ConfigPersister { @Override public ComplexConfigDTO loadConfiguration(final ScopePath scopePath) { Assert.paramNotNull(scopePath, "scopePath"); final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(scopePath) + File.separator + gen.createName(scopePath) + fileExtension); FileInputStream in = null; try { in = FileUtils.openInputStream(configFile); final ComplexConfigDTO configDTO = marshaller.unmarshal(in); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + scopePath + "'!"); } configDTO.setDefiningScopePath(scopePath); return configDTO; } catch (final FileNotFoundException e) { return null; } catch (final IOException e) { throw new StoreConfigException("Error while loading configuration for the scope Path '" + scopePath + "'!", e); } finally { try { if (in != null) { in.close(); } } catch (final IOException e) { LOG.warn("Error while closing inputStream for configuration with scopepath '" + scopePath + "'!", e); } } } }
FileConfigPersister implements ConfigPersister { @Override public ComplexConfigDTO loadConfiguration(final ScopePath scopePath) { Assert.paramNotNull(scopePath, "scopePath"); final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(scopePath) + File.separator + gen.createName(scopePath) + fileExtension); FileInputStream in = null; try { in = FileUtils.openInputStream(configFile); final ComplexConfigDTO configDTO = marshaller.unmarshal(in); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + scopePath + "'!"); } configDTO.setDefiningScopePath(scopePath); return configDTO; } catch (final FileNotFoundException e) { return null; } catch (final IOException e) { throw new StoreConfigException("Error while loading configuration for the scope Path '" + scopePath + "'!", e); } finally { try { if (in != null) { in.close(); } } catch (final IOException e) { LOG.warn("Error while closing inputStream for configuration with scopepath '" + scopePath + "'!", e); } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); }
FileConfigPersister implements ConfigPersister { @Override public ComplexConfigDTO loadConfiguration(final ScopePath scopePath) { Assert.paramNotNull(scopePath, "scopePath"); final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(scopePath) + File.separator + gen.createName(scopePath) + fileExtension); FileInputStream in = null; try { in = FileUtils.openInputStream(configFile); final ComplexConfigDTO configDTO = marshaller.unmarshal(in); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + scopePath + "'!"); } configDTO.setDefiningScopePath(scopePath); return configDTO; } catch (final FileNotFoundException e) { return null; } catch (final IOException e) { throw new StoreConfigException("Error while loading configuration for the scope Path '" + scopePath + "'!", e); } finally { try { if (in != null) { in.close(); } } catch (final IOException e) { LOG.warn("Error while closing inputStream for configuration with scopepath '" + scopePath + "'!", e); } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scopePath, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); }
FileConfigPersister implements ConfigPersister { @Override public ComplexConfigDTO loadConfiguration(final ScopePath scopePath) { Assert.paramNotNull(scopePath, "scopePath"); final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(scopePath) + File.separator + gen.createName(scopePath) + fileExtension); FileInputStream in = null; try { in = FileUtils.openInputStream(configFile); final ComplexConfigDTO configDTO = marshaller.unmarshal(in); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + scopePath + "'!"); } configDTO.setDefiningScopePath(scopePath); return configDTO; } catch (final FileNotFoundException e) { return null; } catch (final IOException e) { throw new StoreConfigException("Error while loading configuration for the scope Path '" + scopePath + "'!", e); } finally { try { if (in != null) { in.close(); } } catch (final IOException e) { LOG.warn("Error while closing inputStream for configuration with scopepath '" + scopePath + "'!", e); } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scopePath, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); static final String ID; }