如何在Olingo V4中创建有限动作(java) [英] How to create a bounded action in Olingo V4 (java)
问题描述
我尝试到处寻找,但无法弄清楚如何在olingo V4 java中实现有限动作.
I have tried looking everywhere but couldn't figure out how to implement bounded actions in olingo V4 java.
给出了无处不在的动作教程.
Everywhere unbounded action tutorial is given.
我尝试调整此代码.
final CsdlAction action = new CsdlAction();
action.setName("testAction");
action.setBound(true);
当我尝试访问$ metadata API时,这给了我错误.
This gives me error when I try to access $metadata API.
如果任何人都可以指导我找到有关如何进行的良好教程,那就太好了.
If anyone can point me towards a good tutorial on how to go about it then it would be great.
推荐答案
我研究了olingo的源代码并调试了它们的代码.经过大量研究工作,我得以在Olingo中实施有限动作.
I looked into the source code of olingo and debugged their code. After a lot of research work I was able to implement bounded actions in Olingo.
假设我们要实现一个绑定动作,该动作绑定到实体类型X,并返回实体Y.
Suppose we want to implement a bounded action which is bounded to an entity type X and which return an entity Y.
需要进行的更改是:
元数据文档: 在扩展CsdlAbstractEdmProvider或实现CsdlEdmProvider的Java类(自定义类)中,
Metadata Document: In your java class (custom class) which extends CsdlAbstractEdmProvider or implements CsdlEdmProvider,
实现getActions(...)函数
implement getActions(...) functions
// Action Names
public static final String ACTION_EXECUTE_NAME = "Execute";
// FullyQualified Action Names
public static final FullQualifiedName ACTION_EXECUTE_FQN = new FullQualifiedName("StackOverflow", ACTION_EXECUTE_NAME);
@Override
public List<CsdlAction> getActions(FullQualifiedName actionName) throws ODataException {
if (actionName.equals(ACTION_EXECUTE_FQN)) {
// It is allowed to overload actions, so we have to provide a list
// of Actions for each action name
final List<CsdlAction> actions = new ArrayList<CsdlAction>();
// Create the Csdl Action
final CsdlAction action = new CsdlAction();
action.setName(ACTION_EXECUTE_FQN.getName());
action.setBound(true);
// Creating Parameter the first one being binding parameter
final List<CsdlParameter> parameters = new ArrayList<CsdlParameter>();
final CsdlParameter parameter = new CsdlParameter();
parameter.setName("Parameter1");
parameter.setType(X);
parameter.setNullable(true);
parameter.setCollection(false);
parameters.add(parameter);
action.setParameters(parameters);
action.setReturnType(new CsdlReturnType().setCollection(false).setType(Y));
actions.add(action);
return actions;
}
return null;
}
并在相同的元数据提供程序类的getSchemas(...)中,调用getActions(...)方法.
and in the getSchemas(...) of the same metadata provider class cal the getActions(...) method.
@Override
public List<CsdlSchema> getSchemas() throws ODataException {
// create Schema
CsdlSchema schema = new CsdlSchema();
schema.setNamespace("Stackoverflow");
// add EntityTypes
List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
entityTypes.add(getEntityType(X));
entityTypes.add(getEntityType(Y));
schema.setEntityTypes(entityTypes);
// add EntityContainer
schema.setEntityContainer(getEntityContainer());
// add bounded actions
List<CsdlAction> actions = new ArrayList<CsdlAction>();
schema.setActions(actions);
actions.addAll(getActions(ACTION_EXECUTE_FQN));
List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
schemas.add(schema);
return schemas;
}
我们要做的是,创建了一个名为ACTION_EXECUTE_FQN的有界操作,该操作以参数作为操作的第一个参数,在我们的示例中为实体X,返回类型为实体Y.
what we have done is that, created a bounded a action named ACTION_EXECUTE_FQN with parameter as first argument of action, in our case being the entity X and return type is entity Y.
服务实施: 现在,还需要实现服务.根据使用的用例,我们需要创建一个实现 ActionEntityProcessor 的类.
Service Implementation: Now, service implementation is also needed. According to the use case which has been taken, we need a create a class implementing ActionEntityProcessor .
此后,一切都相同.我希望这将有所帮助.还有其他ActionProcessor,具体取决于操作的返回类型和操作所绑定到的参数的类型.
After this, everything is same. I hope this will help. There are other ActionProcessors depending on the return type of actions and the type of parameter to which action is bounded.
这篇关于如何在Olingo V4中创建有限动作(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!