@Test public void testViewUriWithTypo() throws Exception { DatasetDescriptor desc = new DatasetDescriptor.Builder() .schema(SchemaBuilder.record("Test").fields() .requiredLong("ts") .endRecord()) .partitionStrategy(new PartitionStrategy.Builder() .year("ts") .month("ts") .day("ts") .build()) .build(); String viewUri = new URIBuilder(repo.getUri(), "ns", "test") .with("year", "2014") .with("month", "3") .with("dy", "14") .build() .toString(); URI actualViewUri = new URIBuilder(repo.getUri(), "ns", "test") .with("month", "3") .with("year", "2014") .build(); Assert.assertTrue("Should be a view URI", viewUri.startsWith("view:")); AbstractDataset ds = mock(AbstractDataset.class); when(repo.load("ns", "test", GenericRecord.class)).thenReturn(ds); when(ds.getDescriptor()).thenReturn(desc); AbstractRefinableView view = mock(AbstractRefinableView.class); when(ds.filter(any(Constraints.class))).thenReturn(view); when(view.getUri()).thenReturn(actualViewUri); command.targets = Lists.newArrayList(viewUri); TestHelpers.assertThrows("Should reject a view with missing attribute", IllegalArgumentException.class, new Runnable() { @Override public void run() { try { command.run(); } catch (IOException e) { throw new RuntimeException("Caught IOException", e); } } }); }
@Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); if(skipTrash) { view.deleteAll(); }else { view.moveToTrash(); } } else if (isDatasetUri(uriOrName)) { if(skipTrash) { Datasets.delete(uriOrName); }else { Datasets.moveToTrash(uriOrName); } } else { if(skipTrash){ getDatasetRepository().delete(namespace, uriOrName); }else { getDatasetRepository().moveToTrash(namespace, uriOrName); } } console.debug("Deleted {}", uriOrName); } return 0; }
DeleteCommand extends BaseDatasetCommand { @Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); if(skipTrash) { view.deleteAll(); }else { view.moveToTrash(); } } else if (isDatasetUri(uriOrName)) { if(skipTrash) { Datasets.delete(uriOrName); }else { Datasets.moveToTrash(uriOrName); } } else { if(skipTrash){ getDatasetRepository().delete(namespace, uriOrName); }else { getDatasetRepository().moveToTrash(namespace, uriOrName); } } console.debug("Deleted {}", uriOrName); } return 0; } }
DeleteCommand extends BaseDatasetCommand { @Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); if(skipTrash) { view.deleteAll(); }else { view.moveToTrash(); } } else if (isDatasetUri(uriOrName)) { if(skipTrash) { Datasets.delete(uriOrName); }else { Datasets.moveToTrash(uriOrName); } } else { if(skipTrash){ getDatasetRepository().delete(namespace, uriOrName); }else { getDatasetRepository().moveToTrash(namespace, uriOrName); } } console.debug("Deleted {}", uriOrName); } return 0; } DeleteCommand(Logger console); }
DeleteCommand extends BaseDatasetCommand { @Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); if(skipTrash) { view.deleteAll(); }else { view.moveToTrash(); } } else if (isDatasetUri(uriOrName)) { if(skipTrash) { Datasets.delete(uriOrName); }else { Datasets.moveToTrash(uriOrName); } } else { if(skipTrash){ getDatasetRepository().delete(namespace, uriOrName); }else { getDatasetRepository().moveToTrash(namespace, uriOrName); } } console.debug("Deleted {}", uriOrName); } return 0; } DeleteCommand(Logger console); @Override int run(); @Override List<String> getExamples(); }
DeleteCommand extends BaseDatasetCommand { @Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); if(skipTrash) { view.deleteAll(); }else { view.moveToTrash(); } } else if (isDatasetUri(uriOrName)) { if(skipTrash) { Datasets.delete(uriOrName); }else { Datasets.moveToTrash(uriOrName); } } else { if(skipTrash){ getDatasetRepository().delete(namespace, uriOrName); }else { getDatasetRepository().moveToTrash(namespace, uriOrName); } } console.debug("Deleted {}", uriOrName); } return 0; } DeleteCommand(Logger console); @Override int run(); @Override List<String> getExamples();  }