Search in sources :

Example 1 with BasicDataSetMetaData

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData in project timbuctoo by HuygensING.

the class AuthCheckTest method checkAdminAccessReturnsNullIfTheUserIsAnAdminForTheDataSet.

@Test
public void checkAdminAccessReturnsNullIfTheUserIsAnAdminForTheDataSet() throws Exception {
    User notOwner = User.create(null, "user");
    UserValidator userValidator = mock(UserValidator.class);
    given(userValidator.getUserFromAccessToken(anyString())).willReturn(Optional.of(notOwner));
    PermissionFetcher permissionFetcher = mock(PermissionFetcher.class);
    given(permissionFetcher.getPermissions(any(User.class), any(BasicDataSetMetaData.class))).willReturn(permissionsForAdmin());
    Response response = checkAdminAccess(permissionFetcher, userValidator, "auth", new BasicDataSetMetaData("ownerid", "datasetid", "http://ex.org", "http://example.org/prefix/", false, false));
    assertThat(response.getStatus(), is(200));
}
Also used : Response(javax.ws.rs.core.Response) PermissionFetcher(nl.knaw.huygens.timbuctoo.v5.security.PermissionFetcher) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) Test(org.junit.Test)

Example 2 with BasicDataSetMetaData

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData in project timbuctoo by HuygensING.

the class BdbRmlDataSourceStoreTest method itWorks.

@Test
public void itWorks() throws Exception {
    BdbNonPersistentEnvironmentCreator dbCreator = new BdbNonPersistentEnvironmentCreator();
    DataSetMetaData dataSetMetadata = new BasicDataSetMetaData("userid", "datasetid", "http://timbuctoo.huygens.knaw.nl/v5/userid/datasetid", "http://example.org/prefix/", false, false);
    final RmlDataSourceStore rmlDataSourceStore = new BdbRmlDataSourceStore(dbCreator.getDatabase("userid", "datasetid", "rmlSource", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()), new ImportStatus(new LogList()));
    RdfSerializer rdfSerializer = new RmlDataSourceRdfSerializer(rmlDataSourceStore);
    RawUploadRdfSaver rawUploadRdfSaver = new RawUploadRdfSaver(dataSetMetadata, "fileName", APPLICATION_OCTET_STREAM_TYPE, rdfSerializer, "origFileName", Clock.systemUTC());
    final String inputCol1 = rawUploadRdfSaver.addCollection("collection1");
    ImportPropertyDescriptions importPropertyDescriptions = new ImportPropertyDescriptions();
    importPropertyDescriptions.getOrCreate(1).setPropertyName("propName1");
    importPropertyDescriptions.getOrCreate(2).setPropertyName("propName2");
    rawUploadRdfSaver.addPropertyDescriptions(inputCol1, importPropertyDescriptions);
    rawUploadRdfSaver.addEntity(inputCol1, ImmutableMap.of("propName1", "value1", "propName2", "val2"));
    rawUploadRdfSaver.addEntity(inputCol1, ImmutableMap.of("propName1", "entVal1", "propName2", "entVal2"));
    final String inputCol2 = rawUploadRdfSaver.addCollection("collection2");
    ImportPropertyDescriptions importPropertyDescriptions1 = new ImportPropertyDescriptions();
    importPropertyDescriptions1.getOrCreate(1).setPropertyName("prop3");
    importPropertyDescriptions1.getOrCreate(2).setPropertyName("prop4");
    rawUploadRdfSaver.addPropertyDescriptions(inputCol2, importPropertyDescriptions1);
    rawUploadRdfSaver.addEntity(inputCol2, ImmutableMap.of("prop3", "value1", "prop4", "val2"));
    rawUploadRdfSaver.addEntity(inputCol2, ImmutableMap.of("prop3", "entVal1", "prop4", "entVal2"));
    rdfSerializer.close();
    RdfDataSource rdfDataSource = new RdfDataSource(rmlDataSourceStore, inputCol1, new JexlRowFactory(ImmutableMap.of(), new HashMapBasedJoinHandler()));
    RdfDataSource rdfDataSource2 = new RdfDataSource(rmlDataSourceStore, inputCol2, new JexlRowFactory(ImmutableMap.of(), new HashMapBasedJoinHandler()));
    final List<String> collection1;
    final List<String> collection2;
    try (Stream<Row> stream = rdfDataSource.getRows(new ThrowingErrorHandler())) {
        collection1 = stream.map(x -> x.getRawValue("propName1") + ":" + x.getRawValue("propName2")).collect(toList());
    }
    try (Stream<Row> stream = rdfDataSource2.getRows(new ThrowingErrorHandler())) {
        collection2 = stream.map(x -> x.getRawValue("prop3") + ":" + x.getRawValue("prop4")).collect(toList());
    }
    assertThat(collection1, contains("value1:val2", "entVal1:entVal2"));
    assertThat(collection2, contains("value1:val2", "entVal1:entVal2"));
    dbCreator.close();
}
Also used : RawUploadRdfSaver(nl.knaw.huygens.timbuctoo.v5.bulkupload.RawUploadRdfSaver) ImportPropertyDescriptions(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ImportPropertyDescriptions) StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler) RmlDataSourceStore(nl.knaw.huygens.timbuctoo.v5.datastores.rmldatasource.RmlDataSourceStore) BdbNonPersistentEnvironmentCreator(nl.knaw.huygens.timbuctoo.v5.dropwizard.BdbNonPersistentEnvironmentCreator) RdfSerializer(nl.knaw.huygens.timbuctoo.v5.rdfio.RdfSerializer) JexlRowFactory(nl.knaw.huygens.timbuctoo.rml.datasource.jexl.JexlRowFactory) LogList(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) HashMapBasedJoinHandler(nl.knaw.huygens.timbuctoo.rml.datasource.joinhandlers.HashMapBasedJoinHandler) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) ThrowingErrorHandler(nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler) Row(nl.knaw.huygens.timbuctoo.rml.Row) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) RdfDataSource(nl.knaw.huygens.timbuctoo.v5.rml.RdfDataSource) Test(org.junit.Test)

