Olingo-OData:如何在Olingo OData中定义复杂类型

时间:2018-07-27 14:20:17

标签: java spring-boot odata olingo

我需要在OData实体的JSON下面定义。

"d" : {
    "__metadata" : {
      "type" : "ServiceCloudAssetModel.HBServicesInfo",
      "uri" : "http://sdf.com/notimplemented/Entity(0)"
    },
    "SPVersion" : "0",
    "Status" : "Informational",
    "ResponseCode" : "100",
    "Description" : "High Memory Usage; Hardware Failure detected",
    "LastBootUpDate" : "2017-04-07T20:48:13.486816",
    "SchemaVersion" : null,
    "AgentVersion" : "2.0.0.0",
    "WindowsUpdatedRunDate" : "2017-04-05T08:13:42",
    "UTCDate" : "2018-06-20T18:22:32.3388283Z",
    "ResponseMessage" : "Success",
    "uuid" : "bada16db-2b2f-46de-a366-545ea9774d2c",
    "LocalDate" : "2018-06-10T23:52:32.3970051+05:30",
    "URL" : "https://uat.sdf.com/#/xyz/devices/heartbeat/XYZ$$9223370507383975807",
    "SystemDriveFreeSpace" : "110.29 GB",
    "HighCPUUsage" : "60",
    "Model" : "ABCE7440",
    "ApplicationCrashesLast24hrs" : null,
    "OSVersion" : "6.3.9600",
    "BIOSVersion" : "A08",
    "ServiceTagId" : "XYZ",
    "Registered" : "false",
    "HighMemUsage" : "87.5"
  }

我已经为简单类型编写了以下getEntityType函数...我需要的是定义__metadata和d复杂类型的帮助。

    @Override
    public CsdlEntityType getEntityType() {
    // create CsdlPropertyRef for Key element
                CsdlEntityType entityType = new CsdlEntityType();
                entityType.setName(ET_HeartBeatData);
                CsdlPropertyRef propertyRef = new CsdlPropertyRef();
                propertyRef.setName(ETF_SERVICETAGID);              
                List<CsdlPropertyRef> csdlPropertyRefList = new ArrayList<CsdlPropertyRef>();
                csdlPropertyRefList.add(propertyRef);               
                entityType.setKey(csdlPropertyRefList);


    // create EntityType properties


        CsdlProperty SPVersion = new CsdlProperty().setName(ETF_SPVERSION)
                .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty Status = new CsdlProperty().setName(ETF_STATUS)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty ResponseCode = new CsdlProperty().setName(ETF_RESPONSECODE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty Description = new CsdlProperty().setName(ETF_DESCRIPTION)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty LastBootUpDate = new CsdlProperty().setName(ETF_LASTBOOTUPDATE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty SchemaVersion = new CsdlProperty().setName(ETF_SCHEMAVERSION)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty AgentVersion = new CsdlProperty().setName(ETF_AGENTVERSION)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());                              
        CsdlProperty WindowsUpdatedRunDate = new CsdlProperty().setName(ETF_WINDOWSUPDATEDRUNDATE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());                              
        CsdlProperty UTCDate = new CsdlProperty().setName(ETF_UTCDATE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty ResponseMessage = new CsdlProperty().setName(ETF_RESPONSEMESSAGE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty uuid = new CsdlProperty().setName(ETF_UUID)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty LocalDate = new CsdlProperty().setName(ETF_LOCALDATE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty URL = new CsdlProperty().setName(ETF_URL)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty SystemDriveFreeSpace = new CsdlProperty().setName(ETF_SYSTEMDRIVEFREESPACE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty HighCPUUsage = new CsdlProperty().setName(ETF_HIGHCPUUSAGE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty Model = new CsdlProperty().setName(ETF_MODEL)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty ApplicationCrashesLast24hrs = new CsdlProperty().setName(ETF_APPLICATIONCRASHESLAST24HRS)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty OSVersion = new CsdlProperty().setName(ETF_OSVERSION)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty BIOSVersion = new CsdlProperty().setName(ETF_BIOSVERSION)
                .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty ServiceTagId = new CsdlProperty().setName(ETF_SERVICETAGID)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty Registered = new CsdlProperty().setName(ETF_REGISTERED)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty HighMemUsage = new CsdlProperty().setName(ETF_HIGHMEMUSAGE)
                        .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

// configure EntityType
entityType.setProperties(Arrays.asList(SPVersion,Status,ResponseCode,Description,LastBootUpDate,SchemaVersion,AgentVersion,WindowsUpdatedRunDate,UTCDate,ResponseMessage,uuid,LocalDate,URL,SystemDriveFreeSpace,HighCPUUsage,Model,ApplicationCrashesLast24hrs,OSVersion,BIOSVersion,ServiceTagId,Registered,HighMemUsage));
return entityType;
    }

请忽略以下文本。 请忽略以下文本。 请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文本。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字。请忽略下面的文字文字。请忽略下面的文字。请忽略下面的文字。

0 个答案:

没有答案