วันจันทร์ที่ 1 พฤศจิกายน พ.ศ. 2553

การ convert ชนิดของข้อมูลใน simple method ของ OFBiz

ในบางกรณีที่ชนิดของข้อมูลที่รับมาจาก field ในฟอร์มเป็นคนละชนิดกับที่อยู่ใน entity เราสามารถใช้ simple method แปลงข้อมูลที่รับมาจาก field เพื่อเอาไปทำงานต่อไปได้ ดังนี้

<simple-method method-name="addProductionRunRoutingTask" short-description="Check parameters and add a production run task.">
        <call-map-processor in-map-name="parameters" out-map-name="context">
            <simple-map-processor name="prepareAddRoutingTask">
                <process field="productionRunId">
                    <copy/>
                </process>
                <process field="routingTaskId">
                    <copy/>
                    <not-empty>
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingRoutingTaskIdMissing"/>
                    </not-empty>
                </process>
                <process field="priority">
                    <copy/>
                    <not-empty>
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunPriorityMissing"/>
                    </not-empty>
                    <convert type="Long">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingRoutingSeqIdFormatNotCorrect"/>
                    </convert>
                </process>
                <process field="estimatedStartDate">
                    <copy/>
                    <convert type="Timestamp">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunStartDateNotCorrect"/>
                    </convert>
                </process>
                <process field="estimatedCompletionDate">
                    <copy/>
                    <convert type="Timestamp">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunCompletionDateNotCorrect"/>
                    </convert>
                </process>
                <process field="estimatedSetupMillis">
                    <copy/>
                    <convert type="BigDecimal">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunQuantityNotCorrect"/>
                    </convert>
                </process>
                <process field="estimatedMilliSeconds">
                    <copy/>
                    <convert type="BigDecimal">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunQuantityNotCorrect"/>
                    </convert>
                </process>
                <process field="workEffortName">
                    <copy/>
                </process>
                <process field="description">
                    <copy/>
                </process>
            </simple-map-processor>
        </call-map-processor>
        <check-errors/>
        <call-service service-name="addProductionRunRoutingTask" in-map-name="context">
        </call-service>
        
        <set field="workEffortAssocMap.workEffortIdFrom" from-field="parameters.workEffortIdFrom"/>
        <set field="workEffortAssocMap.workEffortIdTo" from-field="parameters.routingTaskId"/>
        <set field="workEffortAssocMap.workEffortAssocTypeId" value="WORK_EFF_BREAKDOWN"/>
        <set field="workEffortAssocMap.fromDate" from-field="parameters.estimatedStartDate"/>
        <call-service service-name="createWorkEffortAssoc" in-map-name="workEffortAssocMap"/>
        
        <property-to-field resource="DefaultMessages" property="service.default.message" field="successMessage"/>
    </simple-method>

จะเห็นว่าในส่วนของการรับค่าจากฟอร์ม จะมีการแปลงข้อมูลที่รับจาก field ดังนี้

<process field="priority">
                    <copy/>
                    <not-empty>
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingProductionRunPriorityMissing"/>
                    </not-empty>
                    <convert type="Long">
                        <fail-property resource="ManufacturingUiLabels" property="ManufacturingRoutingSeqIdFormatNotCorrect"/>
                    </convert>
</process> 

ในส่วนของ convert-type จะเป็นการแปลงข้อมูลจาก field ชื่อ priority ที่ได้รับมาจากฟอร์ม ให้กลายเป็นชนิด Long เพื่อนำไปใช้ในเซอร์วิส addProductionRunRoutingTask ต่อไป

ไม่มีความคิดเห็น:

แสดงความคิดเห็น