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;
}
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");
}
}
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;
}
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;
}
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;
}
Aggregations