Search in sources :

Example 86 with Dataset

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

the class Datasets method moveDataset.

@POST
@Path("{id}/move/{targetDataverseAlias}")
public Response moveDataset(@PathParam("id") String id, @PathParam("targetDataverseAlias") String targetDataverseAlias, @QueryParam("forceMove") Boolean force) {
    try {
        System.out.print("force: " + force);
        User u = findUserOrDie();
        Dataset ds = findDatasetOrDie(id);
        Dataverse target = dataverseService.findByAlias(targetDataverseAlias);
        if (target == null) {
            return error(Response.Status.BAD_REQUEST, "Target Dataverse not found.");
        }
        // Command requires Super user - it will be tested by the command
        execCommand(new MoveDatasetCommand(createDataverseRequest(u), ds, target, force));
        return ok("Dataset moved successfully");
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) Dataset(edu.harvard.iq.dataverse.Dataset) MoveDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.MoveDatasetCommand) Dataverse(edu.harvard.iq.dataverse.Dataverse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 87 with Dataset

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

the class Datasets method getDatasetThumbnailCandidates.

@GET
@Path("{id}/thumbnail/candidates")
public Response getDatasetThumbnailCandidates(@PathParam("id") String idSupplied) {
    try {
        Dataset dataset = findDatasetOrDie(idSupplied);
        boolean canUpdateThumbnail = false;
        try {
            canUpdateThumbnail = permissionSvc.requestOn(createDataverseRequest(findUserOrDie()), dataset).canIssue(UpdateDatasetThumbnailCommand.class);
        } catch (WrappedResponse ex) {
            logger.info("Exception thrown while trying to figure out permissions while getting thumbnail for dataset id " + dataset.getId() + ": " + ex.getLocalizedMessage());
        }
        if (!canUpdateThumbnail) {
            return error(Response.Status.FORBIDDEN, "You are not permitted to list dataset thumbnail candidates.");
        }
        JsonArrayBuilder data = Json.createArrayBuilder();
        boolean considerDatasetLogoAsCandidate = true;
        for (DatasetThumbnail datasetThumbnail : DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate)) {
            JsonObjectBuilder candidate = Json.createObjectBuilder();
            String base64image = datasetThumbnail.getBase64image();
            if (base64image != null) {
                logger.fine("found a candidate!");
                candidate.add("base64image", base64image);
            }
            DataFile dataFile = datasetThumbnail.getDataFile();
            if (dataFile != null) {
                candidate.add("dataFileId", dataFile.getId());
            }
            data.add(candidate);
        }
        return ok(data);
    } catch (WrappedResponse ex) {
        return error(Response.Status.NOT_FOUND, "Could not find dataset based on id supplied: " + idSupplied + ".");
    }
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) Dataset(edu.harvard.iq.dataverse.Dataset) UpdateDatasetThumbnailCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 88 with Dataset

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

the class Datasets method updateDraftVersion.

@PUT
@Path("{id}/versions/{versionId}")
public Response updateDraftVersion(String jsonBody, @PathParam("id") String id, @PathParam("versionId") String versionId) {
    if (!":draft".equals(versionId)) {
        return error(Response.Status.BAD_REQUEST, "Only the :draft version can be updated");
    }
    try (StringReader rdr = new StringReader(jsonBody)) {
        DataverseRequest req = createDataverseRequest(findUserOrDie());
        Dataset ds = findDatasetOrDie(id);
        JsonObject json = Json.createReader(rdr).readObject();
        DatasetVersion incomingVersion = jsonParser().parseDatasetVersion(json);
        // clear possibly stale fields from the incoming dataset version.
        // creation and modification dates are updated by the commands.
        incomingVersion.setId(null);
        incomingVersion.setVersionNumber(null);
        incomingVersion.setMinorVersionNumber(null);
        incomingVersion.setVersionState(DatasetVersion.VersionState.DRAFT);
        incomingVersion.setDataset(ds);
        incomingVersion.setCreateTime(null);
        incomingVersion.setLastUpdateTime(null);
        boolean updateDraft = ds.getLatestVersion().isDraft();
        DatasetVersion managedVersion = execCommand(updateDraft ? new UpdateDatasetVersionCommand(req, incomingVersion) : new CreateDatasetVersionCommand(req, ds, incomingVersion));
        return ok(json(managedVersion));
    } catch (JsonParseException ex) {
        logger.log(Level.SEVERE, "Semantic error parsing dataset version Json: " + ex.getMessage(), ex);
        return error(Response.Status.BAD_REQUEST, "Error parsing dataset version: " + ex.getMessage());
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) CreateDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetVersionCommand) Dataset(edu.harvard.iq.dataverse.Dataset) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) UpdateDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 89 with Dataset

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

the class Datasets method publishDataset.

@POST
@Path("{id}/actions/:publish")
public Response publishDataset(@PathParam("id") String id, @QueryParam("type") String type) {
    try {
        if (type == null) {
            return error(Response.Status.BAD_REQUEST, "Missing 'type' parameter (either 'major' or 'minor').");
        }
        type = type.toLowerCase();
        boolean isMinor;
        switch(type) {
            case "minor":
                isMinor = true;
                break;
            case "major":
                isMinor = false;
                break;
            default:
                return error(Response.Status.BAD_REQUEST, "Illegal 'type' parameter value '" + type + "'. It needs to be either 'major' or 'minor'.");
        }
        Dataset ds = findDatasetOrDie(id);
        PublishDatasetResult res = execCommand(new PublishDatasetCommand(ds, createDataverseRequest(findAuthenticatedUserOrDie()), isMinor));
        return res.isCompleted() ? ok(json(res.getDataset())) : accepted(json(res.getDataset()));
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PublishDatasetResult(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetResult) PublishDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 90 with Dataset

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

the class Datasets method getRsync.

@GET
@Path("{identifier}/dataCaptureModule/rsync")
public Response getRsync(@PathParam("identifier") String id) {
    // TODO - does it make sense to switch this to dataset identifier for consistency with the rest of the DCM APIs?
    if (!DataCaptureModuleUtil.rsyncSupportEnabled(settingsSvc.getValueForKey(SettingsServiceBean.Key.UploadMethods))) {
        return error(Response.Status.METHOD_NOT_ALLOWED, SettingsServiceBean.Key.UploadMethods + " does not contain " + SystemConfig.FileUploadMethods.RSYNC + ".");
    }
    Dataset dataset = null;
    try {
        dataset = findDatasetOrDie(id);
        ScriptRequestResponse scriptRequestResponse = execCommand(new RequestRsyncScriptCommand(createDataverseRequest(findUserOrDie()), dataset));
        return ok(scriptRequestResponse.getScript(), MediaType.valueOf(MediaType.TEXT_PLAIN));
    } catch (WrappedResponse wr) {
        return wr.getResponse();
    } catch (EJBException ex) {
        return error(Response.Status.INTERNAL_SERVER_ERROR, "Something went wrong attempting to download rsync script: " + EjbUtil.ejbExceptionToString(ex));
    }
}
Also used : ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) Dataset(edu.harvard.iq.dataverse.Dataset) EJBException(javax.ejb.EJBException) RequestRsyncScriptCommand(edu.harvard.iq.dataverse.engine.command.impl.RequestRsyncScriptCommand) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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