RenameDataSetsWithFolderPath implements BaseUpgradeTaskTo_1_2_0_PE { @Override public void run() { final Stream<DataSetMetadata> datasets = dataSetMetadataRepository.list(); datasets.forEach(dataset -> { final Folder folder = folderRepository.locateEntry(dataset.getId(), FolderContentType.DATASET); if (folder != null && !StringUtils.equals("/", folder.getPath())) { String newName = dataset.getName() + " - " + StringUtils.strip(folder.getPath(), "/"); dataset.setName(newName); dataSetMetadataRepository.save(dataset); LOG.debug("dataset #{} renamed to {}", dataset.getId(), newName); } else { LOG.debug("dataset #{} not renamed since it's in the user home folder", dataset.getId()); } }); }  @Override int getOrder(); @Override target getTarget(); @Override void run();  }
@Test public void shouldRenameDataSets() throws Exception { List<String> expected = new ArrayList<>(); expected.add("cars"); expected.add("us_states - my lookup"); expected.add("communes_france - personnal/confidential"); expected.add("Emails Reference - Quick Examples and Tutorials/Lookup"); expected.add("Customer Contact Data - Quick Examples and Tutorials"); expected.add("Business Unit Regions With States - Quick Examples and Tutorials/Lookup"); expected.add("HRMS Export - Quick Examples and Tutorials"); expected.add("nba_franchises"); expected.add("Marketing Leads - Quick Examples and Tutorials"); expected.add("CRM Export - Quick Examples and Tutorials"); expected.add("Customer Marketing Leads - Quick Examples and Tutorials"); task.run(); final Stream<DataSetMetadata> list = repository.list(); final List<String> names = list.map(DataSetMetadata::getName).collect(toList()); assertTrue(names.containsAll(expected)); }