Package org.alfresco.rest.core.v0
Class BaseAPI
- java.lang.Object
-
- org.alfresco.rest.core.v0.BaseAPI
-
- Direct Known Subclasses:
CopyToAPI,CustomDefinitionsAPI,DispositionScheduleService,HoldsAPI,NodeAPI,NodePropertiesAPI,RecordCategoriesAPI,RecordFoldersAPI,RecordsAPI,RMAuditAPI,RMRolesAndActionsAPI,RulesAPI,SearchAPI,UserTrashcanAPI
public abstract class BaseAPI extends Object
The base API class containing common methods for making v0 API requests- Since:
- 2.5
- Author:
- Kristijan Conkas
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseAPI.PermissionTypestatic classBaseAPI.RETENTION_SCHEDULEstatic classBaseAPI.RM_ACTIONSUsed to execute rm actions on a nodestatic classBaseAPI.RMPropertyUsed to set RM items properties including records, categories and folders
-
Field Summary
Fields Modifier and Type Field Description protected static StringACTIONS_APIprotected org.alfresco.dataprep.ContentServicecontentServiceprotected static org.slf4j.LoggerLOGGERstatic StringNODE_PREFIXstatic StringNODE_REF_WORKSPACE_SPACES_STOREprotected static StringRM_ACTIONS_APIstatic StringRM_SITE_IDprotected static StringSHARE_ACTION_APIprotected static StringUPDATE_METADATA_API
-
Constructor Summary
Constructors Constructor Description BaseAPI()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <K extends Enum<?>>
org.json.JSONObjectaddPropertyToRequest(org.json.JSONObject requestParams, String propertyRequestValue, Map<K,String> itemProperties, Enum<?> property)Retrieves the property value and decides if that gets to be added to the requestprotected voiddeleteItem(String username, String password, String itemPath)Deletes the category, folder or record given as parameterprotected org.json.JSONObjectdoDeleteRequest(String adminUser, String adminPassword, String urlTemplate, String... urlTemplateParams)Helper method for Delete requestsprotected org.json.JSONObjectdoGetRequest(String adminUser, String adminPassword, String urlTemplate, String... urlTemplateParams)Helper method for GET requestsprotected org.apache.http.HttpResponsedoPostJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)Helper method for POST requestsprotected org.json.JSONObjectdoPostRequest(String adminUser, String adminPassword, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)Helper method for POST requestsprotected org.apache.http.HttpResponsedoPutJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)Helper method for PUT requestsprotected org.json.JSONObjectdoPutRequest(String adminUser, String adminPassword, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)Helper method for PUT requestsprotected org.apache.http.HttpResponsedoSlingshotPostJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)Helper method for POST requests to slingshot.protected org.json.JSONObjectfacetedRequest(String username, String password, List<org.apache.http.NameValuePair> parameters, String requestURI)Generic faceted request.static StringgetFilePlanPath()Retrieve the File Plan pathStringgetItemNodeRef(String username, String password, String path)Retrieves the nodeRef of an item (category, folder or record) with the given pathstatic StringgetNodeRefSpacesStore()Retrieve the node ref spaces store valueprotected org.apache.chemistry.opencmis.client.api.CmisObjectgetObjectByPath(String username, String password, String path)Retrieve a Cmis object by its path<K extends Enum<?>>
StringgetPropertyValue(Map<K,String> properties, Enum<?> property)Util to return the property value from a mapprotected StringgetPropertyValue(org.json.JSONObject result, String nodeRef, String propertyName)Helper method to extract the property value for the given nodeRef and property nameprotected List<String>getPropertyValues(org.json.JSONObject result, String propertyName)Helper method to extract list of properties values from result.protected Map<String,List<String>>getPropertyValuesByUniquePropertyValue(org.json.JSONObject requestResult, String uniqueProperty, List<String> otherProperties)Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value.
-
-
-
Field Detail
-
LOGGER
protected static final org.slf4j.Logger LOGGER
-
NODE_PREFIX
public static final String NODE_PREFIX
- See Also:
- Constant Field Values
-
UPDATE_METADATA_API
protected static final String UPDATE_METADATA_API
- See Also:
- Constant Field Values
-
ACTIONS_API
protected static final String ACTIONS_API
- See Also:
- Constant Field Values
-
RM_ACTIONS_API
protected static final String RM_ACTIONS_API
- See Also:
- Constant Field Values
-
RM_SITE_ID
public static final String RM_SITE_ID
- See Also:
- Constant Field Values
-
SHARE_ACTION_API
protected static final String SHARE_ACTION_API
- See Also:
- Constant Field Values
-
contentService
@Autowired protected org.alfresco.dataprep.ContentService contentService
-
NODE_REF_WORKSPACE_SPACES_STORE
public static final String NODE_REF_WORKSPACE_SPACES_STORE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPropertyValues
protected List<String> getPropertyValues(org.json.JSONObject result, String propertyName)
Helper method to extract list of properties values from result.- Parameters:
result- the response- Returns:
- list of specified property values in result
- Throws:
RuntimeException- for malformed response
-
getPropertyValue
protected String getPropertyValue(org.json.JSONObject result, String nodeRef, String propertyName)
Helper method to extract the property value for the given nodeRef and property name- Parameters:
result-nodeRef-propertyName-- Returns:
-
getPropertyValuesByUniquePropertyValue
protected Map<String,List<String>> getPropertyValuesByUniquePropertyValue(org.json.JSONObject requestResult, String uniqueProperty, List<String> otherProperties)
Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value.- Parameters:
requestResult- the request response- Returns:
- a map containing information about multiple properties values that correspond to a unique one
- Throws:
RuntimeException- for malformed response
-
getItemNodeRef
public String getItemNodeRef(String username, String password, String path)
Retrieves the nodeRef of an item (category, folder or record) with the given path- Parameters:
username- the usernamepassword- the passwordpath- the path to the container eg. in case of a category it would be the category name, in case of a folder it would be /categoryName/folderName when trying to get File Plan, the path would be ""- Returns:
- the container nodeRef
-
getObjectByPath
protected org.apache.chemistry.opencmis.client.api.CmisObject getObjectByPath(String username, String password, String path)
Retrieve a Cmis object by its path- Parameters:
username- the user's usernamepassword- its passwordpath- the object path- Returns:
- the object in case it exists, null if its does not exist
-
facetedRequest
protected org.json.JSONObject facetedRequest(String username, String password, List<org.apache.http.NameValuePair> parameters, String requestURI)
Generic faceted request.- Parameters:
username- the usernamepassword- the passwordparameters- if the request has parameters- Returns:
- result object (see API reference for more details), null for any errors
-
doGetRequest
protected org.json.JSONObject doGetRequest(String adminUser, String adminPassword, String urlTemplate, String... urlTemplateParams)
Helper method for GET requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doDeleteRequest
protected org.json.JSONObject doDeleteRequest(String adminUser, String adminPassword, String urlTemplate, String... urlTemplateParams)
Helper method for Delete requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doPutRequest
protected org.json.JSONObject doPutRequest(String adminUser, String adminPassword, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)
Helper method for PUT requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserrequestParams- zero or more endpoint specific request parametersurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doPutJsonRequest
protected org.apache.http.HttpResponse doPutJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)
Helper method for PUT requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserexpectedStatusCode- The expected return status code.requestParams- zero or more endpoint specific request parametersurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doPostRequest
protected org.json.JSONObject doPostRequest(String adminUser, String adminPassword, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)
Helper method for POST requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserrequestParams- zero or more endpoint specific request parametersurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doPostJsonRequest
protected org.apache.http.HttpResponse doPostJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)
Helper method for POST requests- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserexpectedStatusCode- The expected return status code.requestParams- zero or more endpoint specific request parametersurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
doSlingshotPostJsonRequest
protected org.apache.http.HttpResponse doSlingshotPostJsonRequest(String adminUser, String adminPassword, int expectedStatusCode, org.json.JSONObject requestParams, String urlTemplate, String... urlTemplateParams)
Helper method for POST requests to slingshot.- Parameters:
adminUser- user with administrative privilegesadminPassword- password for adminUserexpectedStatusCode- The expected return status code.requestParams- zero or more endpoint specific request parametersurlTemplate- request URL templateurlTemplateParams- zero or more parameters used with urlTemplate
-
getPropertyValue
public <K extends Enum<?>> String getPropertyValue(Map<K,String> properties, Enum<?> property)
Util to return the property value from a map- Parameters:
properties- the map containing propertiesproperty- to get value for- Returns:
- the property value
-
addPropertyToRequest
protected <K extends Enum<?>> org.json.JSONObject addPropertyToRequest(org.json.JSONObject requestParams, String propertyRequestValue, Map<K,String> itemProperties, Enum<?> property) throws org.json.JSONException
Retrieves the property value and decides if that gets to be added to the request- Parameters:
requestParams- the request parameterspropertyRequestValue- the property name in the request, eg. "prop_cm_name"itemProperties- map of item's properties valuesproperty- the property in the property map to check value for- Returns:
- the json object used in request with the property with its value added if that is not null or empty
- Throws:
org.json.JSONException
-
deleteItem
protected void deleteItem(String username, String password, String itemPath)
Deletes the category, folder or record given as parameter- Parameters:
username- the username with whom the delete is performedpassword- the user's passworditemPath- the path to the item eg. in case of a category it would be the "/" + category name, in case of a folder or subCategory it would be /categoryName/folderName or /categoryName/subCategoryName/ in case of a record /categoryName/folderName/recordName- Throws:
AssertionError- if the delete was not successful.
-
getNodeRefSpacesStore
public static String getNodeRefSpacesStore()
Retrieve the node ref spaces store value- Returns:
- node ref spaces store
-
getFilePlanPath
public static String getFilePlanPath()
Retrieve the File Plan path- Returns:
- the File Plan path
-
-