Java Based Apps on SAP Cloud_2_开发ESPM

Developing Java-Based Apps on SAP Cloud Platform Week 2

JPA Model

Check Out JPA Branch

Java Based Apps on SAP Cloud_2_开发ESPM_第1张图片

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

    
        jdbc/DefaultDB
        javax.sql.DataSource
    

Java Based Apps on SAP Cloud_2_开发ESPM_第2张图片

修改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 properties = new HashMap();
            properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
            entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
            Utility.setEntityManagerFactory(entityManagerFactory);
        }
        return entityManagerFactory;
    }
Java Based Apps on SAP Cloud_2_开发ESPM_第3张图片

修改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")
Java Based Apps on SAP Cloud_2_开发ESPM_第4张图片

末尾加入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);
        }
    }

Java Based Apps on SAP Cloud_2_开发ESPM_第5张图片

修改persistence.xml
加入code

com.sap.espm.model.SalesOrderHeader
Java Based Apps on SAP Cloud_2_开发ESPM_第6张图片

OData Services

Check Out OData Branch
Check Out Commit, 然后Reset

Java Based Apps on SAP Cloud_2_开发ESPM_第7张图片

修改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);
        }

Java Based Apps on SAP Cloud_2_开发ESPM_第8张图片

修改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 getCustomerByEmailAddress(@EdmFunctionImportParameter(name = "EmailAddress") final String emailAddress)
            throws ODataException

Java Based Apps on SAP Cloud_2_开发ESPM_第9张图片

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

view.registerOperations(CustomerProcessor.class, null);
Java Based Apps on SAP Cloud_2_开发ESPM_第10张图片

SAP UI5

Check Out UI5 Branch

Java Based Apps on SAP Cloud_2_开发ESPM_第11张图片

修改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"
                }
            }
        },

Java Based Apps on SAP Cloud_2_开发ESPM_第12张图片

修改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");
            });
Java Based Apps on SAP Cloud_2_开发ESPM_第13张图片

修改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");
Java Based Apps on SAP Cloud_2_开发ESPM_第14张图片

你可能感兴趣的:(Java Based Apps on SAP Cloud_2_开发ESPM)