diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 18e717bba0..a4ce79c484 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -81,6 +81,7 @@ public abstract class BaseAPI protected static final String ACTIONS_API = "{0}actionQueue"; protected static final String RM_ACTIONS_API = "{0}rma/actions/ExecutionQueue"; protected static final String RM_SITE_ID = "rm"; + protected static final String SHARE_ACTION_API = "{0}internal/shared/share/workspace/SpacesStore/{1}"; @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; @@ -426,6 +427,7 @@ public abstract class BaseAPI if (responseBody != null && responseBody.has(EXCEPTION_KEY)) { LOGGER.error("Request failed: " + responseBody.getString(EXCEPTION_KEY)); + returnValues = responseBody; } break; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java index 126829a099..deb439d9c8 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java @@ -26,8 +26,10 @@ */ package org.alfresco.rest.v0; +import java.text.MessageFormat; import java.util.Map; +import javafx.util.Pair; import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.dataprep.ContentService; import org.alfresco.rest.core.v0.BaseAPI; @@ -53,6 +55,8 @@ public class RecordsAPI extends BaseAPI private static final String CREATE_NON_ELECTRONIC_RECORD_API = "{0}type/rma:nonElectronicDocument/formprocessor"; + + @Autowired private ContentService contentService; @@ -288,4 +292,31 @@ public class RecordsAPI extends BaseAPI return ""; } + + /** + * Share a document + * + * @param user the user sharing the file + * @param password the user's password + * @param nodeId the node id of the file + * @return {@link Pair}. on success will be true and the shareId. + * on failure will be false and the response status code. + */ + public Pair shareDocument(String user, String password, String nodeId) throws JSONException + { + JSONObject response = doPostRequest(user, password, null, + MessageFormat.format(SHARE_ACTION_API, "{0}", nodeId)); + try + { + if (response.has("sharedId")) + { + return new Pair<>(true, response.getString("sharedId")); + } + } catch (JSONException e) + { + LOGGER.info("Unable to extract response parameter", e); + } + return new Pair<>(false, String.valueOf(response.getJSONObject("status").getInt("code"))); + } + }