How to create a limited action in Olingo V4 (java)

I tried searching everywhere, but couldn't figure out how to implement limited actions in olingo V4 java.

A textbook on unlimited action is provided everywhere.

I tried to configure this code.

  final CsdlAction action = new CsdlAction();
  action.setName("testAction");
  action.setBound(true);

This gives me an error when I try to access the metadata API.

If anyone can point me to a good tutorial on how to do this, then it would be great.

+4
source share
1 answer

I looked at olingo source code and debugged their code. After much research, I was able to implement limited activities at Olingo.

, , X Y.

, , :

: java ( ), CsdlAbstractEdmProvider CsdlEdmProvider,

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

getSchemas (...) getActions (...).

@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.

. , . ActionProcessors , .

+2

Source: https://habr.com/ru/post/1649994/


All Articles