Search in sources :

Example 1 with ParameterConstraint

use of org.alfresco.service.cmr.action.ParameterConstraint in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method testGetActionConstraint.

public void testGetActionConstraint() throws Exception {
    List<ParameterConstraint> constraints = actionService.getParameterConstraints();
    if (constraints.size() == 0) {
        return;
    }
    String name = constraints.get(0).getName();
    Response response = sendRequest(new GetRequest(formateActionConstraintUrl(name)), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertNotNull(result);
    assertTrue(result.has("data"));
    JSONObject data = result.getJSONObject("data");
    assertTrue(data.has("name"));
    assertTrue(data.has("values"));
    JSONArray values = data.getJSONArray("values");
    for (int i = 0; i < values.length(); i++) {
        JSONObject value = values.getJSONObject(i);
        assertTrue(value.has("value"));
        assertTrue(value.has("displayLabel"));
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint)

Example 2 with ParameterConstraint

use of org.alfresco.service.cmr.action.ParameterConstraint in project alfresco-remote-api by Alfresco.

the class ActionConstraintsGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // get request parameters
    String[] names = req.getParameterValues("name");
    List<ParameterConstraint> parameterConstraints = null;
    if (names != null && names.length > 0) {
        // filter is present in request
        parameterConstraints = new ArrayList<ParameterConstraint>();
        // find specified parameter constraints
        for (String name : names) {
            ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name);
            if (parameterConstraint != null) {
                parameterConstraints.add(parameterConstraint);
            }
        }
    } else {
        // no filter was provided, return all parameter constraints
        parameterConstraints = actionService.getParameterConstraints();
    }
    model.put("actionConstraints", parameterConstraints);
    return model;
}
Also used : HashMap(java.util.HashMap) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint)

Example 3 with ParameterConstraint

use of org.alfresco.service.cmr.action.ParameterConstraint in project alfresco-remote-api by Alfresco.

the class ActionConstraintGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // get request parameters
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String name = templateVars.get("name");
    // get specified parameter constraint
    ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name);
    if (parameterConstraint == null) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find parameter constraint with name: " + name);
    }
    model.put("actionConstraint", parameterConstraint);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint)

Aggregations

ParameterConstraint (org.alfresco.service.cmr.action.ParameterConstraint)3 HashMap (java.util.HashMap)2 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)1 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1