Search in sources :

Example 16 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class FileAccessIO method getDatasetDirectory.

private String getDatasetDirectory() throws IOException {
    if (dvObject == null) {
        throw new IOException("No DvObject defined in the Data Access Object");
    }
    Path datasetDirectoryPath = null;
    if (dvObject instanceof Dataset) {
        datasetDirectoryPath = this.getDataset().getFileSystemDirectory();
    } else if (dvObject instanceof DataFile) {
        datasetDirectoryPath = this.getDataFile().getOwner().getFileSystemDirectory();
    } else if (dvObject instanceof Dataverse) {
        throw new IOException("FileAccessIO: Dataverses are not a supported dvObject");
    }
    if (datasetDirectoryPath == null) {
        throw new IOException("Could not determine the filesystem directory of the parent dataset.");
    }
    String datasetDirectory = datasetDirectoryPath.toString();
    if (dvObject.getStorageIdentifier() == null || dvObject.getStorageIdentifier().isEmpty()) {
        throw new IOException("Data Access: No local storage identifier defined for this datafile.");
    }
    return datasetDirectory;
}
Also used : Path(java.nio.file.Path) DataFile(edu.harvard.iq.dataverse.DataFile) Dataset(edu.harvard.iq.dataverse.Dataset) IOException(java.io.IOException) Dataverse(edu.harvard.iq.dataverse.Dataverse)

Example 17 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class S3AccessIO method open.

