mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1869: Retrieve action details
- implementation and tests for retrieve action definition by id
This commit is contained in:
@@ -39,6 +39,8 @@ public interface Actions
|
||||
|
||||
CollectionWithPagingInfo<ActionDefinition> getActionDefinitions(Parameters params);
|
||||
|
||||
ActionDefinition getActionDefinitionById(String actionDefinitionId);
|
||||
|
||||
enum SortKey
|
||||
{
|
||||
NAME,
|
||||
|
@@ -27,13 +27,14 @@ package org.alfresco.rest.api.actions;
|
||||
|
||||
import org.alfresco.rest.api.Actions;
|
||||
import org.alfresco.rest.api.model.ActionDefinition;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
@EntityResource(name="action-definitions", title = "Actions")
|
||||
public class ActionDefinitionsEntityResource implements EntityResourceAction.Read<ActionDefinition>
|
||||
public class ActionDefinitionsEntityResource implements EntityResourceAction.Read<ActionDefinition>, EntityResourceAction.ReadById<ActionDefinition>
|
||||
{
|
||||
private Actions actions;
|
||||
|
||||
@@ -47,4 +48,10 @@ public class ActionDefinitionsEntityResource implements EntityResourceAction.Rea
|
||||
{
|
||||
return actions.getActionDefinitions(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionDefinition readById(String id, Parameters parameters) throws EntityNotFoundException
|
||||
{
|
||||
return actions.getActionDefinitionById(id);
|
||||
}
|
||||
}
|
||||
|
@@ -98,6 +98,53 @@ public class ActionsImpl implements Actions
|
||||
this.prefixResolver = prefixResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionDefinition getActionDefinitionById(String actionDefinitionId)
|
||||
{
|
||||
if (actionDefinitionId == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Missing actionDefinitionId");
|
||||
}
|
||||
|
||||
// Non-existing actionDefinitionId -> 404
|
||||
ActionDefinition result = null;
|
||||
try
|
||||
{
|
||||
result = getActionDefinition(actionService.getActionDefinition(actionDefinitionId));
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException nsbdx)
|
||||
{
|
||||
// Intentionally empty.
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new EntityNotFoundException(actionDefinitionId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private ActionDefinition getActionDefinition(
|
||||
org.alfresco.service.cmr.action.ActionDefinition actionDefinitionId)
|
||||
{
|
||||
List<ActionDefinition.ParameterDefinition> paramDefs =
|
||||
actionDefinitionId.
|
||||
getParameterDefinitions().
|
||||
stream().
|
||||
map(this::toModel).
|
||||
collect(Collectors.toList());
|
||||
return new ActionDefinition(
|
||||
actionDefinitionId.getName(), // ID is a synonym for name.
|
||||
actionDefinitionId.getName(),
|
||||
actionDefinitionId.getTitle(),
|
||||
actionDefinitionId.getDescription(),
|
||||
toShortQNames(actionDefinitionId.getApplicableTypes()),
|
||||
actionDefinitionId.getAdhocPropertiesAllowed(),
|
||||
actionDefinitionId.getTrackStatus(),
|
||||
paramDefs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<ActionDefinition> getActionDefinitions(NodeRef nodeRef, Parameters params)
|
||||
{
|
||||
|
@@ -207,6 +207,47 @@ public class TestActions extends AbstractBaseApiTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetActionDefinition() throws PublicApiException
|
||||
{
|
||||
final String person1 = account1PersonIt.next();
|
||||
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
|
||||
|
||||
ActionDefinition actionDef = actions.getActionDefinition("add-features",200);
|
||||
|
||||
assertNotNull("Action definition should not be null", actionDef);
|
||||
|
||||
// Check ActionDefinition fields
|
||||
assertEquals("add-features", actionDef.getId());
|
||||
assertEquals("add-features", actionDef.getName());
|
||||
assertEquals("Add aspect", actionDef.getTitle());
|
||||
assertEquals("This will add an aspect to the matched item.", actionDef.getDescription());
|
||||
// Applicable types
|
||||
assertEquals(0, actionDef.getApplicableTypes().size());
|
||||
assertEquals(false, actionDef.isTrackStatus());
|
||||
// Parameter definitions
|
||||
assertEquals(1, actionDef.getParameterDefinitions().size());
|
||||
ActionDefinition.ParameterDefinition paramDefs = actionDef.getParameterDefinitions().get(0);
|
||||
assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
|
||||
assertEquals("d:qname", paramDefs.getType());
|
||||
assertEquals(true, paramDefs.isMandatory());
|
||||
assertEquals("Aspect", paramDefs.getDisplayLabel());
|
||||
assertEquals(false, paramDefs.isMultiValued());
|
||||
assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
|
||||
|
||||
// Non-existing actionDefinitionId -> 404
|
||||
{
|
||||
actions.getActionDefinition("some-text",404);
|
||||
}
|
||||
|
||||
// Unauthorized -> 401
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
|
||||
actions.getActionDefinition(null, 401);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetActionDefinitionsForNode() throws Exception
|
||||
{
|
||||
|
@@ -2795,5 +2795,22 @@ public class PublicApiClient
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ActionDefinition getActionDefinition(String actionDefinitionId, int expectedStatus) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getSingle("action-definitions", actionDefinitionId, null,
|
||||
null, null, "Unexpected response", expectedStatus);
|
||||
|
||||
if (response != null && response.getJsonResponse() != null)
|
||||
{
|
||||
JSONObject jsonEntity = (JSONObject) response.getJsonResponse().get("entry");
|
||||
if (jsonEntity != null)
|
||||
{
|
||||
return parseActionDefinition(jsonEntity);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user