use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog in project timbuctoo by HuygensING.
the class DeleteMutation method executeAction.
@Override
public Object executeAction(DataFetchingEnvironment environment) {
final Graph graph = new Graph(environment.getArgument("graph"));
final String uri = environment.getArgument("uri");
final Map entity = environment.getArgument("entity");
ImmutableContextData contextData = environment.getContext();
Optional<User> userOpt = contextData.getUser();
if (!userOpt.isPresent()) {
throw new RuntimeException("User should be logged in.");
}
User user = userOpt.get();
Optional<DataSet> dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName);
if (!dataSetOpt.isPresent()) {
throw new RuntimeException("Data set is not available.");
}
DataSet dataSet = dataSetOpt.get();
if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.DELETE)) {
throw new RuntimeException("User should have permissions to delete entities of the data set.");
}
try (Stream<CursorQuad> quads = dataSet.getQuadStore().getQuadsInGraph(uri, Optional.of(graph))) {
if (quads.findAny().isEmpty()) {
if (graph.isDefaultGraph()) {
throw new RuntimeException("Subject with uri '" + uri + "' does not exist in the default graph");
} else {
throw new RuntimeException("Subject with uri '" + uri + "' does not exist in graph '" + graph + "'");
}
}
}
try {
dataSet.getImportManager().generateLog(dataSet.getMetadata().getBaseUri(), null, new GraphQlToRdfPatch(graph.getUri(), uri, userUriCreator.create(user), new DeleteMutationChangeLog(graph, uri, entity))).get();
} catch (LogStorageFailedException | JsonProcessingException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return new RemovedEntity(graph.getUri(), uri);
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog in project timbuctoo by HuygensING.
the class DeleteMutationChangeLogTest method getAdditionsReturnsNothing.
@Test
public void getAdditionsReturnsNothing() throws Exception {
DeleteMutationChangeLog instance = new DeleteMutationChangeLog(new Graph(GRAPH), SUBJECT, null);
Stream<Change> additions = instance.getAdditions(dataSet);
assertThat(additions, StreamMatchers.empty());
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog in project timbuctoo by HuygensING.
the class DeleteMutationChangeLogTest method getDeletionsReturnsDeletions.
@Test
public void getDeletionsReturnsDeletions() throws Exception {
String existingValue1 = "existingValue1";
String existingValue2 = "existingValue2";
DeleteMutationChangeLog instance = new DeleteMutationChangeLog(new Graph(GRAPH), SUBJECT, null);
valuesInQuadStore(NAMES_PRED, existingValue1, existingValue2);
List<Change> deletions = instance.getDeletions(dataSet).collect(toList());
assertThat(deletions.size(), is(1));
assertThat(deletions, contains(likeChange().valuesIsEmpty().withOldValues(new Value(existingValue1, STRING), new Value(existingValue2, STRING))));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog in project timbuctoo by HuygensING.
the class DeleteMutationChangeLogTest method getReplacementsReturnsNothing.
@Test
public void getReplacementsReturnsNothing() throws Exception {
DeleteMutationChangeLog instance = new DeleteMutationChangeLog(new Graph(GRAPH), SUBJECT, null);
Stream<Change> replacements = instance.getReplacements(dataSet);
assertThat(replacements, StreamMatchers.empty());
}
Aggregations