@Test public void filteredLoad_shouldReturnConfigurationWithCorrespindingMetaData() throws InvalidConfigurationException, PersistenceException { Map<String, String> metaData = new HashMap<String, String>(); metaData.put(ContextId.META_KEY_ID, "context2"); List<ConfigItem<Map<String, String>>> items = persistenceService.load(metaData); assertThat(items.size(), is(1)); ConfigItem<?> loadedConfiguration = items.get(0); assertThat(loadedConfiguration.getMetaData().get(ContextId.META_KEY_ID), is("context2")); }
@Override public void persist(ConfigItem<WorkflowRepresentation> config) throws PersistenceException { LOGGER.info("Persisting Workflow " + config.getContent().getName()); WorkflowRepresentation content = config.getContent(); String marshallWorkflow = converter.marshallWorkflow(content); File file = new File(folder, content.getName()); try { FileWriter writer = new FileWriter(file); writer.write(marshallWorkflow); writer.close(); } catch (IOException e) { throw new PersistenceException(e); } }
@Override public List<ConfigItem<WorkflowRepresentation>> load(Map<String, String> metadata) throws PersistenceException, InvalidConfigurationException { LOGGER.info("Loading all Workflows"); List<ConfigItem<WorkflowRepresentation>> result = new ArrayList<ConfigItem<WorkflowRepresentation>>(); try { File[] listFiles = folder.listFiles(); Arrays.sort(listFiles, NameFileComparator.NAME_COMPARATOR); for (File file : listFiles) { String readFileToString = FileUtils.readFileToString(file); WorkflowRepresentation unmarshallWorkflow = converter.unmarshallWorkflow(readFileToString); ConfigItem<WorkflowRepresentation> config = new ConfigItem<WorkflowRepresentation>(); config.setContent(unmarshallWorkflow); result.add(config); } } catch (IOException e) { throw new PersistenceException(e); } return result; }