From ac9d5861674cc3a49e23169c3fd88c22bb7f73ea Mon Sep 17 00:00:00 2001 From: Tom Page Date: Mon, 6 Nov 2017 16:33:11 +0000 Subject: [PATCH 1/6] RM-5837 Add support for v0 copy-to API. --- .../org/alfresco/rest/core/v0/BaseAPI.java | 55 +++++++++++-- .../java/org/alfresco/rest/v0/CopyToAPI.java | 81 +++++++++++++++++++ 2 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java 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 1d2feb9848..ca03bc9143 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 @@ -80,6 +80,7 @@ public abstract class BaseAPI 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}"; + private static final String SLINGSHOT_PREFIX = "alfresco/s/slingshot/"; @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; @@ -352,12 +353,50 @@ public abstract class BaseAPI String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); - client.close(); + return doPostJsonRequest(adminUser, adminPassword, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); + } + /** + * Helper method for POST requests to slingshot. + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template + * @param urlTemplateParams zero or more parameters used with urlTemplate + */ + protected boolean doSlingshotPostJsonRequest(String adminUser, + String adminPassword, + JSONObject requestParams, + String urlTemplate, + String... urlTemplateParams) + { + AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); + return doPostJsonRequest(adminUser, adminPassword, client.getAlfrescoUrl() + SLINGSHOT_PREFIX, requestParams, urlTemplate, urlTemplateParams); + } + + /** + * Helper method for POST requests + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param urlStart the start of the URL (for example "alfresco/s/slingshot"). + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template + * @param urlTemplateParams zero or more parameters used with urlTemplate + */ + private boolean doPostJsonRequest(String adminUser, + String adminPassword, + String urlStart, + JSONObject requestParams, + String urlTemplate, + String... urlTemplateParams) + { + // Ensure the host is part of the request URL. + String requestUrl = MessageFormat.format( + urlTemplate, + urlStart, + urlTemplateParams); try { return doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); @@ -482,7 +521,11 @@ public abstract class BaseAPI ((HttpEntityEnclosingRequestBase) request).setEntity(new StringEntity(requestParams.toString())); } - return client.execute(adminUser, adminPassword, request).getStatusLine().getStatusCode() == HttpStatus.SC_OK; + LOGGER.info("Sending {} request to {}", requestType.getSimpleName(), requestUrl); + LOGGER.info("Request body: {}", requestParams); + HttpResponse httpResponse = client.execute(adminUser, adminPassword, request); + LOGGER.info("Response: {}", httpResponse.getStatusLine()); + return httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (UnsupportedEncodingException | URISyntaxException error1) { diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java new file mode 100644 index 0000000000..0ec3c49579 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java @@ -0,0 +1,81 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.v0; + +import java.text.MessageFormat; +import java.util.List; + +import org.alfresco.rest.core.v0.BaseAPI; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * The v0 REST API for copy-to (which supports multi-item copy). + * + * @author Tom Page + * @since 2.6 + */ +@Component +public class CopyToAPI extends BaseAPI +{ + /** Logger for the class. */ + private static final Logger LOGGER = LoggerFactory.getLogger(CopyToAPI.class); + /** The URI for the copy-to API. */ + private static final String COPY_TO_API = "{0}doclib/action/copy-to/node/{1}"; + + /** + * Copy a list of nodes to the target container. + * + * @param user The username of the user to use. + * @param password The password of the user. + * @param targetContainerPath The destination to copy the nodes to. This should be in the format + * "{site}/{container}/{path}", "{site}/{container}", "{store_type}/{store_id}/{id}/{path}", + * "{store_type}/{store_id}/{id}" or "{store_type}/{store_id}". + * @param nodeRefs The list of nodes to copy. + * @return true if the request was successful. + */ + public boolean copyTo(String user, String password, String targetContainerPath, List nodeRefs) + { + try + { + JSONObject requestParams = new JSONObject(); + requestParams.put("nodeRefs", new JSONArray(nodeRefs)); + + return doSlingshotPostJsonRequest(user, password, requestParams, + MessageFormat.format(COPY_TO_API, "{0}", targetContainerPath)); + } + catch (JSONException error) + { + LOGGER.error("Unable to extract response parameter", error); + } + return false; + } +} From 434676de32ab7998b5ed0e479216e85cd12c8d9e Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 7 Nov 2017 10:15:40 +0000 Subject: [PATCH 2/6] RM-5837 Refactor POST API calls to return HTTP response. By default throw an exception if the calls are not successful. This allows us to remove a huge number of assertion statements from REST API tests. Returning the response allows us to make more detailed assertions if we need to - for example checking exactly what the status code was. --- .../org/alfresco/rest/core/v0/BaseAPI.java | 28 ++- .../java/org/alfresco/rest/v0/CopyToAPI.java | 40 ++-- .../rest/v0/RMRolesAndActionsAPI.java | 98 ++++------ .../alfresco/rest/v0/RecordCategoriesAPI.java | 74 +++----- .../alfresco/rest/v0/RecordFoldersAPI.java | 9 +- .../java/org/alfresco/rest/v0/RecordsAPI.java | 171 ++++++++---------- .../java/org/alfresco/rest/v0/RulesAPI.java | 43 ++--- 7 files changed, 202 insertions(+), 261 deletions(-) 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 ca03bc9143..06674c99e1 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 @@ -26,6 +26,8 @@ */ package org.alfresco.rest.core.v0; +import static org.testng.AssertJUnit.assertEquals; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -342,18 +344,20 @@ public abstract class BaseAPI * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser + * @param expectFailure If false then an exception will be thrown if the POST is not successful. * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected boolean doPostJsonRequest(String adminUser, + protected HttpResponse doPostJsonRequest(String adminUser, String adminPassword, + boolean expectFailure, JSONObject requestParams, String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - return doPostJsonRequest(adminUser, adminPassword, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); + return doPostJsonRequest(adminUser, adminPassword, expectFailure, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); } /** @@ -361,18 +365,20 @@ public abstract class BaseAPI * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser + * @param expectFailure If false then an exception will be thrown if the POST is not successful. * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected boolean doSlingshotPostJsonRequest(String adminUser, + protected HttpResponse doSlingshotPostJsonRequest(String adminUser, String adminPassword, + boolean expectFailure, JSONObject requestParams, String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - return doPostJsonRequest(adminUser, adminPassword, client.getAlfrescoUrl() + SLINGSHOT_PREFIX, requestParams, urlTemplate, urlTemplateParams); + return doPostJsonRequest(adminUser, adminPassword, expectFailure, client.getAlfrescoUrl() + SLINGSHOT_PREFIX, requestParams, urlTemplate, urlTemplateParams); } /** @@ -380,13 +386,15 @@ public abstract class BaseAPI * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser + * @param expectFailure If false then an exception will be thrown if the POST is not successful. * @param urlStart the start of the URL (for example "alfresco/s/slingshot"). * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - private boolean doPostJsonRequest(String adminUser, + private HttpResponse doPostJsonRequest(String adminUser, String adminPassword, + boolean expectFailure, String urlStart, JSONObject requestParams, String urlTemplate, @@ -399,7 +407,9 @@ public abstract class BaseAPI urlTemplateParams); try { - return doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); + HttpResponse httpResponse = doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); + assertEquals("POST request was not successful.", httpResponse.getStatusLine().getStatusCode(), 200); + return httpResponse; } catch (InstantiationException | IllegalAccessException error) { @@ -501,7 +511,7 @@ public abstract class BaseAPI return returnValues; } - private boolean doRequestJson( + private HttpResponse doRequestJson( Class requestType, String requestUrl, String adminUser, @@ -525,7 +535,7 @@ public abstract class BaseAPI LOGGER.info("Request body: {}", requestParams); HttpResponse httpResponse = client.execute(adminUser, adminPassword, request); LOGGER.info("Response: {}", httpResponse.getStatusLine()); - return httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK; + return httpResponse; } catch (UnsupportedEncodingException | URISyntaxException error1) { @@ -540,7 +550,7 @@ public abstract class BaseAPI client.close(); } - return false; + return null; } /** diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java index 0ec3c49579..ecbfc006ce 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java @@ -30,8 +30,8 @@ import java.text.MessageFormat; import java.util.List; import org.alfresco.rest.core.v0.BaseAPI; +import org.apache.http.HttpResponse; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,22 +60,32 @@ public class CopyToAPI extends BaseAPI * "{site}/{container}/{path}", "{site}/{container}", "{store_type}/{store_id}/{id}/{path}", * "{store_type}/{store_id}/{id}" or "{store_type}/{store_id}". * @param nodeRefs The list of nodes to copy. - * @return true if the request was successful. + * @return The HTTP Response. + * @throws AssertionError If the API call didn't return a 200 response. */ - public boolean copyTo(String user, String password, String targetContainerPath, List nodeRefs) + public HttpResponse copyTo(String user, String password, String targetContainerPath, List nodeRefs) { - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("nodeRefs", new JSONArray(nodeRefs)); + return copyToAndGetResponse(user, password, false, targetContainerPath, nodeRefs); + } - return doSlingshotPostJsonRequest(user, password, requestParams, - MessageFormat.format(COPY_TO_API, "{0}", targetContainerPath)); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + /** + * Copy a list of nodes to the target container. + * + * @param user The username of the user to use. + * @param password The password of the user. + * @param expectFailure If false then an exception will be thrown if the POST is not successful. + * @param targetContainerPath The destination to copy the nodes to. This should be in the format + * "{site}/{container}/{path}", "{site}/{container}", "{store_type}/{store_id}/{id}/{path}", + * "{store_type}/{store_id}/{id}" or "{store_type}/{store_id}". + * @param nodeRefs The list of nodes to copy. + * @return The HTTP Response. + */ + public HttpResponse copyToAndGetResponse(String user, String password, boolean expectFailure, String targetContainerPath, List nodeRefs) + { + JSONObject requestParams = new JSONObject(); + requestParams.put("nodeRefs", new JSONArray(nodeRefs)); + + return doSlingshotPostJsonRequest(user, password, expectFailure, requestParams, + MessageFormat.format(COPY_TO_API, "{0}", targetContainerPath)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java index 32fead509e..9ff6069efe 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java @@ -27,6 +27,7 @@ package org.alfresco.rest.v0; import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON; +import static org.testng.AssertJUnit.assertNotNull; import java.io.IOException; import java.text.MessageFormat; @@ -206,9 +207,9 @@ public class RMRolesAndActionsAPI extends BaseAPI * @param user the user executing the action * @param password the user's password * @param contentName the content name - * @return true if the action completed successfully + * @return The HTTP response. */ - public boolean executeAction(String user, String password, String contentName, RM_ACTIONS rm_action) + public HttpResponse executeAction(String user, String password, String contentName, RM_ACTIONS rm_action) { return executeAction(user, password, contentName, rm_action, null); } @@ -220,32 +221,24 @@ public class RMRolesAndActionsAPI extends BaseAPI * @param password the user's password * @param contentName the record folder name * @param date the date to be updated - * @return true if the action completed successfully + * @return The HTTP response. */ - public boolean executeAction(String user, String password, String contentName, RM_ACTIONS action, ZonedDateTime date) + public HttpResponse executeAction(String user, String password, String contentName, RM_ACTIONS action, ZonedDateTime date) { String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, contentName); - try + JSONObject requestParams = new JSONObject(); + requestParams.put("name", action.getAction()); + requestParams.put("nodeRef", recNodeRef); + if (date != null) { - JSONObject requestParams = new JSONObject(); - requestParams.put("name", action.getAction()); - requestParams.put("nodeRef", recNodeRef); - if (date != null) - { - String thisMoment = date.format(DateTimeFormatter.ISO_INSTANT); - requestParams.put("params", new JSONObject() - .put("asOfDate", new JSONObject() - .put("iso8601", thisMoment) - ) - ); - } - return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); + String thisMoment = date.format(DateTimeFormatter.ISO_INSTANT); + requestParams.put("params", new JSONObject() + .put("asOfDate", new JSONObject() + .put("iso8601", thisMoment) + ) + ); } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); } /** @@ -288,37 +281,32 @@ public class RMRolesAndActionsAPI extends BaseAPI * @param holdName the hold name * @param reason hold reason * @param description hold description - * @return true if the hold creation has been successful + * @return The HTTP response (or null if no POST call was needed). */ - public boolean createHold(String user, String password, String holdName, String reason, String description) + public HttpResponse createHold(String user, String password, String holdName, String reason, String description) { // if the hold already exists don't try to create it again String holdsContainerPath = getFilePlanPath() + "/Holds"; - - CmisObject hold = getObjectByPath(user, password, holdsContainerPath + "/" + holdName); + String fullHoldPath = holdsContainerPath + "/" + holdName; + CmisObject hold = getObjectByPath(user, password, fullHoldPath); if (hold != null) { - return true; + return null; } // retrieve the Holds container nodeRef String parentNodeRef = getItemNodeRef(user, password, "/Holds"); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); - requestParams.put("prop_cm_name", holdName); - requestParams.put("prop_cm_description", description); - requestParams.put("prop_rma_holdReason", reason); + JSONObject requestParams = new JSONObject(); + requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); + requestParams.put("prop_cm_name", holdName); + requestParams.put("prop_cm_description", description); + requestParams.put("prop_rma_holdReason", reason); - boolean requestSucceeded = doPostJsonRequest(user, password, requestParams, CREATE_HOLDS_API); - return requestSucceeded && getObjectByPath(user, password, holdsContainerPath + "/" + holdName) != null; - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + // Make the POST request and throw an assertion error if it fails. + HttpResponse httpResponse = doPostJsonRequest(user, password, false, requestParams, CREATE_HOLDS_API); + assertNotNull("Expected object to have been created at " + fullHoldPath, + getObjectByPath(user, password, fullHoldPath)); + return httpResponse; } /** @@ -327,24 +315,16 @@ public class RMRolesAndActionsAPI extends BaseAPI * @param username the user updating the item * @param password the user's password * @param itemNodeRef the item noderef - * @return true if the update of the item properties has been successful + * @return The HTTP response. */ - public boolean updateMetadata(String username, String password, String itemNodeRef, Map properties) + public HttpResponse updateMetadata(String username, String password, String itemNodeRef, Map properties) { - try - { - JSONObject requestParams = new JSONObject(); - addPropertyToRequest(requestParams, "prop_cm_name", properties, RMProperty.NAME); - addPropertyToRequest(requestParams, "prop_cm_title", properties, RMProperty.TITLE); - addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION); - addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR); + JSONObject requestParams = new JSONObject(); + addPropertyToRequest(requestParams, "prop_cm_name", properties, RMProperty.NAME); + addPropertyToRequest(requestParams, "prop_cm_title", properties, RMProperty.TITLE); + addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION); + addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR); - return doPostJsonRequest(username, password, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(username, password, false, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java index 8d11c14b14..96e12a7744 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java @@ -31,7 +31,7 @@ import java.util.HashMap; import java.util.Map; import org.alfresco.rest.core.v0.BaseAPI; -import org.json.JSONException; +import org.apache.http.HttpResponse; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,24 +56,17 @@ public class RecordCategoriesAPI extends BaseAPI * @param user the user creating the disposition schedule * @param password the user's password * @param categoryName the category name to create the retention schedule for - * @return true if the creation completed successfully + * @return The HTTP Response. */ - public boolean createRetentionSchedule(String user, String password, String categoryName) + public HttpResponse createRetentionSchedule(String user, String password, String categoryName) { String catNodeRef = getNodeRefSpacesStore() + getItemNodeRef(user, password, "/" + categoryName); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("name", "createDispositionSchedule"); - requestParams.put("nodeRef", catNodeRef); + JSONObject requestParams = new JSONObject(); + requestParams.put("name", "createDispositionSchedule"); + requestParams.put("nodeRef", catNodeRef); - return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); - } catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); } /** @@ -82,24 +75,17 @@ public class RecordCategoriesAPI extends BaseAPI * @param user the user creating the disposition schedule * @param password the user's password * @param retentionNodeRef the retention nodeRef - * @return true if the creation completed successfully + * @return The HTTP Response. */ - public boolean setRetentionScheduleGeneralFields(String user, String password, String retentionNodeRef, Map retentionProperties, Boolean appliedToRecords) + public HttpResponse setRetentionScheduleGeneralFields(String user, String password, String retentionNodeRef, Map retentionProperties, Boolean appliedToRecords) { String dispRetentionNodeRef = NODE_PREFIX + retentionNodeRef; - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("prop_rma_dispositionAuthority", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_AUTHORITY)); - requestParams.put("prop_rma_dispositionInstructions", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS)); - requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString()); - return doPostJsonRequest(user, password, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); - } catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + JSONObject requestParams = new JSONObject(); + requestParams.put("prop_rma_dispositionAuthority", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_AUTHORITY)); + requestParams.put("prop_rma_dispositionInstructions", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS)); + requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString()); + return doPostJsonRequest(user, password, false, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); } /** @@ -108,30 +94,22 @@ public class RecordCategoriesAPI extends BaseAPI * @param user the user creating the disposition schedule * @param password the user's password * @param categoryName the category name to create the retention schedule for - * @return true if the creation completed successfully + * @return The HTTP Response. */ - public boolean addDispositionScheduleSteps(String user, String password, String categoryName, Map properties) + public HttpResponse addDispositionScheduleSteps(String user, String password, String categoryName, Map properties) { String catNodeRef = NODE_PREFIX + getItemNodeRef(user, password, "/" + categoryName); - { - try - { - JSONObject requestParams = new JSONObject(); - addPropertyToRequest(requestParams, "name", properties, RETENTION_SCHEDULE.NAME); - addPropertyToRequest(requestParams, "description", properties, RETENTION_SCHEDULE.DESCRIPTION); - addPropertyToRequest(requestParams, "period", properties, RETENTION_SCHEDULE.RETENTION_PERIOD); - addPropertyToRequest(requestParams, "ghostOnDestroy", properties, RETENTION_SCHEDULE.RETENTION_GHOST); - addPropertyToRequest(requestParams, "periodProperty", properties, RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY); - addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS); - addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT); - return doPostJsonRequest(user, password, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); - } catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; - } + JSONObject requestParams = new JSONObject(); + addPropertyToRequest(requestParams, "name", properties, RETENTION_SCHEDULE.NAME); + addPropertyToRequest(requestParams, "description", properties, RETENTION_SCHEDULE.DESCRIPTION); + addPropertyToRequest(requestParams, "period", properties, RETENTION_SCHEDULE.RETENTION_PERIOD); + addPropertyToRequest(requestParams, "ghostOnDestroy", properties, RETENTION_SCHEDULE.RETENTION_GHOST); + addPropertyToRequest(requestParams, "periodProperty", properties, RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY); + addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS); + addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT); + + return doPostJsonRequest(user, password, false, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); } /** diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java index c605fee395..776888b633 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java @@ -28,6 +28,7 @@ package org.alfresco.rest.v0; import org.alfresco.dataprep.ContentService; import org.alfresco.rest.core.v0.BaseAPI; +import org.apache.http.HttpResponse; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -55,9 +56,9 @@ public class RecordFoldersAPI extends BaseAPI * @param user the user closing the folder * @param password the user's password * @param recordFolder the record folder name - * @return true if the action completed successfully + * @return The HTTP Response (or null if the response could not be understood). */ - public boolean closeRecordFolder(String user, String password, String recordFolder) + public HttpResponse closeRecordFolder(String user, String password, String recordFolder) { String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordFolder); @@ -67,12 +68,12 @@ public class RecordFoldersAPI extends BaseAPI requestParams.put("name", "closeRecordFolder"); requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); } catch (JSONException error) { LOGGER.error("Unable to extract response parameter", error); } - return false; + return null; } } 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 ca51c60200..0801d3b08c 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 @@ -29,11 +29,11 @@ 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; import org.apache.chemistry.opencmis.client.api.CmisObject; +import org.apache.http.HttpResponse; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -41,6 +41,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javafx.util.Pair; + /** * Methods to make API requests using v0 API on records * @@ -65,25 +67,17 @@ public class RecordsAPI extends BaseAPI * @param password the user's password * @param siteID the site id in which the document exists * @param documentName the document name - * @return true if the action was successful + * @return The HTTP Response. */ - public boolean declareDocumentAsRecord(String user, String password, String siteID, String documentName) + public HttpResponse declareDocumentAsRecord(String user, String password, String siteID, String documentName) { String docNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, siteID, documentName); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("actionedUponNode", docNodeRef); - requestParams.put("actionDefinitionName", "create-record"); + JSONObject requestParams = new JSONObject(); + requestParams.put("actionedUponNode", docNodeRef); + requestParams.put("actionDefinitionName", "create-record"); - return doPostJsonRequest(user, password, requestParams, ACTIONS_API); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); } /** @@ -92,28 +86,19 @@ public class RecordsAPI extends BaseAPI * @param user the user declaring the document as record * @param password the user's password * @param recordName the record name - * @return true if the action completed successfully + * @return The HTTP Response. */ - public boolean completeRecord(String user, String password, String recordName) + public HttpResponse completeRecord(String user, String password, String recordName) { String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("name", "declareRecord"); - requestParams.put("nodeRef", recNodeRef); + JSONObject requestParams = new JSONObject(); + requestParams.put("name", "declareRecord"); + requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); } - /** * Reject the record given as parameter * @@ -121,28 +106,38 @@ public class RecordsAPI extends BaseAPI * @param password the user's password * @param recordName the record name * @param reason reject reason - * @return true if the action completed successfully + * @return The HTTP Response. + * @throws AssertionError If the POST call is not successful. */ - public boolean rejectRecord(String user, String password, String recordName, String reason) + public HttpResponse rejectRecord(String user, String password, String recordName, String reason) + { + return rejectRecordAndGetResponse(user, password, false, recordName, reason); + } + + /** + * Reject the record given as parameter + * + * @param user the user declaring the document as record + * @param password the user's password + * @param expectFailure If false then throws an exception if the POST call fails. + * @param recordName the record name + * @param reason reject reason + * @return The HTTP Response. + * @throws AssertionError If expectFailure is false and the POST call is not successful. + */ + public HttpResponse rejectRecordAndGetResponse(String user, String password, boolean expectFailure, String recordName, String reason) { String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("name", "reject"); - requestParams.put("nodeRef", recNodeRef); - requestParams.put("params",new JSONObject() - .put("reason",reason)); + JSONObject requestParams = new JSONObject(); + requestParams.put("name", "reject"); + requestParams.put("nodeRef", recNodeRef); + requestParams.put("params",new JSONObject() + .put("reason",reason)); - return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, expectFailure, requestParams, RM_ACTIONS_API); } + /** * Declare document version as record * @@ -150,29 +145,25 @@ public class RecordsAPI extends BaseAPI * @param password the user's password * @param siteID the site id in which the document exists * @param documentName the document name - * @return true if the action was successful + * @return The HTTP Response. */ - public boolean declareDocumentVersionAsRecord(String user, String password, String siteID, String documentName) + public HttpResponse declareDocumentVersionAsRecord(String user, String password, String siteID, String documentName) { String docNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, siteID, documentName); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("actionedUponNode", docNodeRef); - requestParams.put("actionDefinitionName", "declare-as-version-record"); + JSONObject requestParams = new JSONObject(); + requestParams.put("actionedUponNode", docNodeRef); + requestParams.put("actionDefinitionName", "declare-as-version-record"); - return doPostJsonRequest(user, password, requestParams, ACTIONS_API); - } - catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); } /** * Creates a non-electronic record + *
    + *
  • eg. of usage for Unfiled records with folder : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, "unfiled records folder"); + *
  • eg. of usage for creating record directly in Unfiled Records : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, ""); + *
