use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog in project timbuctoo by HuygensING.
the class CreateMutationChangeLogTest method getAdditionsReturnsCreations.
@Test
public void getAdditionsReturnsCreations() throws Exception {
String addedValue = "newValue";
Map<Object, Object> creations = Maps.newHashMap();
creations.put(NAMES_FIELD, createPropertyInput(addedValue));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("creations", creations);
CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
List<Change> adds = instance.getAdditions(dataSet).collect(toList());
assertThat(adds.size(), is(2));
assertThat(adds.get(0), is(likeChange().withValues(new Value(TYPE_URI, null)).oldValuesIsEmpty()));
assertThat(adds.get(1), is(likeChange().withValues(new Value(addedValue, STRING)).oldValuesIsEmpty()));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog in project timbuctoo by HuygensING.
the class CreateMutation 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.CREATE)) {
throw new RuntimeException("User should have permissions to create entities of the data set.");
}
try (Stream<CursorQuad> quads = dataSet.getQuadStore().getQuadsInGraph(uri, Optional.of(graph))) {
if (quads.findAny().isPresent()) {
if (graph.isDefaultGraph()) {
throw new RuntimeException("Subject with uri '" + uri + "' already exists in the default graph");
} else {
throw new RuntimeException("Subject with uri '" + uri + "' already exists in graph '" + graph + "'");
}
}
}
try {
dataSet.getImportManager().generateLog(dataSet.getMetadata().getBaseUri(), null, new GraphQlToRdfPatch(graph.getUri(), uri, userUriCreator.create(user), new CreateMutationChangeLog(graph, uri, typeUri, entity))).get();
} catch (LogStorageFailedException | JsonProcessingException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return subjectFetcher.getItemInGraph(uri, Optional.of(graph), dataSet);
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog in project timbuctoo by HuygensING.
the class CreateMutationChangeLogTest method getReplacementsReturnsNothing.
@Test
public void getReplacementsReturnsNothing() throws Exception {
String addedValue1 = "newValue1";
String addedValue2 = "newValue2";
Map<Object, Object> creations = Maps.newHashMap();
creations.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue1), createPropertyInput(addedValue2)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("creations", creations);
CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
Stream<Change> replacements = instance.getReplacements(dataSet);
assertThat(replacements, StreamMatchers.empty());
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog in project timbuctoo by HuygensING.
the class CreateMutationChangeLogTest method getDeletionsReturnsNothing.
@Test
public void getDeletionsReturnsNothing() throws Exception {
String addedValue1 = "newValue1";
String addedValue2 = "newValue2";
Map<Object, Object> creations = Maps.newHashMap();
creations.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue1), createPropertyInput(addedValue2)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("creations", creations);
CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
Stream<Change> deletes = instance.getDeletions(dataSet);
assertThat(deletes, StreamMatchers.empty());
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog in project timbuctoo by HuygensING.
the class CreateMutationChangeLogTest method getAdditionsForListReturnsCreations.
@Test
public void getAdditionsForListReturnsCreations() throws Exception {
String addedValue1 = "newValue1";
String addedValue2 = "newValue2";
Map<Object, Object> creations = Maps.newHashMap();
creations.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue1), createPropertyInput(addedValue2)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("creations", creations);
CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
List<Change> adds = instance.getAdditions(dataSet).collect(toList());
assertThat(adds.size(), is(2));
assertThat(adds.get(0), is(likeChange().withValues(new Value(TYPE_URI, null)).oldValuesIsEmpty()));
assertThat(adds.get(1), is(likeChange().withValues(new Value(addedValue1, STRING), new Value(addedValue2, STRING)).oldValuesIsEmpty()));
}
Aggregations