diff --git a/src/main/java/edu/harvard/iq/dataverse/datacapturemodule/DataCaptureModuleServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/datacapturemodule/DataCaptureModuleServiceBean.java index 2acf60cc762..3ae6ed2121f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/datacapturemodule/DataCaptureModuleServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/datacapturemodule/DataCaptureModuleServiceBean.java @@ -2,17 +2,17 @@ import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; import java.util.logging.Logger; -import javax.json.Json; -import javax.json.JsonObjectBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.Unirest; +import edu.harvard.iq.dataverse.Dataset; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; import static edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key.DataCaptureModuleUrl; import java.io.Serializable; import javax.ejb.EJB; import javax.ejb.Stateless; import javax.inject.Named; +import javax.json.JsonObjectBuilder; @Stateless @Named @@ -29,26 +29,16 @@ public class DataCaptureModuleServiceBean implements Serializable { * @throws Exception Throws an exception if Data Capture Module URL hasn't * been configured or if the POST failed. */ - public HttpResponse requestRsyncScriptCreation(AuthenticatedUser user) throws Exception { - /** - * @todo Move this to a "util" class. - * - * @todo Send user id instead of "userIdentifier" ... may need to add - * more lookups by user database id to the "admin" API. - * - * @todo pass dataset id - */ - JsonObjectBuilder jsonObject = Json.createObjectBuilder(); - jsonObject.add("userIdentifier", user.getAuthenticatedUserLookup().getPersistentUserId()); - jsonObject.add("uid", user.getAuthenticatedUserLookup().getPersistentUserId()); - String json = jsonObject.build().toString(); + public HttpResponse requestRsyncScriptCreation(AuthenticatedUser user, Dataset dataset, JsonObjectBuilder jab) throws Exception { String dcmBaseUrl = settingsService.getValueForKey(DataCaptureModuleUrl); if (dcmBaseUrl == null) { throw new Exception("Problem POSTing JSON to Data Capture Module. The '" + DataCaptureModuleUrl + "' setting has not been configured."); } + String jsonString = jab.build().toString(); + logger.info("JSON to send to Data Capture Module: " + jsonString); try { HttpResponse jsonResponse = Unirest.post(dcmBaseUrl + "/ur.py") - .body(json) + .body(jsonString) .asJson(); return jsonResponse; } catch (Exception ex) { diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/RequestRsyncScriptCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/RequestRsyncScriptCommand.java index 06e4b2cf34a..99db76c6e99 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/RequestRsyncScriptCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/RequestRsyncScriptCommand.java @@ -14,6 +14,8 @@ import edu.harvard.iq.dataverse.authorization.users.User; import edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException; import java.util.logging.Logger; +import javax.json.Json; +import javax.json.JsonObjectBuilder; @RequiredPermissions(Permission.AddDataset) public class RequestRsyncScriptCommand extends AbstractVoidCommand { @@ -46,14 +48,18 @@ protected void executeImpl(CommandContext ctxt) throws CommandException { * * @todo make sure the error is logged to the actionlogrecord */ + JsonObjectBuilder jab = Json.createObjectBuilder(); + // The general rule should be to always pass the user id and dataset id to the DCM. + jab.add("userId", au.getId()); + jab.add("datasetId", dataset.getId()); try { - response = ctxt.dataCaptureModule().requestRsyncScriptCreation(au); + response = ctxt.dataCaptureModule().requestRsyncScriptCreation(au, dataset, jab); } catch (Exception ex) { throw new CommandException("Problem retrieving rsync script from Data Capture Module: " + ex.getLocalizedMessage(), this); } int statusCode = response.getStatus(); if (statusCode != 200) { - logger.info("Problem retrieving rsync script from Data Capture Module. Status code was: " + statusCode); + logger.info("Problem retrieving rsync script from Data Capture Module. Status code was " + statusCode + " and body was \'" + response.getBody() + "\'."); } String script = response.getBody().getObject().getString("script"); if (script == null || script.isEmpty()) {