use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class Import method importData.
@POST
@Produces("application/json")
public Response importData(@HeaderParam("Authorization") String authorization, @QueryParam("forceCreation") boolean forceCreation, ImportData importData) throws DataStoreCreationException {
final Either<Response, Response> responses = authCheck.getOrCreate(authorization, importData.userId, importData.dataSetId, forceCreation).flatMap(userAndDs -> authCheck.hasAdminAccess(userAndDs.getLeft(), userAndDs.getRight())).map(userAndDs -> {
final DataSet dataSet = userAndDs.getRight();
ImportManager importManager = dataSet.getImportManager();
try {
LOG.info("Loading files");
Iterator<RemoteFile> files = resourceSyncFileLoader.loadFiles(importData.source.toString()).iterator();
LOG.info("Found files '{}'", files.hasNext());
ResourceSyncResport resourceSyncResport = new ResourceSyncResport();
while (files.hasNext()) {
RemoteFile file = files.next();
MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE;
try {
parsedMediatype = MediaType.valueOf(file.getMimeType());
} catch (IllegalArgumentException e) {
LOG.error("Failed to get mediatype", e);
}
if (importManager.isRdfTypeSupported(parsedMediatype)) {
resourceSyncResport.importedFiles.add(file.getUrl());
importManager.addLog(dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getBaseUri(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData(), Optional.of(Charsets.UTF_8), parsedMediatype);
} else {
resourceSyncResport.ignoredFiles.add(file.getUrl());
importManager.addFile(file.getData(), file.getUrl(), parsedMediatype);
}
}
return Response.ok(resourceSyncResport).build();
} catch (Exception e) {
LOG.error("Could not read files to import", e);
return Response.serverError().build();
}
});
if (responses.isLeft()) {
return responses.getLeft();
} else {
return responses.get();
}
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibility method getFieldDefinition.
@Override
public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) {
Collection<DataSet> dataSets = dataSetRepository.getDataSets();
Set<String> dataSetNamesWithOutReadPermission = dataSets.stream().filter(dataSet -> !userPermissionCheck.getPermissions(dataSet.getMetadata()).contains(Permission.READ)).map(dataSet -> dataSet.getMetadata().getCombinedId()).collect(Collectors.toSet());
Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator();
while (graphQlFieldDefinitionIterator.hasNext()) {
GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next();
if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) {
return graphQlFieldDefinition;
}
}
return null;
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibility method getFieldDefinitions.
@Override
public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) {
List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>();
Collection<DataSet> dataSets = dataSetRepository.getDataSets();
Set<String> dataSetNamesWithOutReadPermission = dataSets.stream().filter(dataSet -> !userPermissionCheck.getPermissions(dataSet.getMetadata()).contains(Permission.READ)).map(dataSet -> dataSet.getMetadata().getCombinedId()).collect(Collectors.toSet());
Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator();
while (graphQlFieldDefinitionIterator.hasNext()) {
GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next();
if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) {
graphQlFieldDefinitions.add(graphQlFieldDefinition);
}
}
return graphQlFieldDefinitions;
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class RootQuery method getCollections.
public CollectionMetadataList getCollections(DataSetMetaData input, Optional<User> userOpt) {
final User user = userOpt.orElse(null);
final DataSet dataSet = dataSetRepository.getDataSet(user, input.getOwnerId(), input.getDataSetId()).get();
final TypeNameStore typeNameStore = dataSet.getTypeNameStore();
final List<CollectionMetadata> colls = dataSet.getSchemaStore().getStableTypes().values().stream().map(x -> {
return getCollection(dataSet, typeNameStore, x);
}).collect(Collectors.toList());
return ImmutableCollectionMetadataList.builder().nextCursor(Optional.empty()).prevCursor(Optional.empty()).items(colls).build();
}
use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.
the class DataSetRepositoryTest method removeDataSetRemovesTheDataSetsAuthorizations.
@Test
public void removeDataSetRemovesTheDataSetsAuthorizations() throws Exception {
User user = User.create(null, "user");
final DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
DataSetMetaData metadata = dataSet.getMetadata();
String owner = metadata.getOwnerId();
given(permissionFetcher.getPermissions(user, metadata)).willReturn(Sets.newHashSet(Permission.ADMIN));
dataSetRepository.removeDataSet(owner, "dataset", user);
verify(permissionFetcher).removeAuthorizations(metadata.getCombinedId());
}
Aggregations