use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class MutationHelpers method checkAdminPermissions.
public static void checkAdminPermissions(DataFetchingEnvironment env, DataSetMetaData dataSetMetaData) throws RuntimeException {
ContextData contextData = env.getContext();
UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck();
if (!userPermissionCheck.getPermissions(dataSetMetaData).contains(Permission.ADMIN)) {
throw new RuntimeException("You are not admin of this dataset");
}
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class PredicateMutationRdfPatcher method sendQuads.
@Override
public void sendQuads(RdfPatchSerializer saver, Consumer<String> importStatusConsumer, DataSet dataSet) throws LogStorageFailedException {
final QuadStore quadStore = dataSet.getQuadStore();
final Map<String, String> foundSubjects = new HashMap<>();
for (Map.Entry<UUID, PredicateMutation.SubjectFinder> entry : mutation.getSubjectFinders().entrySet()) {
foundSubjects.put(entry.getKey().toString(), entry.getValue().getSubject(quadStore));
}
for (CursorQuad newValue : mutation.getFullRetractions()) {
final String subject = foundSubjects.getOrDefault(newValue.getSubject(), newValue.getSubject());
final String predicate = newValue.getPredicate();
final Direction direction = newValue.getDirection();
try (Stream<CursorQuad> quads = quadStore.getQuads(subject, predicate, direction, "")) {
for (CursorQuad oldValue : (Iterable<CursorQuad>) quads::iterator) {
saver.delQuad(oldValue.getSubject(), oldValue.getPredicate(), oldValue.getObject(), oldValue.getValuetype().orElse(null), oldValue.getLanguage().orElse(null), null);
}
}
}
for (CursorQuad oldValue : mutation.getRetractions()) {
saver.delQuad(foundSubjects.getOrDefault(oldValue.getSubject(), oldValue.getSubject()), oldValue.getPredicate(), foundSubjects.getOrDefault(oldValue.getObject(), oldValue.getObject()), oldValue.getValuetype().orElse(null), oldValue.getLanguage().orElse(null), null);
}
for (CursorQuad newValue : mutation.getAdditions()) {
if (newValue.getObject() != null) {
saver.onQuad(foundSubjects.getOrDefault(newValue.getSubject(), newValue.getSubject()), newValue.getPredicate(), foundSubjects.getOrDefault(newValue.getObject(), newValue.getObject()), newValue.getValuetype().orElse(null), newValue.getLanguage().orElse(null), null);
}
}
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class SummaryPropsMutation method get.
@Override
public Object get(DataFetchingEnvironment env) {
DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
try {
String collectionUri = env.getArgument("collectionUri");
Map data = env.getArgument("summaryProperties");
final PredicateMutation mutation = new PredicateMutation();
mutation.entity(collectionUri, getValue(data, "title").map(v -> replace(TIM_SUMMARYTITLEPREDICATE, value(v))).orElse(null), getValue(data, "image").map(v -> replace(TIM_SUMMARYIMAGEPREDICATE, value(v))).orElse(null), getValue(data, "description").map(v -> replace(TIM_SUMMARYDESCRIPTIONPREDICATE, value(v))).orElse(null));
MutationHelpers.addMutation(dataSet, mutation);
return new LazyTypeSubjectReference(collectionUri, dataSet);
} catch (LogStorageFailedException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class JsonLdEditEndpoint method submitChanges.
@PUT
public Response submitChanges(String jsonLdImport, @PathParam("user") String ownerId, @PathParam("dataset") String dataSetId, @HeaderParam("authorization") String authHeader) throws LogStorageFailedException {
Optional<User> user;
try {
user = userValidator.getUserFromAccessToken(authHeader);
} catch (UserValidationException e) {
user = Optional.empty();
}
Optional<DataSet> dataSetOpt = dataSetRepository.getDataSet(user.get(), ownerId, dataSetId);
if (!dataSetOpt.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final DataSet dataSet = dataSetOpt.get();
final QuadStore quadStore = dataSet.getQuadStore();
final ImportManager importManager = dataSet.getImportManager();
final Response response = checkWriteAccess(dataSet, user, permissionFetcher);
if (response != null) {
return response;
}
try {
final Future<ImportStatus> promise = importManager.generateLog(dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getBaseUri(), fromCurrentState(documentLoader, jsonLdImport, quadStore, TIM_USERS + user.get().getPersistentId(), UUID.randomUUID().toString(), Clock.systemUTC()));
return handleImportManagerResult(promise);
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (ConcurrentUpdateException e) {
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
}
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class RdfUpload method upload.
@Consumes(MediaType.MULTIPART_FORM_DATA)
@POST
public Response upload(@FormDataParam("file") final InputStream rdfInputStream, @FormDataParam("file") final FormDataBodyPart body, @FormDataParam("fileMimeTypeOverride") final MediaType mimeTypeOverride, @FormDataParam("encoding") final String encoding, @FormDataParam("baseUri") final URI baseUri, @FormDataParam("defaultGraph") final URI defaultGraph, @HeaderParam("authorization") final String authHeader, @PathParam("userId") final String userId, @PathParam("dataSet") final String dataSetId, @QueryParam("forceCreation") boolean forceCreation, @QueryParam("async") final boolean async) throws ExecutionException, InterruptedException, LogStorageFailedException, DataStoreCreationException {
final Either<Response, Response> result = authCheck.getOrCreate(authHeader, userId, dataSetId, forceCreation).flatMap(userAndDs -> authCheck.hasAdminAccess(userAndDs.getLeft(), userAndDs.getRight())).map((Tuple<User, DataSet> userDataSetTuple) -> {
final MediaType mediaType = mimeTypeOverride == null ? body.getMediaType() : mimeTypeOverride;
final DataSet dataSet = userDataSetTuple.getRight();
ImportManager importManager = dataSet.getImportManager();
if (mediaType == null || !importManager.isRdfTypeSupported(mediaType)) {
return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity("{\"error\": \"We do not support the mediatype '" + mediaType + "'. Make sure to add the correct " + "mediatype to the file parameter. In curl you'd use `-F \"file=@<filename>;type=<mediatype>\"`. In a " + "webbrowser you probably have no way of setting the correct mimetype. So you can use a special " + "parameter " + "to override it: `formData.append(\"fileMimeTypeOverride\", \"<mimetype>\");`\"}").build();
}
if (StringUtils.isBlank(encoding)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Please provide an 'encoding' parameter").build();
}
if (StringUtils.isBlank(body.getContentDisposition().getFileName())) {
return Response.status(400).entity("filename cannot be empty.").build();
}
Future<ImportStatus> promise = null;
try {
promise = importManager.addLog(baseUri == null ? dataSet.getMetadata().getBaseUri() : baseUri.toString(), defaultGraph == null ? dataSet.getMetadata().getBaseUri() : defaultGraph.toString(), body.getContentDisposition().getFileName(), rdfInputStream, Optional.of(Charset.forName(encoding)), mediaType);
} catch (LogStorageFailedException e) {
return Response.serverError().build();
}
if (!async) {
return handleImportManagerResult(promise);
}
return Response.accepted().build();
});
if (result.isLeft()) {
return result.getLeft();
} else {
return result.get();
}
}
Aggregations