use of org.alfresco.rest.api.model.ActionDefinition in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinitionsForNode.
@Test
public void canGetActionDefinitionsForNode() throws Exception {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
// Get the actions available on the -my- node-ref alias
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode("-my-", emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
// Check defaults, given that no paging params were sent in the request
assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
// Check ActionDefinition fields
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("add-features", action.getId());
assertEquals("add-features", action.getName());
assertEquals("Add aspect", action.getTitle());
assertEquals("This will add an aspect to the matched item.", action.getDescription());
// Applicable types
assertEquals(0, action.getApplicableTypes().size());
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(1, action.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = action.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());
}
AuthenticationUtil.setFullyAuthenticatedUser(person1);
// Get the actions for a "checked out" node - there should be a "check-in" action present.
// Inspect the fields, to make sure that they're all there. Especially applicableTypes, as
// this isn't available on any of the actions that appear for the "-my-" alias in the test above.
{
NodeRef nodeForCheckout = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, getMyNodeId()), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node-checkedout"), ContentModel.TYPE_CONTENT).getChildRef();
CheckOutCheckInService coci = applicationContext.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
coci.checkout(nodeForCheckout);
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(nodeForCheckout.getId(), emptyParams, 200);
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("check-in")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("check-in", action.getId());
assertEquals("check-in", action.getName());
assertEquals("Check in", action.getTitle());
assertEquals("This will check in the matched content.", action.getDescription());
// Applicable types
assertEquals(1, action.getApplicableTypes().size());
assertEquals("cm:content", action.getApplicableTypes().get(0));
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(2, action.getParameterDefinitions().size());
// "description"
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(CheckInActionExecuter.PARAM_DESCRIPTION, paramDefs.getName());
assertEquals("d:text", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Description", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
// "minorChange"
paramDefs = action.getParameterDefinitions().get(1);
assertEquals(CheckInActionExecuter.PARAM_MINOR_CHANGE, paramDefs.getName());
assertEquals("d:boolean", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Minor change", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
}
String myNode = getMyNodeId();
NodeRef validNode = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myNode), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node"), ContentModel.TYPE_CONTENT).getChildRef();
// Get the actions available using a specific node ID
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
}
// Basic/default paging and sorting
checkBasicPagingAndSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
paging -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 200));
// Test explicit sorting by title
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "title");
// Test explicit sorting by name
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "name");
// Badly formed request -> 400
{
// -1 is not acceptable
PublicApiClient.Paging paging = getPaging(0, -1);
actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 400);
}
// Non-existent node ID
{
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "750a2867-ecfa-478c-8343-fa0e39d27be3");
assertFalse("Test pre-requisite: node must not exist", nodeService.exists(nodeRef));
actions.getActionDefinitionsForNode(nodeRef.getId(), emptyParams, 404);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 401);
}
}
use of org.alfresco.rest.api.model.ActionDefinition in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinition.
@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);
}
}
use of org.alfresco.rest.api.model.ActionDefinition in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinitions.
@Test
public void canGetActionDefinitions() throws PublicApiException {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitions(emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
// Check defaults, given that no paging params were sent in the request
assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
// Check ActionDefinition fields
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("add-features", action.getId());
assertEquals("add-features", action.getName());
assertEquals("Add aspect", action.getTitle());
assertEquals("This will add an aspect to the matched item.", action.getDescription());
// Applicable types
assertEquals(0, action.getApplicableTypes().size());
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(1, action.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = action.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());
}
checkBasicPagingAndSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
paging -> actions.getActionDefinitions(createParams(paging, null), 200));
// Explicit sorting by title
checkSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitions(createParams(paging, orderBy), 200), "title");
// Explicit sorting by name
checkSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitions(createParams(paging, orderBy), 200), "name");
// Badly formed request -> 400
{
// -1 is not acceptable
PublicApiClient.Paging paging = getPaging(0, -1);
actions.getActionDefinitions(createParams(paging, null), 400);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinitions(emptyParams, 401);
}
}
Aggregations