![](/img/trans.png)
[英]How to create an enum entity type in Olingo OData V4 java API
[英]How to create a bounded action in Olingo V4 (java)
我試過到處尋找,但無法弄清楚如何在olingo V4 java中實現有界動作。
到處都是無限制的動作教程。
我試過調整這段代碼。
final CsdlAction action = new CsdlAction();
action.setName("testAction");
action.setBound(true);
當我嘗試訪問$ metadata API時,這會給我帶來錯誤。
如果有人能指出我如何去做一個很好的教程那么它會很棒。
我查看了olingo的源代碼並調試了他們的代碼。 經過大量的研究工作,我能夠在Olingo中實施有限的行動。
假設我們想要實現一個有界動作,該動作與實體類型X綁定並返回實體Y.
需要做出的改變是:
元數據文檔:在擴展CsdlAbstractEdmProvider或實現CsdlEdmProvider的java類(自定義類)中,
實現getActions(...)函數
// 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;
}
並且在getActions(...)方法的相同元數據提供者類cal的getSchemas(...)中。
@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.
服務實施:現在,還需要服務實施。 根據已經使用的用例,我們需要創建一個實現ActionEntityProcessor的類。
在此之后,一切都是一樣的。 我希望這將有所幫助。 還有其他ActionProcessor,具體取決於操作的返回類型以及操作所限定的參數類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.