@Override
public void open(DataAccessOption... options) throws IOException {
    if (s3 == null) {
        throw new IOException("ERROR: s3 not initialised. ");
    }
    if (bucketName == null || !s3.doesBucketExist(bucketName)) {
        throw new IOException("ERROR: S3AccessIO - You must create and configure a bucket before creating datasets.");
    }
    DataAccessRequest req = this.getRequest();
    if (isWriteAccessRequested(options)) {
        isWriteAccess = true;
        isReadAccess = false;
    } else {
        isWriteAccess = false;
        isReadAccess = true;
    }
    if (dvObject instanceof DataFile) {
        String storageIdentifier = dvObject.getStorageIdentifier();
        DataFile dataFile = this.getDataFile();
        if (req != null && req.getParameter("noVarHeader") != null) {
            this.setNoVarHeader(true);
        }
        if (storageIdentifier == null || "".equals(storageIdentifier)) {
            throw new FileNotFoundException("Data Access: No local storage identifier defined for this datafile.");
        }
        if (isReadAccess) {
            key = getMainFileKey();
            S3Object s3object = s3.getObject(new GetObjectRequest(bucketName, key));
            InputStream in = s3object.getObjectContent();
            if (in == null) {
                throw new IOException("Cannot get Object" + key);
            }
            this.setInputStream(in);
            setChannel(Channels.newChannel(in));
            this.setSize(s3object.getObjectMetadata().getContentLength());
            if (dataFile.getContentType() != null && dataFile.getContentType().equals("text/tab-separated-values") && dataFile.isTabularData() && dataFile.getDataTable() != null && (!this.noVarHeader())) {
                List<DataVariable> datavariables = dataFile.getDataTable().getDataVariables();
                String varHeaderLine = generateVariableHeader(datavariables);
                this.setVarHeader(varHeaderLine);
            }
        } else if (isWriteAccess) {
            key = dataFile.getOwner().getAuthority() + "/" + this.getDataFile().getOwner().getIdentifier();
            if (storageIdentifier.startsWith(S3_IDENTIFIER_PREFIX + "://")) {
                key += "/" + storageIdentifier.substring(storageIdentifier.lastIndexOf(":") + 1);
            } else {
                key += "/" + storageIdentifier;
                dvObject.setStorageIdentifier(S3_IDENTIFIER_PREFIX + "://" + bucketName + ":" + storageIdentifier);
            }
        }
        this.setMimeType(dataFile.getContentType());
        try {
            this.setFileName(dataFile.getFileMetadata().getLabel());
        } catch (Exception ex) {
            this.setFileName("unknown");
        }
    } else if (dvObject instanceof Dataset) {
        Dataset dataset = this.getDataset();
        key = dataset.getAuthority() + "/" + dataset.getIdentifier();
        dataset.setStorageIdentifier(S3_IDENTIFIER_PREFIX + "://" + key);
    } else if (dvObject instanceof Dataverse) {
        throw new IOException("Data Access: Invalid DvObject type : Dataverse");
    } else {
        throw new IOException("Data Access: Invalid DvObject type");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Dataset(edu.harvard.iq.dataverse.Dataset) FileNotFoundException(java.io.FileNotFoundException) DataVariable(edu.harvard.iq.dataverse.datavariable.DataVariable) IOException(java.io.IOException) Dataverse(edu.harvard.iq.dataverse.Dataverse) MultiObjectDeleteException(com.amazonaws.services.s3.model.MultiObjectDeleteException) FileNotFoundException(java.io.FileNotFoundException) AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException) SdkClientException(com.amazonaws.SdkClientException) DataFile(edu.harvard.iq.dataverse.DataFile) S3Object(com.amazonaws.services.s3.model.S3Object) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 18 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class XlistRecordsHandler method createRecord.

private Record createRecord(OAICompiledRequest parameters, Item item) throws BadArgumentException, CannotDisseminateRecordException, OAIException, NoMetadataFormatsException, CannotDisseminateFormatException {
    MetadataFormat format = getContext().formatForPrefix(parameters.getMetadataPrefix());
    Header header = new Header();
    Dataset dataset = ((Xitem) item).getDataset();
    Xrecord xrecord = new Xrecord().withFormatName(parameters.getMetadataPrefix()).withDataset(dataset);
    header.withIdentifier(item.getIdentifier());
    ItemHelper itemHelperWrap = new ItemHelper(item);
    header.withDatestamp(item.getDatestamp());
    for (Set set : itemHelperWrap.getSets(getContext(), getRepository().getFilterResolver())) header.withSetSpec(set.getSpec());
    if (item.isDeleted())
        header.withStatus(Header.Status.DELETED);
    xrecord.withHeader(header);
    xrecord.withMetadata(item.getMetadata());
    return xrecord;
}
Also used : ItemHelper(com.lyncode.xoai.dataprovider.handlers.helpers.ItemHelper) MetadataFormat(com.lyncode.xoai.dataprovider.model.MetadataFormat) Set(com.lyncode.xoai.dataprovider.model.Set) Dataset(edu.harvard.iq.dataverse.Dataset)

Example 19 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class PrivateUrlUtil method getDraftDatasetVersionFromRoleAssignment.

/**
 * @return DatasetVersion if a draft or null.
 *
 * @todo If there is a use case for this outside the context of Private URL,
 * move this method to somewhere more centralized.
 */
public static DatasetVersion getDraftDatasetVersionFromRoleAssignment(RoleAssignment roleAssignment) {
    if (roleAssignment == null) {
        return null;
    }
    Dataset dataset = getDatasetFromRoleAssignment(roleAssignment);
    if (dataset != null) {
        DatasetVersion latestVersion = dataset.getLatestVersion();
        if (latestVersion.isDraft()) {
            return latestVersion;
        }
    }
    logger.fine("Couldn't find draft, returning null");
    return null;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion)

Example 20 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class Index method getContentInDatabaseButStaleInOrMissingFromSolr.

private JsonObjectBuilder getContentInDatabaseButStaleInOrMissingFromSolr() {
    List<Dataverse> stateOrMissingDataverses = indexService.findStaleOrMissingDataverses();
    List<Dataset> staleOrMissingDatasets = indexService.findStaleOrMissingDatasets();
    JsonArrayBuilder jsonStateOrMissingDataverses = Json.createArrayBuilder();
    for (Dataverse dataverse : stateOrMissingDataverses) {
        jsonStateOrMissingDataverses.add(dataverse.getId());
    }
    JsonArrayBuilder datasetsInDatabaseButNotSolr = Json.createArrayBuilder();
    for (Dataset dataset : staleOrMissingDatasets) {
        datasetsInDatabaseButNotSolr.add(dataset.getId());
    }
    JsonObjectBuilder contentInDatabaseButStaleInOrMissingFromSolr = Json.createObjectBuilder().add("dataverses", jsonStateOrMissingDataverses.build().size()).add("datasets", datasetsInDatabaseButNotSolr.build().size());
    return contentInDatabaseButStaleInOrMissingFromSolr;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Dataverse(edu.harvard.iq.dataverse.Dataverse)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)142 Test (org.junit.Test)53 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)44 DataFile (edu.harvard.iq.dataverse.DataFile)41 Dataverse (edu.harvard.iq.dataverse.Dataverse)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)27 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)22 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)17 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)17 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)16 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)16 Date (java.util.Date)16 JsonObjectBuilder (javax.json.JsonObjectBuilder)16 JsonObject (javax.json.JsonObject)15 DvObject (edu.harvard.iq.dataverse.DvObject)14 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)14 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)14