如何在应用程序编程模型(APM)中正确实现功能

时间:2018-12-17 00:43:39

标签: java sap

按照此站点(Implement Functions)中的说明,我正在尝试在服务中实现功能。

我从UI5应用调用函数导入

_sGetActiveStatus: "GetActiveStatus"

oThis.getModel().callFunction(
            "/" + oThis._sGetActiveStatus, {
                method: "GET",
                urlParameters: {
                    ExternalID: sExternalId,
                    StartDate: oThis._oViewModel.getProperty(
                        "/MondayDate"),
                    EndDate: oThis._oViewModel.getProperty("/FridayDate")
                },
                success: function (oData, response) {
                    console.log(oData);
                },
                error: function (oError) {
                    console.log(oError);
                }
            });

在Java类中:

@Function(serviceName = "myService", Name = "GetActiveStatus")
public OperationResponse getActiveStatus(OperationRequest functionRequest) {
    System.out.println("==> Calling the backend OData V2 service - Get ActiveStatus");
    ExpressionBuilderImpl builder = new ExpressionBuilderImpl();
    // Retrieve the parameters of the function from the
    // OperationRequest object
    Map<String, Object> params = functionRequest.getParameters();

    try {
        List<EntityData> productsList = new ArrayList<>();
        String productID = (String) params.get("ExternalID");
        System.out.println("==> Class of StartDate: " + params.get("StartDate").getClass());
        System.out.println("==> StartDate: " + params.get("StartDate"));
        // LocalDateTime startDate = (LocalDateTime) params.get("StartDate");
        System.out.println("==> Class of EndDate: " + params.get("EndDate").getClass());
        System.out.println("==> EndDate: " + params.get("EndDate"));
        // LocalDateTime endDate = (LocalDateTime) params.get("EndDate");

        // EntityData sampleProduct = fetchData(productID);

        // Add the retrieved entity data to a products list
        // productsList.add(sampleProduct);

        // Return an instance of OperationResponse in the case of a
        // successful fetch of product data
        return OperationResponse.setSuccess().setEntityData(productsList).response();

    } catch (Exception e) {
        // Return an instance of OperationResponse containing the error in
        // case of failure
        ErrorResponse errorResponse = ErrorResponse.getBuilder().setMessage(e.getMessage()).setCause(e).response();

        return OperationResponse.setError(errorResponse);
    }
}

CDS文件:

service myService {@cds.persistence.skip entity ActiveDate {key PersonExternalID: String(12);
IsSatActive : Boolean;
IsSunActive : Boolean;
IsMonActive : Boolean;
IsTueActive : Boolean;
IsWedActive : Boolean;
IsThuActive : Boolean;
IsFriActive : Boolean;}; function GetActiveStatus(ExternalID:String(12), StartDate:Date, EndDate:Date) returns ActiveDate;}

但是,调用函数import时出现错误。

{"error":{"code":"501","message":{"lang":"en-GB","value":"Not implemented"}}}

我看到我的函数名称在UI以及Java和CDS中都相同。 我该如何解决? 三

0 个答案:

没有答案