Java Based Apps on SAP Cloud_2_开发ESPM

Developing Java-Based Apps on SAP Cloud Platform Week 2

JPA Model

Check Out JPA Branch


修改web.xml
Path: src/main/webapp/WEB-INF/web.xml, Project: espm-cloud-web,加入代码

    <resource-ref>
        <res-ref-name>jdbc/DefaultDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
    </resource-ref>


修改JpaEntityManagerFactory.java
Path: src/main/java/>com.sap.espm.model.web>
JpaEntityManagerFactory.java, Project: espm-cloud-web加入代码

    public static synchronized EntityManagerFactory getEntityManagerFactory() throws NamingException, SQLException
    {
        if (entityManagerFactory == null)
        {
            final InitialContext ctx = new InitialContext();
            final DataSource ds = (DataSource) ctx.lookup(DATA_SOURCE_NAME);
            final Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
            entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
            Utility.setEntityManagerFactory(entityManagerFactory);
        }
        return entityManagerFactory;
    }

修改SalesOrderHeader.java
path: Java
src/main/java>com.sap.espm.model>SalesOrderHeader.java , Project : espm-cloud-jpa, 加入code

@Entity
@Table(name = "ESPM_SALES_ORDER_HEADER")

末尾加入code (如果有error, Date 类型需要导入)

    @PrePersist
    private void persist()
    {
        final Calendar cal = Calendar.getInstance();
        final Date date = new Date();
        cal.setTime(date);
        this.lifeCycleStatus = "N";
        this.lifeCycleStatusName = "New";
        int itemNumber = 10;
        this.netAmount = new BigDecimal("0.00");
        this.taxAmount = new BigDecimal("0.00");
        this.grossAmount = new BigDecimal("0.00");
        this.createdAt = cal;
        for (final SalesOrderItem item : salesOrderItems)
        {
            item.setSalesOrderId(this.getSalesOrderId());
            item.setItemNumber(itemNumber);
            itemNumber += 10;
            item.persist();
            this.netAmount = this.netAmount.add(item.getNetAmount()).setScale(3);
            this.taxAmount = this.taxAmount.add(item.getTaxAmount()).setScale(3);
            this.grossAmount = this.grossAmount.add(item.getGrossAmount()).setScale(3);
        }
    }


修改persistence.xml
加入code

<class>com.sap.espm.model.SalesOrderHeader</class>

OData Services

Check Out OData Branch
Check Out Commit, 然后Reset


修改EspmServiceFactory
package: com.sap.espm.model.web, Project: espm-cloud-web,加入code

        final ODataJPAContext oDataJPAContext = this.getODataJPAContext();
        EntityManagerFactory emf;
        try
        {
            emf = JpaEntityManagerFactory.getEntityManagerFactory();
            oDataJPAContext.setEntityManagerFactory(emf);
            oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
            oDataJPAContext.setJPAEdmExtension(new EspmProcessingExtension());
            oDataJPAContext.setJPAEdmMappingModel("EspmEdmMapping.xml");
            return oDataJPAContext;
        }
        catch (final Exception e)
        {
            throw new ODataRuntimeException(e);
        }


修改CustomerProcessor.java
package: com.sap.espm.model.function.impl, Project:
espm-cloud-web

    @EdmFunctionImport(name = "GetCustomerByEmailAddress", entitySet = "Customers", returnType = @ReturnType(type = Type.ENTITY, isCollection = true))
    public List<Customer> getCustomerByEmailAddress(@EdmFunctionImportParameter(name = "EmailAddress") final String emailAddress)
            throws ODataException


修改EspmProcessingExtension.java
package: com.sap.espm.model.web, Project:
espm-cloud-web

view.registerOperations(CustomerProcessor.class, null);

SAP UI5

Check Out UI5 Branch


修改manifest.json
path: src > main > webapp > webshop , Project: espm-cloud-web

      "dataSources": {
            "espmDataModel": {
                "uri": "/espm-cloud-web/espm.svc",
                "type": "OData",
                "settings": {
                "odataVersion": "2.0"
                }
            }
        },


修改index.html
path: src > main > webapp > webshop, Project: espm-cloud-web

            sap.ui.getCore().attachInit(function() {
                new sap.m.Shell({
                    app : new sap.ui.core.ComponentContainer({
                        height : "100%",
                        name : "com.sap.espm.shop"
                    })
                }).placeAt("content");
            });

修改Component.js
path: src > main > webapp > webshop, Project: espm-cloud-web

            // set the device model, odata model and json model
            this.setModel(models.createDeviceModel(), "device");
            var sServiceUrl = this.getMetadata().getManifestEntry(
                    "sap.app").dataSources.espmDataModel.uri;
            var oEspmModel = new sap.ui.model.odata.ODataModel(
                    sServiceUrl, {
                        json : true,
                        loadMetadataAsync : true
                    });
            this.setModel(oEspmModel, "EspmModel");
            var oData = {
                ShoppingCart : []
            };
            var oModel = new sap.ui.model.json.JSONModel(oData);
            this.setModel(oModel, "Cart");
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • jHipster - 微服务搭建 CC_简书[https://www.jianshu.com/u/be0d56c4...
    quanjj阅读 843评论 0 2
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,971评论 6 342
  • 武志红《衡量自我的五个维度》学习复盘。 我原来是一个特别不会识人、也很不愿意去识人很自我的人。是一个”自我疆界“很...
    龚少90990阅读 550评论 6 4
  • 概述 Session-409的主题为[What’s New in Testing],主要包括: Enhanceme...
    nuclear阅读 1,470评论 0 1