* @param method provides the method to add to the model.
* @throws ResourceConfigException on validation errors.
*/
private static void addActionResourceMethod(final ResourceModel model, final Method method)
{
Action actionAnno = method.getAnnotation(Action.class);
if (actionAnno == null)
{
return;
}
String actionName = actionAnno.name();
List<Parameter<?>> parameters = getParameters(model, method, ResourceMethod.ACTION);
Class<?> returnClass = getActionReturnClass(model, method, actionAnno, actionName);
TyperefDataSchema returnTyperefSchema = getActionTyperefDataSchema(model, actionAnno, actionName);
validateActionReturnType(model, method, returnClass, returnTyperefSchema);
if (!Modifier.isPublic(method.getModifiers()))
{
throw new ResourceConfigException(String.format("Resource '%s' contains non-public action method '%s'.",
model.getName(),
method.getName()));
}
RecordDataSchema recordDataSchema = DynamicRecordMetadata.buildSchema(method.getName(),
parameters);
RecordDataSchema actionReturnRecordDataSchema;
FieldDef<?> returnFieldDef;
if(returnClass != Void.TYPE)
{
@SuppressWarnings({"unchecked", "rawtypes"})
FieldDef<?> nonVoidFieldDef = new FieldDef(ActionResponse.VALUE_NAME, returnClass, getDataSchema(returnClass, returnTyperefSchema));
returnFieldDef = nonVoidFieldDef;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(ActionResponse.class.getName(), Collections.singleton((returnFieldDef)));
}
else
{
returnFieldDef = null;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(ActionResponse.class.getName(), Collections.<FieldDef<?>>emptyList());
}
if (model.getResourceLevel() == ResourceLevel.ENTITY && actionAnno.resourceLevel() == ResourceLevel.COLLECTION)
{
throw new ResourceConfigException(
String.format("Resource '%s' is a simple resource, it cannot contain actions at resource level \"COLLECTION\".",
model.getName()));
}