* * @param username the username * @param password the password @@ -180,16 +171,14 @@ public class RecordsAPI extends BaseAPI * @param categoryName the category that contains the record, in the case in which the container would be Unfiled records use UNFILED_RECORDS_BREADCRUMB as value * @param folderName the folder inside which the record exists, in the case in which the folder name is "", the record will be created directly in the specified container * this case is useful when trying to create a record directly in Unfiled Records - * @return true if the creation of the record has been successful - * eg. of usage for Unfiled records with folder : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, "unfiled records folder"); - * eg. of usage for creating record directly in Unfiled Records : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, ""); + * @return The HTTP Response (or null if the request was not needed). */ - public > boolean createNonElectronicRecord(String username, String password, Map properties, String categoryName, String folderName) + public > HttpResponse createNonElectronicRecord(String username, String password, Map properties, String categoryName, String folderName) { String recordName = properties.get(RMProperty.NAME); if (getRecord(username, password, folderName, recordName) != null) { - return true; + return null; } String recordPath = "/" + categoryName; if (!folderName.equals("")) @@ -201,7 +190,7 @@ public class RecordsAPI extends BaseAPI if (record != null) { - return true; + return null; } // non-electronic properties String recordTitle = getPropertyValue(properties, RMProperty.TITLE); @@ -216,26 +205,19 @@ public class RecordsAPI extends BaseAPI // retrieve the container nodeRef String parentNodeRef = getItemNodeRef(username, password, recordPath); - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); - requestParams.put("prop_cm_name", recordName); - requestParams.put("prop_cm_title", recordTitle); - requestParams.put("prop_cm_description", description); - requestParams.put("prop_rma_physicalSize", physicalSize); - requestParams.put("prop_rma_numberOfCopies", numberOfCopies); - requestParams.put("prop_rma_storageLocation", storage); - requestParams.put("prop_rma_shelf", shelf); - requestParams.put("prop_rma_box", box); - requestParams.put("prop_rma_file", file); + JSONObject requestParams = new JSONObject(); + requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); + requestParams.put("prop_cm_name", recordName); + requestParams.put("prop_cm_title", recordTitle); + requestParams.put("prop_cm_description", description); + requestParams.put("prop_rma_physicalSize", physicalSize); + requestParams.put("prop_rma_numberOfCopies", numberOfCopies); + requestParams.put("prop_rma_storageLocation", storage); + requestParams.put("prop_rma_shelf", shelf); + requestParams.put("prop_rma_box", box); + requestParams.put("prop_rma_file", file); - return doPostJsonRequest(username, password, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); - } catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(username, password, false, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); } /** @@ -351,24 +333,17 @@ public class RecordsAPI extends BaseAPI * @param user the user * @param password the user's password * @param nodeId the in place record node id - * @return true if the action was successful + * @return The HTTP Response. */ - public boolean hideRecord(String user, String password, String nodeId) + public HttpResponse hideRecord(String user, String password, String nodeId) { String docNodeRef = getNodeRefSpacesStore() + nodeId; - try - { - JSONObject requestParams = new JSONObject(); - requestParams.put("actionedUponNode", docNodeRef); - requestParams.put("actionDefinitionName", "hide-record"); + JSONObject requestParams = new JSONObject(); + requestParams.put("actionedUponNode", docNodeRef); + requestParams.put("actionDefinitionName", "hide-record"); - return doPostJsonRequest(user, password, requestParams, ACTIONS_API); - } catch (JSONException error) - { - LOGGER.error("Unable to extract response parameter", error); - } - return false; + return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java index 00704081da..8b3bef51b0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java @@ -37,6 +37,7 @@ import java.util.stream.Collectors; import org.alfresco.rest.core.v0.BaseAPI; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.apache.http.HttpResponse; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -63,20 +64,20 @@ public class RulesAPI extends BaseAPI * * @param containerNodeRef the container to have the rule created on * @param ruleProperties the rule properties - * @return true if the rule has been created successfully, false otherwise + * @return The HTTP Response (or null if the response could not be understood). */ - public boolean createRule(String username, String password, String containerNodeRef, RuleDefinition ruleProperties) + public HttpResponse createRule(String username, String password, String containerNodeRef, RuleDefinition ruleProperties) { try { - return doPostJsonRequest(username, password, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, false, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); } catch (JSONException error) { LOGGER.error("Unable to extract response parameter.", error); } - return false; + return null; } /** @@ -309,22 +310,15 @@ public class RulesAPI extends BaseAPI * @param password the password * @param containerNodeRef the container nodeRef * - * @return true if the rule has been disabled or if the current state is disabled + * @return The HTTP Response (or null if the current state is disabled). */ - public boolean disableRulesInheritance(String username, String password, String containerNodeRef) + public HttpResponse disableRulesInheritance(String username, String password, String containerNodeRef) { - try + if(containerInheritsRulesFromParent(username, password, containerNodeRef)) { - if(containerInheritsRulesFromParent(username, password, containerNodeRef)) - { - return doPostJsonRequest(username, password, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); - } + return doPostJsonRequest(username, password, false, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } - catch (JSONException e) - { - return false; - } - return true; + return null; } /** @@ -333,22 +327,15 @@ public class RulesAPI extends BaseAPI * @param username the username * @param password the password * @param containerNodeRef the container nodeRef - * @return true if the rule has been enabled or if the current state is enabled + * @return The HTTP Response (or null if the current state is disabled). */ - public boolean enableRulesInheritance(String username, String password, String containerNodeRef) + public HttpResponse enableRulesInheritance(String username, String password, String containerNodeRef) { - try + if (!containerInheritsRulesFromParent(username, password, containerNodeRef)) { - if (!containerInheritsRulesFromParent(username, password, containerNodeRef)) - { - return doPostJsonRequest(username, password, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); - } + return doPostJsonRequest(username, password, false, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } - catch (JSONException e) - { - return false; - } - return true; + return null; } /** From 8e35851a7492cb4c99236c4c7c8f7b48f139ece8 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 7 Nov 2017 10:40:49 +0000 Subject: [PATCH 3/6] RM-5837 Finish off test and add util to extract JSON. Use two folders, as copying a file and a folder always passes even with the old code. --- .../org/alfresco/rest/core/v0/APIUtils.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java new file mode 100644 index 0000000000..5404b483c8 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java @@ -0,0 +1,73 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.core.v0; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper methods for use with REST APIs. + * + * @author Tom Page + * @since 2.6 + */ +public class APIUtils +{ + /** Logger for this class. */ + private static final Logger LOGGER = LoggerFactory.getLogger(APIUtils.class); + + /** Private constructor for helper class. */ + private APIUtils() + { + } + + /** + * Extract the body of a HTTP response as a JSON object. + * + * @param httpResponse The HTTP response. + * @return A JSON representation of the object. + */ + public static JSONObject convertHTTPResponseToJSON(HttpResponse httpResponse) + { + String source = null; + try + { + source = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"); + } + catch (IOException e) + { + throw new IllegalArgumentException("Could not extract JSON from HTTP response.", e); + } + LOGGER.info("Response body:\n{}", source); + return new JSONObject(source); + } +} From 350ea660ae80a9b7c4b8d06a1dc1abb9ee0fa522 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 8 Nov 2017 11:57:27 +0000 Subject: [PATCH 4/6] RM-5837 Only assert the return code if we're not expecting a failure. --- .../src/main/java/org/alfresco/rest/core/v0/BaseAPI.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 06674c99e1..8f77a8403d 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 @@ -408,7 +408,10 @@ public abstract class BaseAPI try { HttpResponse httpResponse = doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); - assertEquals("POST request was not successful.", httpResponse.getStatusLine().getStatusCode(), 200); + if (!expectFailure) + { + assertEquals("POST request was not successful.", httpResponse.getStatusLine().getStatusCode(), 200); + } return httpResponse; } catch (InstantiationException | IllegalAccessException error) From 592275b1aa0d4dd76c6138352fcf30ed97b70145 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 8 Nov 2017 12:44:22 +0000 Subject: [PATCH 5/6] RM-5837 Always assert status code when making a v0 POST request. Refactor the DestroyRecordFolderActions UI test as this previously relied on the create retention schedule API call failing silently for the second test. --- .../org/alfresco/rest/core/v0/BaseAPI.java | 48 +++++++++---------- .../java/org/alfresco/rest/v0/CopyToAPI.java | 9 ++-- .../rest/v0/RMRolesAndActionsAPI.java | 6 +-- .../alfresco/rest/v0/RecordCategoriesAPI.java | 6 +-- .../alfresco/rest/v0/RecordFoldersAPI.java | 2 +- .../java/org/alfresco/rest/v0/RecordsAPI.java | 26 +++++----- .../java/org/alfresco/rest/v0/RulesAPI.java | 6 +-- 7 files changed, 51 insertions(+), 52 deletions(-) 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 8f77a8403d..3f0f4c3920 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 @@ -342,59 +342,60 @@ public abstract class BaseAPI /** * Helper method for POST requests * - * @param adminUser user with administrative privileges - * @param adminPassword password for adminUser - * @param expectFailure If false then an exception will be thrown if the POST is not successful. - * @param requestParams zero or more endpoint specific request parameters - * @param urlTemplate request URL template + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param expectedStatusCode The expected return status code. + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ protected HttpResponse doPostJsonRequest(String adminUser, String adminPassword, - boolean expectFailure, + int expectedStatusCode, JSONObject requestParams, String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - return doPostJsonRequest(adminUser, adminPassword, expectFailure, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); + return doPostJsonRequest(adminUser, adminPassword, expectedStatusCode, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); } /** * Helper method for POST requests to slingshot. * - * @param adminUser user with administrative privileges - * @param adminPassword password for adminUser - * @param expectFailure If false then an exception will be thrown if the POST is not successful. - * @param requestParams zero or more endpoint specific request parameters - * @param urlTemplate request URL template + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param expectedStatusCode The expected return status code. + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ protected HttpResponse doSlingshotPostJsonRequest(String adminUser, String adminPassword, - boolean expectFailure, + int expectedStatusCode, JSONObject requestParams, String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - return doPostJsonRequest(adminUser, adminPassword, expectFailure, client.getAlfrescoUrl() + SLINGSHOT_PREFIX, requestParams, urlTemplate, urlTemplateParams); + return doPostJsonRequest(adminUser, adminPassword, expectedStatusCode, client.getAlfrescoUrl() + SLINGSHOT_PREFIX, requestParams, urlTemplate, urlTemplateParams); } /** * Helper method for POST requests * - * @param adminUser user with administrative privileges - * @param adminPassword password for adminUser - * @param expectFailure If false then an exception will be thrown if the POST is not successful. - * @param urlStart the start of the URL (for example "alfresco/s/slingshot"). - * @param requestParams zero or more endpoint specific request parameters - * @param urlTemplate request URL template + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param expectedStatusCode The expected return status code. + * @param urlStart the start of the URL (for example "alfresco/s/slingshot"). + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate + * @throws AssertionError if the returned status code is not as expected. */ private HttpResponse doPostJsonRequest(String adminUser, String adminPassword, - boolean expectFailure, + int expectedStatusCode, String urlStart, JSONObject requestParams, String urlTemplate, @@ -408,10 +409,7 @@ public abstract class BaseAPI try { HttpResponse httpResponse = doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); - if (!expectFailure) - { - assertEquals("POST request was not successful.", httpResponse.getStatusLine().getStatusCode(), 200); - } + assertEquals("POST request to " + requestUrl + " was not successful.", httpResponse.getStatusLine().getStatusCode(), expectedStatusCode); return httpResponse; } catch (InstantiationException | IllegalAccessException error) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java index ecbfc006ce..f50e6ff4d3 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CopyToAPI.java @@ -65,7 +65,7 @@ public class CopyToAPI extends BaseAPI */ public HttpResponse copyTo(String user, String password, String targetContainerPath, List nodeRefs) { - return copyToAndGetResponse(user, password, false, targetContainerPath, nodeRefs); + return copyTo(user, password, 200, targetContainerPath, nodeRefs); } /** @@ -73,19 +73,20 @@ public class CopyToAPI extends BaseAPI * * @param user The username of the user to use. * @param password The password of the user. - * @param expectFailure If false then an exception will be thrown if the POST is not successful. + * @param expectedStatusCode The expected return status code. * @param targetContainerPath The destination to copy the nodes to. This should be in the format * "{site}/{container}/{path}", "{site}/{container}", "{store_type}/{store_id}/{id}/{path}", * "{store_type}/{store_id}/{id}" or "{store_type}/{store_id}". * @param nodeRefs The list of nodes to copy. * @return The HTTP Response. + * @throws AssertionError If the API didn't return the expected status code. */ - public HttpResponse copyToAndGetResponse(String user, String password, boolean expectFailure, String targetContainerPath, List nodeRefs) + public HttpResponse copyTo(String user, String password, int expectedStatusCode, String targetContainerPath, List nodeRefs) { JSONObject requestParams = new JSONObject(); requestParams.put("nodeRefs", new JSONArray(nodeRefs)); - return doSlingshotPostJsonRequest(user, password, expectFailure, requestParams, + return doSlingshotPostJsonRequest(user, password, expectedStatusCode, requestParams, MessageFormat.format(COPY_TO_API, "{0}", targetContainerPath)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java index 9ff6069efe..36b87aac1e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java @@ -238,7 +238,7 @@ public class RMRolesAndActionsAPI extends BaseAPI ) ); } - return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); } /** @@ -303,7 +303,7 @@ public class RMRolesAndActionsAPI extends BaseAPI requestParams.put("prop_rma_holdReason", reason); // Make the POST request and throw an assertion error if it fails. - HttpResponse httpResponse = doPostJsonRequest(user, password, false, requestParams, CREATE_HOLDS_API); + HttpResponse httpResponse = doPostJsonRequest(user, password, 200, requestParams, CREATE_HOLDS_API); assertNotNull("Expected object to have been created at " + fullHoldPath, getObjectByPath(user, password, fullHoldPath)); return httpResponse; @@ -325,6 +325,6 @@ public class RMRolesAndActionsAPI extends BaseAPI addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION); addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR); - return doPostJsonRequest(username, password, false, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); + return doPostJsonRequest(username, password, 200, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java index 96e12a7744..2908082b89 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java @@ -66,7 +66,7 @@ public class RecordCategoriesAPI extends BaseAPI requestParams.put("name", "createDispositionSchedule"); requestParams.put("nodeRef", catNodeRef); - return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); } /** @@ -85,7 +85,7 @@ public class RecordCategoriesAPI extends BaseAPI requestParams.put("prop_rma_dispositionAuthority", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_AUTHORITY)); requestParams.put("prop_rma_dispositionInstructions", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS)); requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString()); - return doPostJsonRequest(user, password, false, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); + return doPostJsonRequest(user, password, 200, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); } /** @@ -109,7 +109,7 @@ public class RecordCategoriesAPI extends BaseAPI addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS); addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT); - return doPostJsonRequest(user, password, false, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); + return doPostJsonRequest(user, password, 200, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); } /** diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java index 776888b633..36681f0094 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java @@ -68,7 +68,7 @@ public class RecordFoldersAPI extends BaseAPI requestParams.put("name", "closeRecordFolder"); requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); } catch (JSONException error) { 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 0801d3b08c..47fcaefc5a 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 @@ -77,7 +77,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "create-record"); - return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); } /** @@ -96,7 +96,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("name", "declareRecord"); requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, false, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); } /** @@ -111,21 +111,21 @@ public class RecordsAPI extends BaseAPI */ public HttpResponse rejectRecord(String user, String password, String recordName, String reason) { - return rejectRecordAndGetResponse(user, password, false, recordName, reason); + return rejectRecord(user, password, 200, recordName, reason); } /** * Reject the record given as parameter * - * @param user the user declaring the document as record - * @param password the user's password - * @param expectFailure If false then throws an exception if the POST call fails. + * @param user the user declaring the document as record + * @param password the user's password + * @param expectedStatusCode The expected return status code. * @param recordName the record name - * @param reason reject reason + * @param reason reject reason * @return The HTTP Response. - * @throws AssertionError If expectFailure is false and the POST call is not successful. + * @throws AssertionError If the expectedStatusCode was not returned. */ - public HttpResponse rejectRecordAndGetResponse(String user, String password, boolean expectFailure, String recordName, String reason) + public HttpResponse rejectRecord(String user, String password, int expectedStatusCode, String recordName, String reason) { String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName); @@ -135,7 +135,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("params",new JSONObject() .put("reason",reason)); - return doPostJsonRequest(user, password, expectFailure, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, expectedStatusCode, requestParams, RM_ACTIONS_API); } /** @@ -155,7 +155,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "declare-as-version-record"); - return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); } /** @@ -217,7 +217,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("prop_rma_box", box); requestParams.put("prop_rma_file", file); - return doPostJsonRequest(username, password, false, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); + return doPostJsonRequest(username, password, 200, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); } /** @@ -343,7 +343,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "hide-record"); - return doPostJsonRequest(user, password, false, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java index 8b3bef51b0..4d13d277c4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java @@ -71,7 +71,7 @@ public class RulesAPI extends BaseAPI { try { - return doPostJsonRequest(username, password, false, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, 200, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); } catch (JSONException error) { @@ -316,7 +316,7 @@ public class RulesAPI extends BaseAPI { if(containerInheritsRulesFromParent(username, password, containerNodeRef)) { - return doPostJsonRequest(username, password, false, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, 200, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } return null; } @@ -333,7 +333,7 @@ public class RulesAPI extends BaseAPI { if (!containerInheritsRulesFromParent(username, password, containerNodeRef)) { - return doPostJsonRequest(username, password, false, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, 200, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } return null; } From bb915f12317b927356f2752748d1eaa2c1147d8b Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 8 Nov 2017 14:02:22 +0000 Subject: [PATCH 6/6] RM-5837 Use constants for status codes. Also code review fixes for new test. --- .../org/alfresco/rest/v0/RMRolesAndActionsAPI.java | 7 ++++--- .../org/alfresco/rest/v0/RecordCategoriesAPI.java | 8 +++++--- .../org/alfresco/rest/v0/RecordFoldersAPI.java | 4 +++- .../main/java/org/alfresco/rest/v0/RecordsAPI.java | 14 ++++++++------ .../main/java/org/alfresco/rest/v0/RulesAPI.java | 8 +++++--- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java index 36b87aac1e..d5805a9a3b 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java @@ -27,6 +27,7 @@ package org.alfresco.rest.v0; import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON; +import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertNotNull; import java.io.IOException; @@ -238,7 +239,7 @@ public class RMRolesAndActionsAPI extends BaseAPI ) ); } - return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); } /** @@ -303,7 +304,7 @@ public class RMRolesAndActionsAPI extends BaseAPI requestParams.put("prop_rma_holdReason", reason); // Make the POST request and throw an assertion error if it fails. - HttpResponse httpResponse = doPostJsonRequest(user, password, 200, requestParams, CREATE_HOLDS_API); + HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); assertNotNull("Expected object to have been created at " + fullHoldPath, getObjectByPath(user, password, fullHoldPath)); return httpResponse; @@ -325,6 +326,6 @@ public class RMRolesAndActionsAPI extends BaseAPI addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION); addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR); - return doPostJsonRequest(username, password, 200, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); + return doPostJsonRequest(username, password, SC_OK, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java index 2908082b89..da327055e4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordCategoriesAPI.java @@ -26,6 +26,8 @@ */ package org.alfresco.rest.v0; +import static org.apache.http.HttpStatus.SC_OK; + import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; @@ -66,7 +68,7 @@ public class RecordCategoriesAPI extends BaseAPI requestParams.put("name", "createDispositionSchedule"); requestParams.put("nodeRef", catNodeRef); - return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); } /** @@ -85,7 +87,7 @@ public class RecordCategoriesAPI extends BaseAPI requestParams.put("prop_rma_dispositionAuthority", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_AUTHORITY)); requestParams.put("prop_rma_dispositionInstructions", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS)); requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString()); - return doPostJsonRequest(user, password, 200, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); + return doPostJsonRequest(user, password, SC_OK, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef)); } /** @@ -109,7 +111,7 @@ public class RecordCategoriesAPI extends BaseAPI addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS); addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT); - return doPostJsonRequest(user, password, 200, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); + return doPostJsonRequest(user, password, SC_OK, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef)); } /** diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java index 36681f0094..ad59119162 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java @@ -26,6 +26,8 @@ */ package org.alfresco.rest.v0; +import static org.apache.http.HttpStatus.SC_OK; + import org.alfresco.dataprep.ContentService; import org.alfresco.rest.core.v0.BaseAPI; import org.apache.http.HttpResponse; @@ -68,7 +70,7 @@ public class RecordFoldersAPI extends BaseAPI requestParams.put("name", "closeRecordFolder"); requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); } catch (JSONException error) { 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 47fcaefc5a..177f5a2372 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,6 +26,8 @@ */ package org.alfresco.rest.v0; +import static org.apache.http.HttpStatus.SC_OK; + import java.text.MessageFormat; import java.util.Map; @@ -77,7 +79,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "create-record"); - return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API); } /** @@ -96,7 +98,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("name", "declareRecord"); requestParams.put("nodeRef", recNodeRef); - return doPostJsonRequest(user, password, 200, requestParams, RM_ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); } /** @@ -111,7 +113,7 @@ public class RecordsAPI extends BaseAPI */ public HttpResponse rejectRecord(String user, String password, String recordName, String reason) { - return rejectRecord(user, password, 200, recordName, reason); + return rejectRecord(user, password, SC_OK, recordName, reason); } /** @@ -155,7 +157,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "declare-as-version-record"); - return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API); } /** @@ -217,7 +219,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("prop_rma_box", box); requestParams.put("prop_rma_file", file); - return doPostJsonRequest(username, password, 200, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); + return doPostJsonRequest(username, password, SC_OK, requestParams, CREATE_NON_ELECTRONIC_RECORD_API); } /** @@ -343,7 +345,7 @@ public class RecordsAPI extends BaseAPI requestParams.put("actionedUponNode", docNodeRef); requestParams.put("actionDefinitionName", "hide-record"); - return doPostJsonRequest(user, password, 200, requestParams, ACTIONS_API); + return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java index 4d13d277c4..5ff625c9d6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RulesAPI.java @@ -29,6 +29,8 @@ package org.alfresco.rest.v0; import static java.util.Arrays.asList; +import static org.apache.http.HttpStatus.SC_OK; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -71,7 +73,7 @@ public class RulesAPI extends BaseAPI { try { - return doPostJsonRequest(username, password, 200, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, SC_OK, getRuleRequest(ruleProperties), MessageFormat.format(RULES_API, "{0}", containerNodeRef)); } catch (JSONException error) { @@ -316,7 +318,7 @@ public class RulesAPI extends BaseAPI { if(containerInheritsRulesFromParent(username, password, containerNodeRef)) { - return doPostJsonRequest(username, password, 200, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, SC_OK, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } return null; } @@ -333,7 +335,7 @@ public class RulesAPI extends BaseAPI { if (!containerInheritsRulesFromParent(username, password, containerNodeRef)) { - return doPostJsonRequest(username, password, 200, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); + return doPostJsonRequest(username, password, SC_OK, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef)); } return null; }