Search in sources :

Example 31 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class PendingWorkflowInvocation method reCreateContext.

public WorkflowContext reCreateContext(RoleAssigneeServiceBean roleAssignees) {
    DataverseRequest aRequest = new DataverseRequest((User) roleAssignees.getRoleAssignee(userId), IpAddress.valueOf(ipAddress));
    final WorkflowContext workflowContext = new WorkflowContext(aRequest, dataset, nextVersionNumber, nextMinorVersionNumber, WorkflowContext.TriggerType.values()[typeOrdinal], doiProvider);
    workflowContext.setInvocationId(invocationId);
    return workflowContext;
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest)

Example 32 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class CreateSavedSearchCommand method execute.

@Override
public SavedSearch execute(CommandContext ctxt) throws CommandException {
    String query = savedSearchToCreate.getQuery();
    if (query == null) {
        /**
         * @todo This probably shouldn't be the default. We are disallowing
         * wildcard searches. Go fix the DataversePage and make sure the
         * query is set.
         */
        String wildcardSearch = "*";
        savedSearchToCreate.setQuery(wildcardSearch);
    }
    SavedSearch persistedSavedSearch = ctxt.savedSearches().save(savedSearchToCreate);
    if (persistedSavedSearch != null) {
        try {
            DataverseRequest dataverseRequest = new DataverseRequest(savedSearchToCreate.getCreator(), SavedSearchServiceBean.getHttpServletRequest());
            JsonObjectBuilder result = ctxt.savedSearches().makeLinksForSingleSavedSearch(dataverseRequest, persistedSavedSearch, true);
            logger.log(Level.INFO, "result from attempt to make links from saved search: {0}", result.build().toString());
        } catch (SearchException ex) {
            logger.info(ex.getLocalizedMessage());
        }
        return persistedSavedSearch;
    } else {
        return null;
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch) SearchException(edu.harvard.iq.dataverse.search.SearchException) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 33 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest 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 34 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class Files method restrictFileInDataset.

/**
 * Restrict or Unrestrict an Existing File
 * @author sarahferry
 *
 * @param fileToRestrictId
 * @param restrictStr
 * @return
 */
@PUT
@Path("{id}/restrict")
public Response restrictFileInDataset(@PathParam("id") Long fileToRestrictId, String restrictStr) {
    // create request
    DataverseRequest dataverseRequest = null;
    // get the datafile
    DataFile dataFile = fileService.find(fileToRestrictId);
    if (dataFile == null) {
        return error(BAD_REQUEST, "Could not find datafile with id " + fileToRestrictId);
    }
    boolean restrict = Boolean.valueOf(restrictStr);
    try {
        dataverseRequest = createDataverseRequest(findUserOrDie());
    } catch (WrappedResponse wr) {
        return error(BAD_REQUEST, "Couldn't find user to execute command: " + wr.getLocalizedMessage());
    }
    // try to restrict the datafile
    try {
        engineSvc.submit(new RestrictFileCommand(dataFile, dataverseRequest, restrict));
    } catch (CommandException ex) {
        return error(BAD_REQUEST, "Problem trying to update restriction status on " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
    }
    // update the dataset
    try {
        engineSvc.submit(new UpdateDatasetCommand(dataFile.getOwner(), dataverseRequest));
    } catch (CommandException ex) {
        return error(BAD_REQUEST, "Problem saving datafile " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
    }
    String text = restrict ? "restricted." : "unrestricted.";
    return ok("File " + dataFile.getDisplayName() + " " + text);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DataFile(edu.harvard.iq.dataverse.DataFile) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 35 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class Files method getMapLayerMetadatas.

// end: replaceFileInDataset
@DELETE
@Path("{id}/map")
public Response getMapLayerMetadatas(@PathParam("id") Long idSupplied) {
    DataverseRequest dataverseRequest = null;
    try {
        dataverseRequest = createDataverseRequest(findUserOrDie());
    } catch (WrappedResponse wr) {
        return error(BAD_REQUEST, "Couldn't find user to execute command: " + wr.getLocalizedMessage());
    }
    DataFile dataFile = fileService.find(idSupplied);
    try {
        boolean deleted = engineSvc.submit(new DeleteMapLayerMetadataCommand(dataverseRequest, dataFile));
        if (deleted) {
            return ok("Map deleted from file id " + dataFile.getId());
        } else {
            return error(BAD_REQUEST, "Could not delete map from file id " + dataFile.getId());
        }
    } catch (CommandException ex) {
        return error(BAD_REQUEST, "Problem trying to delete map from file id " + dataFile.getId() + ": " + ex.getLocalizedMessage());
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DataFile(edu.harvard.iq.dataverse.DataFile) DeleteMapLayerMetadataCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteMapLayerMetadataCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)57 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)22 Dataverse (edu.harvard.iq.dataverse.Dataverse)21 Test (org.junit.Test)18 Dataset (edu.harvard.iq.dataverse.Dataset)15 Path (javax.ws.rs.Path)14 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)13 SwordError (org.swordapp.server.SwordError)10 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)6 IOException (java.io.IOException)6 POST (javax.ws.rs.POST)6 DataFile (edu.harvard.iq.dataverse.DataFile)5 User (edu.harvard.iq.dataverse.authorization.users.User)5 HarvestingClient (edu.harvard.iq.dataverse.harvest.client.HarvestingClient)5 JsonObject (javax.json.JsonObject)5 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 DepositReceipt (org.swordapp.server.DepositReceipt)5 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)4