Search in sources :

Example 1 with JsonFileBackedData

use of nl.knaw.huygens.timbuctoo.v5.jsonfilebackeddata.JsonFileBackedData 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)

Aggregations

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 IOException (java.io.IOException)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 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 DataSetConfiguration (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetConfiguration)1 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)1 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)1 DataSetStorage (nl.knaw.huygens.timbuctoo.v5.datastorage.DataSetStorage)1 DataStorage (nl.knaw.huygens.timbuctoo.v5.datastorage.DataStorage)1 FileHelper (nl.knaw.huygens.timbuctoo.v5.filehelper.FileHelper)1