mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-5837_TestOnCopyNotificationEvent' into 'master'
Feature/rm 5837 test on copy notification event See merge request !670
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #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);
|
||||||
|
}
|
||||||
|
}
|
@@ -26,6 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.core.v0;
|
package org.alfresco.rest.core.v0;
|
||||||
|
|
||||||
|
import static org.testng.AssertJUnit.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -80,6 +82,7 @@ public abstract class BaseAPI
|
|||||||
protected static final String RM_ACTIONS_API = "{0}rma/actions/ExecutionQueue";
|
protected static final String RM_ACTIONS_API = "{0}rma/actions/ExecutionQueue";
|
||||||
protected static final String RM_SITE_ID = "rm";
|
protected static final String RM_SITE_ID = "rm";
|
||||||
protected static final String SHARE_ACTION_API = "{0}internal/shared/share/workspace/SpacesStore/{1}";
|
protected static final String SHARE_ACTION_API = "{0}internal/shared/share/workspace/SpacesStore/{1}";
|
||||||
|
private static final String SLINGSHOT_PREFIX = "alfresco/s/slingshot/";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AlfrescoHttpClientFactory alfrescoHttpClientFactory;
|
private AlfrescoHttpClientFactory alfrescoHttpClientFactory;
|
||||||
@@ -341,26 +344,73 @@ public abstract class BaseAPI
|
|||||||
*
|
*
|
||||||
* @param adminUser user with administrative privileges
|
* @param adminUser user with administrative privileges
|
||||||
* @param adminPassword password for adminUser
|
* @param adminPassword password for adminUser
|
||||||
|
* @param expectedStatusCode The expected return status code.
|
||||||
* @param requestParams zero or more endpoint specific request parameters
|
* @param requestParams zero or more endpoint specific request parameters
|
||||||
* @param urlTemplate request URL template
|
* @param urlTemplate request URL template
|
||||||
* @param urlTemplateParams zero or more parameters used with <i>urlTemplate</i>
|
* @param urlTemplateParams zero or more parameters used with <i>urlTemplate</i>
|
||||||
*/
|
*/
|
||||||
protected boolean doPostJsonRequest(String adminUser,
|
protected HttpResponse doPostJsonRequest(String adminUser,
|
||||||
String adminPassword,
|
String adminPassword,
|
||||||
|
int expectedStatusCode,
|
||||||
JSONObject requestParams,
|
JSONObject requestParams,
|
||||||
String urlTemplate,
|
String urlTemplate,
|
||||||
String... urlTemplateParams)
|
String... urlTemplateParams)
|
||||||
{
|
{
|
||||||
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
|
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
|
||||||
|
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 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 <i>urlTemplate</i>
|
||||||
|
*/
|
||||||
|
protected HttpResponse doSlingshotPostJsonRequest(String adminUser,
|
||||||
|
String adminPassword,
|
||||||
|
int expectedStatusCode,
|
||||||
|
JSONObject requestParams,
|
||||||
|
String urlTemplate,
|
||||||
|
String... urlTemplateParams)
|
||||||
|
{
|
||||||
|
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
|
||||||
|
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 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 <i>urlTemplate</i>
|
||||||
|
* @throws AssertionError if the returned status code is not as expected.
|
||||||
|
*/
|
||||||
|
private HttpResponse doPostJsonRequest(String adminUser,
|
||||||
|
String adminPassword,
|
||||||
|
int expectedStatusCode,
|
||||||
|
String urlStart,
|
||||||
|
JSONObject requestParams,
|
||||||
|
String urlTemplate,
|
||||||
|
String... urlTemplateParams)
|
||||||
|
{
|
||||||
|
// Ensure the host is part of the request URL.
|
||||||
String requestUrl = MessageFormat.format(
|
String requestUrl = MessageFormat.format(
|
||||||
urlTemplate,
|
urlTemplate,
|
||||||
client.getApiUrl(),
|
urlStart,
|
||||||
urlTemplateParams);
|
urlTemplateParams);
|
||||||
client.close();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams);
|
HttpResponse httpResponse = doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams);
|
||||||
|
assertEquals("POST request to " + requestUrl + " was not successful.", httpResponse.getStatusLine().getStatusCode(), expectedStatusCode);
|
||||||
|
return httpResponse;
|
||||||
}
|
}
|
||||||
catch (InstantiationException | IllegalAccessException error)
|
catch (InstantiationException | IllegalAccessException error)
|
||||||
{
|
{
|
||||||
@@ -462,7 +512,7 @@ public abstract class BaseAPI
|
|||||||
return returnValues;
|
return returnValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends HttpRequestBase> boolean doRequestJson(
|
private <T extends HttpRequestBase> HttpResponse doRequestJson(
|
||||||
Class<T> requestType,
|
Class<T> requestType,
|
||||||
String requestUrl,
|
String requestUrl,
|
||||||
String adminUser,
|
String adminUser,
|
||||||
@@ -482,7 +532,11 @@ public abstract class BaseAPI
|
|||||||
((HttpEntityEnclosingRequestBase) request).setEntity(new StringEntity(requestParams.toString()));
|
((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;
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException | URISyntaxException error1)
|
catch (UnsupportedEncodingException | URISyntaxException error1)
|
||||||
{
|
{
|
||||||
@@ -497,7 +551,7 @@ public abstract class BaseAPI
|
|||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* #%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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
|
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.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 The HTTP Response.
|
||||||
|
* @throws AssertionError If the API call didn't return a 200 response.
|
||||||
|
*/
|
||||||
|
public HttpResponse copyTo(String user, String password, String targetContainerPath, List<String> nodeRefs)
|
||||||
|
{
|
||||||
|
return copyTo(user, password, 200, targetContainerPath, nodeRefs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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 copyTo(String user, String password, int expectedStatusCode, String targetContainerPath, List<String> nodeRefs)
|
||||||
|
{
|
||||||
|
JSONObject requestParams = new JSONObject();
|
||||||
|
requestParams.put("nodeRefs", new JSONArray(nodeRefs));
|
||||||
|
|
||||||
|
return doSlingshotPostJsonRequest(user, password, expectedStatusCode, requestParams,
|
||||||
|
MessageFormat.format(COPY_TO_API, "{0}", targetContainerPath));
|
||||||
|
}
|
||||||
|
}
|
@@ -27,6 +27,8 @@
|
|||||||
package org.alfresco.rest.v0;
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON;
|
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;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@@ -206,9 +208,9 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
* @param user the user executing the action
|
* @param user the user executing the action
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param contentName the content name
|
* @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);
|
return executeAction(user, password, contentName, rm_action, null);
|
||||||
}
|
}
|
||||||
@@ -220,13 +222,11 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param contentName the record folder name
|
* @param contentName the record folder name
|
||||||
* @param date the date to be updated
|
* @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);
|
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, contentName);
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("name", action.getAction());
|
requestParams.put("name", action.getAction());
|
||||||
requestParams.put("nodeRef", recNodeRef);
|
requestParams.put("nodeRef", recNodeRef);
|
||||||
@@ -239,13 +239,7 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||||
}
|
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -288,37 +282,32 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
* @param holdName the hold name
|
* @param holdName the hold name
|
||||||
* @param reason hold reason
|
* @param reason hold reason
|
||||||
* @param description hold description
|
* @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
|
// if the hold already exists don't try to create it again
|
||||||
String holdsContainerPath = getFilePlanPath() + "/Holds";
|
String holdsContainerPath = getFilePlanPath() + "/Holds";
|
||||||
|
String fullHoldPath = holdsContainerPath + "/" + holdName;
|
||||||
CmisObject hold = getObjectByPath(user, password, holdsContainerPath + "/" + holdName);
|
CmisObject hold = getObjectByPath(user, password, fullHoldPath);
|
||||||
if (hold != null)
|
if (hold != null)
|
||||||
{
|
{
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
// retrieve the Holds container nodeRef
|
// retrieve the Holds container nodeRef
|
||||||
String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
||||||
requestParams.put("prop_cm_name", holdName);
|
requestParams.put("prop_cm_name", holdName);
|
||||||
requestParams.put("prop_cm_description", description);
|
requestParams.put("prop_cm_description", description);
|
||||||
requestParams.put("prop_rma_holdReason", reason);
|
requestParams.put("prop_rma_holdReason", reason);
|
||||||
|
|
||||||
boolean requestSucceeded = doPostJsonRequest(user, password, requestParams, CREATE_HOLDS_API);
|
// Make the POST request and throw an assertion error if it fails.
|
||||||
return requestSucceeded && getObjectByPath(user, password, holdsContainerPath + "/" + holdName) != null;
|
HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API);
|
||||||
}
|
assertNotNull("Expected object to have been created at " + fullHoldPath,
|
||||||
catch (JSONException error)
|
getObjectByPath(user, password, fullHoldPath));
|
||||||
{
|
return httpResponse;
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,11 +316,9 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
* @param username the user updating the item
|
* @param username the user updating the item
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param itemNodeRef the item noderef
|
* @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<RMProperty, String> properties)
|
public HttpResponse updateMetadata(String username, String password, String itemNodeRef, Map<RMProperty, String> properties)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
addPropertyToRequest(requestParams, "prop_cm_name", properties, RMProperty.NAME);
|
addPropertyToRequest(requestParams, "prop_cm_name", properties, RMProperty.NAME);
|
||||||
@@ -339,12 +326,6 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION);
|
addPropertyToRequest(requestParams, "prop_cm_description", properties, RMProperty.DESCRIPTION);
|
||||||
addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR);
|
addPropertyToRequest(requestParams, "prop_cm_author", properties, RMProperty.AUTHOR);
|
||||||
|
|
||||||
return doPostJsonRequest(username, password, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef));
|
return doPostJsonRequest(username, password, SC_OK, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", itemNodeRef));
|
||||||
}
|
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,12 +26,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.v0;
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
|
import static org.apache.http.HttpStatus.SC_OK;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
import org.json.JSONException;
|
import org.apache.http.HttpResponse;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -56,24 +58,17 @@ public class RecordCategoriesAPI extends BaseAPI
|
|||||||
* @param user the user creating the disposition schedule
|
* @param user the user creating the disposition schedule
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param categoryName the category name to create the retention schedule for
|
* @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);
|
String catNodeRef = getNodeRefSpacesStore() + getItemNodeRef(user, password, "/" + categoryName);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("name", "createDispositionSchedule");
|
requestParams.put("name", "createDispositionSchedule");
|
||||||
requestParams.put("nodeRef", catNodeRef);
|
requestParams.put("nodeRef", catNodeRef);
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||||
} catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,24 +77,17 @@ public class RecordCategoriesAPI extends BaseAPI
|
|||||||
* @param user the user creating the disposition schedule
|
* @param user the user creating the disposition schedule
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param retentionNodeRef the retention nodeRef
|
* @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<RETENTION_SCHEDULE, String> retentionProperties, Boolean appliedToRecords)
|
public HttpResponse setRetentionScheduleGeneralFields(String user, String password, String retentionNodeRef, Map<RETENTION_SCHEDULE, String> retentionProperties, Boolean appliedToRecords)
|
||||||
{
|
{
|
||||||
String dispRetentionNodeRef = NODE_PREFIX + retentionNodeRef;
|
String dispRetentionNodeRef = NODE_PREFIX + retentionNodeRef;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("prop_rma_dispositionAuthority", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_AUTHORITY));
|
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_dispositionInstructions", getPropertyValue(retentionProperties, RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS));
|
||||||
requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString());
|
requestParams.put("prop_rma_recordLevelDisposition", appliedToRecords.toString());
|
||||||
return doPostJsonRequest(user, password, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef));
|
return doPostJsonRequest(user, password, SC_OK, requestParams, MessageFormat.format(UPDATE_METADATA_API, "{0}", dispRetentionNodeRef));
|
||||||
} catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,14 +96,12 @@ public class RecordCategoriesAPI extends BaseAPI
|
|||||||
* @param user the user creating the disposition schedule
|
* @param user the user creating the disposition schedule
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param categoryName the category name to create the retention schedule for
|
* @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<RETENTION_SCHEDULE, String> properties)
|
public HttpResponse addDispositionScheduleSteps(String user, String password, String categoryName, Map<RETENTION_SCHEDULE, String> properties)
|
||||||
{
|
{
|
||||||
String catNodeRef = NODE_PREFIX + getItemNodeRef(user, password, "/" + categoryName);
|
String catNodeRef = NODE_PREFIX + getItemNodeRef(user, password, "/" + categoryName);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
addPropertyToRequest(requestParams, "name", properties, RETENTION_SCHEDULE.NAME);
|
addPropertyToRequest(requestParams, "name", properties, RETENTION_SCHEDULE.NAME);
|
||||||
addPropertyToRequest(requestParams, "description", properties, RETENTION_SCHEDULE.DESCRIPTION);
|
addPropertyToRequest(requestParams, "description", properties, RETENTION_SCHEDULE.DESCRIPTION);
|
||||||
@@ -125,13 +111,7 @@ public class RecordCategoriesAPI extends BaseAPI
|
|||||||
addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS);
|
addPropertyToRequest(requestParams, "events", properties, RETENTION_SCHEDULE.RETENTION_EVENTS);
|
||||||
addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT);
|
addPropertyToRequest(requestParams, "eligibleOnFirstCompleteEvent", properties, RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT);
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef));
|
return doPostJsonRequest(user, password, SC_OK, requestParams, MessageFormat.format(DISPOSITION_ACTIONS_API, "{0}", catNodeRef));
|
||||||
} catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,8 +26,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.v0;
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
|
import static org.apache.http.HttpStatus.SC_OK;
|
||||||
|
|
||||||
import org.alfresco.dataprep.ContentService;
|
import org.alfresco.dataprep.ContentService;
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -55,9 +58,9 @@ public class RecordFoldersAPI extends BaseAPI
|
|||||||
* @param user the user closing the folder
|
* @param user the user closing the folder
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param recordFolder the record folder name
|
* @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);
|
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordFolder);
|
||||||
|
|
||||||
@@ -67,12 +70,12 @@ public class RecordFoldersAPI extends BaseAPI
|
|||||||
requestParams.put("name", "closeRecordFolder");
|
requestParams.put("name", "closeRecordFolder");
|
||||||
requestParams.put("nodeRef", recNodeRef);
|
requestParams.put("nodeRef", recNodeRef);
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||||
}
|
}
|
||||||
catch (JSONException error)
|
catch (JSONException error)
|
||||||
{
|
{
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
LOGGER.error("Unable to extract response parameter", error);
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,14 +26,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.v0;
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
|
import static org.apache.http.HttpStatus.SC_OK;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
|
||||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||||
import org.alfresco.dataprep.ContentService;
|
import org.alfresco.dataprep.ContentService;
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -41,6 +43,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javafx.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods to make API requests using v0 API on records
|
* Methods to make API requests using v0 API on records
|
||||||
*
|
*
|
||||||
@@ -65,25 +69,17 @@ public class RecordsAPI extends BaseAPI
|
|||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param siteID the site id in which the document exists
|
* @param siteID the site id in which the document exists
|
||||||
* @param documentName the document name
|
* @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);
|
String docNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, siteID, documentName);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("actionedUponNode", docNodeRef);
|
requestParams.put("actionedUponNode", docNodeRef);
|
||||||
requestParams.put("actionDefinitionName", "create-record");
|
requestParams.put("actionDefinitionName", "create-record");
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API);
|
||||||
}
|
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,27 +88,18 @@ public class RecordsAPI extends BaseAPI
|
|||||||
* @param user the user declaring the document as record
|
* @param user the user declaring the document as record
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param recordName the record name
|
* @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);
|
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("name", "declareRecord");
|
requestParams.put("name", "declareRecord");
|
||||||
requestParams.put("nodeRef", recNodeRef);
|
requestParams.put("nodeRef", recNodeRef);
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||||
}
|
}
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reject the record given as parameter
|
* Reject the record given as parameter
|
||||||
@@ -121,28 +108,38 @@ public class RecordsAPI extends BaseAPI
|
|||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param recordName the record name
|
* @param recordName the record name
|
||||||
* @param reason reject reason
|
* @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 rejectRecord(user, password, SC_OK, recordName, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reject the record given as parameter
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* @return The HTTP Response.
|
||||||
|
* @throws AssertionError If the expectedStatusCode was not returned.
|
||||||
|
*/
|
||||||
|
public HttpResponse rejectRecord(String user, String password, int expectedStatusCode, String recordName, String reason)
|
||||||
{
|
{
|
||||||
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName);
|
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("name", "reject");
|
requestParams.put("name", "reject");
|
||||||
requestParams.put("nodeRef", recNodeRef);
|
requestParams.put("nodeRef", recNodeRef);
|
||||||
requestParams.put("params",new JSONObject()
|
requestParams.put("params",new JSONObject()
|
||||||
.put("reason",reason));
|
.put("reason",reason));
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API);
|
return doPostJsonRequest(user, password, expectedStatusCode, requestParams, RM_ACTIONS_API);
|
||||||
}
|
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare document version as record
|
* Declare document version as record
|
||||||
*
|
*
|
||||||
@@ -150,29 +147,25 @@ public class RecordsAPI extends BaseAPI
|
|||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param siteID the site id in which the document exists
|
* @param siteID the site id in which the document exists
|
||||||
* @param documentName the document name
|
* @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);
|
String docNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, siteID, documentName);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("actionedUponNode", docNodeRef);
|
requestParams.put("actionedUponNode", docNodeRef);
|
||||||
requestParams.put("actionDefinitionName", "declare-as-version-record");
|
requestParams.put("actionDefinitionName", "declare-as-version-record");
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API);
|
||||||
}
|
|
||||||
catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a non-electronic record
|
* Creates a non-electronic record
|
||||||
|
* <ul>
|
||||||
|
* <li>eg. of usage for Unfiled records with folder : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, "unfiled records folder");
|
||||||
|
* <li>eg. of usage for creating record directly in Unfiled Records : createNonElectronicRecord(getAdminName(), getAdminPassword(), properties, UNFILED_RECORDS_BREADCRUMB, "");
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param username the username
|
* @param username the username
|
||||||
* @param password the password
|
* @param password the password
|
||||||
@@ -180,16 +173,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 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
|
* @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
|
* 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
|
* @return The HTTP Response (or null if the request was not needed).
|
||||||
* 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, "");
|
|
||||||
*/
|
*/
|
||||||
public <K extends Enum<?>> boolean createNonElectronicRecord(String username, String password, Map<K, String> properties, String categoryName, String folderName)
|
public <K extends Enum<?>> HttpResponse createNonElectronicRecord(String username, String password, Map<K, String> properties, String categoryName, String folderName)
|
||||||
{
|
{
|
||||||
String recordName = properties.get(RMProperty.NAME);
|
String recordName = properties.get(RMProperty.NAME);
|
||||||
if (getRecord(username, password, folderName, recordName) != null)
|
if (getRecord(username, password, folderName, recordName) != null)
|
||||||
{
|
{
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
String recordPath = "/" + categoryName;
|
String recordPath = "/" + categoryName;
|
||||||
if (!folderName.equals(""))
|
if (!folderName.equals(""))
|
||||||
@@ -201,7 +192,7 @@ public class RecordsAPI extends BaseAPI
|
|||||||
|
|
||||||
if (record != null)
|
if (record != null)
|
||||||
{
|
{
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
// non-electronic properties
|
// non-electronic properties
|
||||||
String recordTitle = getPropertyValue(properties, RMProperty.TITLE);
|
String recordTitle = getPropertyValue(properties, RMProperty.TITLE);
|
||||||
@@ -216,8 +207,6 @@ public class RecordsAPI extends BaseAPI
|
|||||||
// retrieve the container nodeRef
|
// retrieve the container nodeRef
|
||||||
String parentNodeRef = getItemNodeRef(username, password, recordPath);
|
String parentNodeRef = getItemNodeRef(username, password, recordPath);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
||||||
requestParams.put("prop_cm_name", recordName);
|
requestParams.put("prop_cm_name", recordName);
|
||||||
@@ -230,12 +219,7 @@ public class RecordsAPI extends BaseAPI
|
|||||||
requestParams.put("prop_rma_box", box);
|
requestParams.put("prop_rma_box", box);
|
||||||
requestParams.put("prop_rma_file", file);
|
requestParams.put("prop_rma_file", file);
|
||||||
|
|
||||||
return doPostJsonRequest(username, password, requestParams, CREATE_NON_ELECTRONIC_RECORD_API);
|
return doPostJsonRequest(username, password, SC_OK, requestParams, CREATE_NON_ELECTRONIC_RECORD_API);
|
||||||
} catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -351,24 +335,17 @@ public class RecordsAPI extends BaseAPI
|
|||||||
* @param user the user
|
* @param user the user
|
||||||
* @param password the user's password
|
* @param password the user's password
|
||||||
* @param nodeId the in place record node id
|
* @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;
|
String docNodeRef = getNodeRefSpacesStore() + nodeId;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("actionedUponNode", docNodeRef);
|
requestParams.put("actionedUponNode", docNodeRef);
|
||||||
requestParams.put("actionDefinitionName", "hide-record");
|
requestParams.put("actionDefinitionName", "hide-record");
|
||||||
|
|
||||||
return doPostJsonRequest(user, password, requestParams, ACTIONS_API);
|
return doPostJsonRequest(user, password, SC_OK, requestParams, ACTIONS_API);
|
||||||
} catch (JSONException error)
|
|
||||||
{
|
|
||||||
LOGGER.error("Unable to extract response parameter", error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@ package org.alfresco.rest.v0;
|
|||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
import static org.apache.http.HttpStatus.SC_OK;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,6 +39,7 @@ import java.util.stream.Collectors;
|
|||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -63,20 +66,20 @@ public class RulesAPI extends BaseAPI
|
|||||||
*
|
*
|
||||||
* @param containerNodeRef the container to have the rule created on
|
* @param containerNodeRef the container to have the rule created on
|
||||||
* @param ruleProperties the rule properties
|
* @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
|
try
|
||||||
{
|
{
|
||||||
return doPostJsonRequest(username, password, 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)
|
catch (JSONException error)
|
||||||
{
|
{
|
||||||
LOGGER.error("Unable to extract response parameter.", error);
|
LOGGER.error("Unable to extract response parameter.", error);
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,22 +312,15 @@ public class RulesAPI extends BaseAPI
|
|||||||
* @param password the password
|
* @param password the password
|
||||||
* @param containerNodeRef the container nodeRef
|
* @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, SC_OK, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef));
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,22 +329,15 @@ public class RulesAPI extends BaseAPI
|
|||||||
* @param username the username
|
* @param username the username
|
||||||
* @param password the password
|
* @param password the password
|
||||||
* @param containerNodeRef the container nodeRef
|
* @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, SC_OK, new JSONObject(), MessageFormat.format(INHERIT_RULES_API, "{0}", containerNodeRef));
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user