Example 3 with BasicDataSetMetaData

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData in project timbuctoo by HuygensING.

the class FileSystemDataStorage method loadDataSetMetaData.

@Override
public Map<String, Set<DataSetMetaData>> loadDataSetMetaData() throws IOException {
    Map<String, Set<DataSetMetaData>> metaDataSet = Maps.newHashMap();
    File[] directories = new File(dataSetMetadataLocation).listFiles(File::isDirectory);
    for (int i = 0; i < directories.length; i++) {
        String dirName = directories[i].toString();
        String currentOwnerId = dirName.substring(dirName.lastIndexOf("/") + 1, dirName.length());
        Set<DataSetMetaData> tempMetaDataSet = new HashSet<>();
        try (Stream<Path> fileStream = Files.walk(directories[i].toPath())) {
            Set<Path> paths = fileStream.filter(current -> Files.isDirectory(current)).collect(Collectors.toSet());
            for (Path path : paths) {
                File tempFile = new File(path.toString() + "/metaData.json");
                if (tempFile.exists()) {
                    JsonFileBackedData<BasicDataSetMetaData> metaDataFromFile = null;
                    metaDataFromFile = JsonFileBackedData.getOrCreate(tempFile, null, new TypeReference<BasicDataSetMetaData>() {
                    });
                    tempMetaDataSet.add(metaDataFromFile.getData());
                }
            }
        }
        metaDataSet.put(currentOwnerId, tempMetaDataSet);
    }
    return metaDataSet;
}
Also used : Path(java.nio.file.Path) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) DataSetConfiguration(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetConfiguration) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) File(java.io.File) HashSet(java.util.HashSet) DataStorage(nl.knaw.huygens.timbuctoo.v5.datastorage.DataStorage) Stream(java.util.stream.Stream) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) Map(java.util.Map) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) RdfIoFactory(nl.knaw.huygens.timbuctoo.v5.rdfio.RdfIoFactory) FileHelper(nl.knaw.huygens.timbuctoo.v5.filehelper.FileHelper) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) DataSetStorage(nl.knaw.huygens.timbuctoo.v5.datastorage.DataSetStorage) JsonFileBackedData(nl.knaw.huygens.timbuctoo.v5.jsonfilebackeddata.JsonFileBackedData) Set(java.util.Set) HashSet(java.util.HashSet) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) File(java.io.File) HashSet(java.util.HashSet)

