Search in sources :

Example 1 with ParameterDefinition

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

the class AbstractRuleWebScript method parseJsonParameterValues.

protected Map<String, Serializable> parseJsonParameterValues(JSONObject jsonParameterValues, String name, boolean isAction) throws JSONException {
    Map<String, Serializable> parameterValues = new HashMap<String, Serializable>();
    // get parameters names
    JSONArray names = jsonParameterValues.names();
    if (names == null) {
        return null;
    }
    // Get the action or condition definition
    ParameterizedItemDefinition definition = null;
    if (isAction == true) {
        definition = actionService.getActionDefinition(name);
    } else {
        definition = actionService.getActionConditionDefinition(name);
    }
    if (definition == null) {
        throw new AlfrescoRuntimeException("Could not find defintion for action/condition " + name);
    }
    for (int i = 0; i < names.length(); i++) {
        String propertyName = names.getString(i);
        Object propertyValue = jsonParameterValues.get(propertyName);
        // Get the parameter definition we care about
        ParameterDefinition paramDef = definition.getParameterDefintion(propertyName);
        if (paramDef == null && !definition.getAdhocPropertiesAllowed()) {
            throw new AlfrescoRuntimeException("Invalid parameter " + propertyName + " for action/condition " + name);
        }
        if (paramDef != null) {
            QName typeQName = paramDef.getType();
            // Convert the property value
            Serializable value = convertValue(typeQName, propertyValue);
            parameterValues.put(propertyName, value);
        } else {
            // If there is no parameter definition we can only rely on the .toString() representation of the ad-hoc property
            parameterValues.put(propertyName, propertyValue.toString());
        }
    }
    return parameterValues;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ParameterizedItemDefinition(org.alfresco.service.cmr.action.ParameterizedItemDefinition) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) ParameterDefinition(org.alfresco.service.cmr.action.ParameterDefinition)

Example 2 with ParameterDefinition

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

the class ActionsImpl method extractActionParams.

private Map<String, Serializable> extractActionParams(org.alfresco.service.cmr.action.ActionDefinition actionDefinition, Map<String, String> params) {
    Map<String, Serializable> parameterValues = new HashMap<>();
    try {
        for (Map.Entry<String, String> entry : params.entrySet()) {
            String propertyName = entry.getKey();
            Object propertyValue = entry.getValue();
            // Get the parameter definition we care about
            ParameterDefinition paramDef = actionDefinition.getParameterDefintion(propertyName);
            if (paramDef == null && !actionDefinition.getAdhocPropertiesAllowed()) {
                throw new AlfrescoRuntimeException("Invalid parameter " + propertyName + " for action/condition " + actionDefinition.getName());
            }
            if (paramDef != null) {
                QName typeQName = paramDef.getType();
                // Convert the property value
                Serializable value = convertValue(typeQName, propertyValue);
                parameterValues.put(propertyName, value);
            } else {
                // If there is no parameter definition we can only rely on the .toString()
                // representation of the ad-hoc property
                parameterValues.put(propertyName, propertyValue.toString());
            }
        }
    } catch (JSONException je) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
    }
    return parameterValues;
}
Also used : Serializable(java.io.Serializable) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException) HashMap(java.util.HashMap) Map(java.util.Map) ParameterDefinition(org.alfresco.service.cmr.action.ParameterDefinition)

Example 3 with ParameterDefinition

use of org.alfresco.service.cmr.action.ParameterDefinition in project records-management by Alfresco.

the class ApplyCustomTypeAction method getParameterDefintions.

@Override
protected synchronized List<ParameterDefinition> getParameterDefintions() {
    // We can take these parameter definitions from the properties defined in the dod model.
    if (this.parameterDefinitions == null) {
        AspectDefinition aspectDefinition = getDictionaryService().getAspect(customTypeAspect);
        if (aspectDefinition == null) {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CUSTOM_ASPECT_NOT_RECOGNISED, customTypeAspect));
        }
        Map<QName, PropertyDefinition> props = aspectDefinition.getProperties();
        this.parameterDefinitions = new ArrayList<ParameterDefinition>(props.size());
        for (Map.Entry<QName, PropertyDefinition> entry : props.entrySet()) {
            String paramName = entry.getKey().toPrefixString(getNamespaceService());
            PropertyDefinition value = entry.getValue();
            QName paramType = value.getDataType().getName();
            boolean paramIsMandatory = value.isMandatory();
            parameterDefinitions.add(new ParameterDefinitionImpl(paramName, paramType, paramIsMandatory, null));
        }
    }
    return parameterDefinitions;
}
Also used : QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashMap(java.util.HashMap) Map(java.util.Map) ParameterDefinitionImpl(org.alfresco.repo.action.ParameterDefinitionImpl) ParameterDefinition(org.alfresco.service.cmr.action.ParameterDefinition)

Example 4 with ParameterDefinition

use of org.alfresco.service.cmr.action.ParameterDefinition in project records-management by Alfresco.

the class ExtendedActionServiceTest method inheritsAllParameterDefinitions.

/**
 * Checks if the action definition rmAction inherits all the parameter definitions from delegateAction.
 * @param rmAction The name of the action definition extending DelegateAction.
 * @param delegateAction The name of the delegate action.
 * @return true if rmAction inherits all the parameter definitions from delegateAction. false otherwise.
 */
private boolean inheritsAllParameterDefinitions(String rmAction, String delegateAction) {
    /*
         * Get the parameter definition list for rmAction
         */
    ActionDefinition rmActionDefinition = actionService.getActionDefinition(rmAction);
    assertNotNull(rmActionDefinition);
    List<ParameterDefinition> rmParameterDefinitions = rmActionDefinition.getParameterDefinitions();
    /*
         * Get the parameter definition list for the delegate action
         */
    ActionDefinition delegateActionDefinition = actionService.getActionDefinition(delegateAction);
    assertNotNull(delegateActionDefinition);
    List<ParameterDefinition> delegateParameterDefinitions = delegateActionDefinition.getParameterDefinitions();
    /*
         * Check if rmActionDefinition contains all the elements in  rmActionDefinition
         */
    return rmParameterDefinitions.containsAll(delegateParameterDefinitions);
}
Also used : ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition) ParameterDefinition(org.alfresco.service.cmr.action.ParameterDefinition)

Aggregations

ParameterDefinition (org.alfresco.service.cmr.action.ParameterDefinition)4 HashMap (java.util.HashMap)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 QName (org.alfresco.service.namespace.QName)3 Serializable (java.io.Serializable)2 Map (java.util.Map)2 ParameterDefinitionImpl (org.alfresco.repo.action.ParameterDefinitionImpl)1 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)1 ParameterizedItemDefinition (org.alfresco.service.cmr.action.ParameterizedItemDefinition)1 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1