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;
}
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;
}
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;
}
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);
}
Aggregations