Example 4 with BasicDataSetMetaData

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData in project timbuctoo by HuygensING.

the class DataSetRepository method createDataSet.

public DataSet createDataSet(User user, String dataSetId) throws DataStoreCreationException, IllegalDataSetNameException {
    // The ownerId might not be valid (i.e. a safe string). We make it safe here:
    // dataSetId is under the control of the user so we simply throw if it's not valid
    String ownerPrefix = "u" + user.getPersistentId();
    final String baseUri = rdfIdHelper.dataSetBaseUri(ownerPrefix, dataSetId);
    String uriPrefix;
    if (!baseUri.endsWith("/") && !baseUri.endsWith("#") && !baseUri.endsWith("?")) {
        // #boo&foo=bar
        if (baseUri.contains("#") || baseUri.contains("?")) {
            if (baseUri.endsWith("&")) {
                uriPrefix = baseUri;
            } else {
                uriPrefix = baseUri + "&";
            }
        } else {
            uriPrefix = baseUri + "/";
        }
    } else {
        uriPrefix = baseUri;
    }
    final DataSetMetaData dataSet = new BasicDataSetMetaData(ownerPrefix, dataSetId, baseUri, uriPrefix, false, publicByDefault);
    try {
        dataStorage.getDataSetStorage(ownerPrefix, dataSetId).saveMetaData(dataSet);
    } catch (DataStorageSaveException e) {
        throw new DataStoreCreationException(e);
    }
    synchronized (dataSetMap) {
        Map<String, DataSet> userDataSets = dataSetMap.computeIfAbsent(ownerPrefix, key -> new HashMap<>());
        if (!userDataSets.containsKey(dataSetId)) {
            try {
                permissionFetcher.initializeOwnerAuthorization(user, dataSet.getOwnerId(), dataSet.getDataSetId());
                userDataSets.put(dataSetId, dataSet(dataSet, executorService, rdfBaseUri, dataStoreFactory, () -> onUpdated.accept(dataSet.getCombinedId()), dataStorage.getDataSetStorage(ownerPrefix, dataSetId)));
            } catch (PermissionFetchingException | AuthorizationCreationException | IOException e) {
                throw new DataStoreCreationException(e);
            }
        }
        return userDataSets.get(dataSetId);
    }
}
Also used : DataStorageSaveException(nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) IOException(java.io.IOException) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) AuthorizationCreationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)

Example 5 with BasicDataSetMetaData

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData in project timbuctoo by HuygensING.

the class RawUploadRdfSaverTest method setUp.

@Before
public void setUp() throws Exception {
    rdfSerializer = mock(RdfSerializer.class);
    dataSetMetadata = new BasicDataSetMetaData("userid", "dataset", "http://timbuctoo.huygens.knaw.nl/v5/datasets/userid/dataset", "http://example.org/prefix/", false, false);
    instance = instanceWithRdfSerializer(rdfSerializer, dataSetMetadata);
}
Also used : BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) RdfSerializer(nl.knaw.huygens.timbuctoo.v5.rdfio.RdfSerializer) Before(org.junit.Before)

Aggregations

BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)8 Test (org.junit.Test)5 Response (javax.ws.rs.core.Response)4 UserValidator (nl.knaw.huygens.timbuctoo.v5.security.UserValidator)4 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)3 PermissionFetcher (nl.knaw.huygens.timbuctoo.v5.security.PermissionFetcher)3 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)3 IOException (java.io.IOException)2 RdfSerializer (nl.knaw.huygens.timbuctoo.v5.rdfio.RdfSerializer)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1