วันพุธที่ 9 มิถุนายน พ.ศ. 2553

การ สร้าง service เพื่อ edit ข้อมูลในฐานข้อมูลโดยใช้ simple method

ในบทความนี้จะแสดงการสร้าง service ที่ใช้แก้ไขข้อมูลใน entity โดยใช้ simple method ในไฟล์ *Services.xml มีวิธีทำดังนี้

1. สร้างฟอร์มชื่อ EditBlog ที่ *Forms.xml
<form name="EditBlog" type="single" target="editBlog" title="" 
            default-map-name="resultMap" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="statusId">
            <drop-down allow-empty="false">
                <entity-options description="${description}" entity-name="StatusItem" key-field-name="statusId">
                <entity-constraint name="statusTypeId" value="CONTENT_STATUS"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="editButton" title="Save" ><submit button-type="button"/></field>
</form>

2. include form ชื่อ EditBlog เข้าไปในไฟล์ *Screens.xml
<screen name="EditBlog">
        <section>
            <actions>
                <set field="newBlogId" from-field="parameters.newBlogId" global="true"/>
                <entity-one value-field="resultMap" entity-name="NewBlog" auto-field-map="true"></entity-one>
            </actions>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://myblog/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container id="content">
                             <container style="post">
                                   <container style="entry">
                                        <include-form location="component://myblog/widget/MyBlogForms.xml" name="EditBlog"/>
                                   </container>
                             </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

3. กลับไปดูที่ไฟล์ *Forms.xml ฟอร์มชื่อ EditBlog มี target="editBlog"
<form name="EditBlog" type="single" target="editBlog" title="" 
            default-map-name="resultMap" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="statusId">
            <drop-down allow-empty="false">
                <entity-options description="${description}" entity-name="StatusItem" key-field-name="statusId">
                <entity-constraint name="statusTypeId" value="CONTENT_STATUS"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="editButton" title="Save" ><submit button-type="button"/></field>
</form

4. ใน controller.xml ทำการสร้าง request-map และสั่งให้มีการการ invoke simple method ชื่อ editBlog ที่ services.xml
<request-map uri="editBlog">
        <security https="true" auth="false"/>
        <event type="service" invoke="editBlog"/>
        <response name="success" type="request-redirect-noparam" value="home"></response>
</request-map>

5. ใน services.xml มีการ invoke editBlog ในไฟล์ *Services.xml
<service name="editBlog" engine="simple" auth="false"
            location="component://myblog/script/com/org/toon/myblog/MyBlogServices.xml" invoke="editBlog">
            <attribute name="newBlogId" mode="INOUT" type="String" optional="false"></attribute>
            <attribute name="newBlogTitle" mode="IN" type="String" optional="false"></attribute>
            <attribute name="newBlogBody" mode="IN" type="String" optional="false"></attribute>
            <attribute name="statusId" mode="IN" type="String" optional="true"></attribute>
</service>

6. สร้าง service ชื่อ editBlog ในไฟล์ MyBlogServices.xml
<simple-method method-name="editBlog" short-description="edit a Blog">
        <entity-one value-field="newData" entity-name="NewBlog" auto-field-map="true"></entity-one>
        <set-nonpk-fields value-field="newData" map="parameters"/>
        <store-value value-field="newData"/>
</simple-metho

7. จบส่วนในการสร้างและเรียกใช้ Service ต่อไปจะทำการ controller ให้เรียก view ที่มีหน้า form ของการ edit new blog มาแสดงผล

8.  เพิ่ม controller ชื่อ EditBlog ใน controller.xml ให้เรียก view ชื่อ CreateBlog มาแสดงผล เมื่อมีการเรียกเข้ามาที่ controller นี้
<request-map uri="EditBlog"><security https="true" auth="false"/>
        <response name="success" type="view" value="EditBlog"/>
    </request-map>

9. สร้าง view ชื่อ EditBlog เรียกฟอร์มการสร้างมาแสดงผล
<view-map name="EditBlog" type="screen" page="component://myblog/widget/MyBlogScreens.xml#EditBlog"/>

10. ทำการ ./startofbiz.sh ใหม่อีกครั้ง แล้วทดลองเแก้ไขข้อมูลลงใน entity

วันอังคารที่ 8 มิถุนายน พ.ศ. 2553

การสร้าง service เพื่อ insert ข้อมูลลงในฐานข้อมูลโดยใช้ simple method

ในการสร้าง service ใน OFBiz นั้น สามารถใช้ engine ในการสร้าง method ได้ 3 วิธี ดังนี้
1. engine="java" ทำได้โดยการเขียนโปรแกรมภาษา java เก็บไว้ในโฟลเดอร์ src แล้วเรียกใช้งานผ่าน package
2. engine="simple" เขียนเป็น simple method เก็บไว้ในไฟล์ *Services.xml
3. engine เป็น webservice

ในบทความนี้จะแสดงการสร้าง service โดยใช้ simple method ในไฟล์ *Services.xml มีวิธีทำดังนี้

1. สร้าง form ชื่อ CreateBlog ที่ *Forms.xml

<form name="CreateBlog" type="single" target="createBlog" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="saveButton" title="Save" ><submit button-type="button"/></field>
</form>

2. include form ชื่อ CreateBlog เข้าไปในไฟล์ *Screens.xml
<screen name="CreateBlog">
        <section>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://myblog/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container id="content">
                            <container id="content-bgtop">
                                <container id="content-bgbtm">
                                    <container style="post">
                                        <include-form location="component://myblog/widget/MyBlogForms.xml" name="CreateBlog"/>
                                    </container>
                                </container>
                            </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

3. กลับไปดูที่ไฟล์ *Forms.xml ฟอร์มชื่อ CreateBlog มี target="createBlog"
<form name="CreateBlog" type="single" target="createBlog" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="saveButton" title="Save" ><submit button-type="button"/></field>
</form>

4. ใน controller.xml ทำการสร้าง request-map และสั่งให้มีการการ invoke simple method ชื่อ createBlog ที่ services.xml

<request-map uri="createBlog">
        <event type="service" invoke="createBlog"/>
        <response name="success" type="request-redirect-noparam" value="blog"></response>
</request-map>

5. ใน services.xml มีการ invoke createBlog ในไฟล์ *Services.xml
<service name="createBlog" engine="simple" auth="false"
            location="component://myblog/script/com/org/toon/myblog/MyBlogServices.xml" invoke="createBlog">
            <attribute name="newBlogId" mode="INOUT" type="String" optional="false"></attribute>
            <attribute name="newBlogTitle" mode="IN" type="String" optional="false"></attribute>
            <attribute name="newBlogBody" mode="IN" type="String" optional="false"></attribute>
            <attribute name="statusId" mode="IN" type="String" optional="true"></attribute>
</service>

6. สร้าง service ชื่อ createBlog ในไฟล์ MyBlogServices.xml
<simple-method method-name="createBlog" short-description="create a Blog">
        <make-value entity-name="NewBlog" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        
        <create-value value-field="newEntity"/>

        <field-to-result field="parameters.newBlogId" result-name="newBlogId"/>
</simple-method>


7.จบส่วนในการสร้างและเรียกใช้ Service ต่อไปจะทำการ controller ให้เรียก view ที่มีหน้า form ของการ create new blog มาแสดงผล

8. เพิ่ม controller ชื่อ CreateBlog ใน controller.xml ให้เรียก view ชื่อ CreateBlog มาแสดงผล เมื่อมีการเรียกเข้ามาที่ controller นี้

<request-map uri="CreateBlog">
        <security https="true" auth="false"/>
        <response name="success" type="view" value="CreateBlog"></response>
</request-map>

9. สร้าง view ชื่อ CreateBlog เรียกฟอร์มการสร้างมาแสดงผล
<view-map name="CreateBlog" type="screen" page="component://myblog/widget/MyBlogScreens.xml#CreateBlog"/>

10. ทำการ ./startofbiz.sh ใหม่อีกครั้ง แล้วทดลองเพิ่มข้อมูลลงใน entity

ในบทความต่อไปจะแสดงการแก้ไขข้อมูลในฐานข้อมูลผ่านการสร้าง service โดยใช้ simple method แบบเดียวกันนี้

การใช้ form widget ใน OFBiz - การสร้าง list form widget

จากบทความที่แล้ว (การใช้ form widget ใน OFBiz - การสร้าง find form widget) ได้ทำการสร้างฟอร์มการค้นหา ขั้นตอนต่อไปจะทำการสร้างฟอร์มที่แสดลผลการค้นหา หรือ list form ดังนี้

1. define form ของการแสดงผลของ list form ในไฟล์ *Forms.xml

<form name="ListExamples" type="list" target="example" default-entity-name="Example" list-name="listIt">
        <actions>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="Example"/>
            </service>
        </actions>
        <auto-fields-entity entity-name="Example" default-field-type="display"/>
    </form>

อธิบายโค้ด
ในส่วนของ actions จะมีการเรียกใช้ service ในไฟล์ services.xml ดังนี้
service-name="performFind" result-map="result" result-map-list="listIt" มีการเรียกใช้ service ชื่อ performFind ซึ่งเป็น service ของ OFBiz ที่สร้างขึ้นมาเพื่อให้เรียกใช้งาน find form ได้

2. ที่ screen ที่ต้องการให้ข้อมูลผลลัพธ์ของการค้นหาแสดงผล ให้เพิ่มโค้ดในส่วนของ actions และ include form ListExamples เข้าไป ดังนี้

<actions>
                <set field="exampleId" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
            </actions>

<include-form location="component://culinary/widget/CulinaryForms.xml" name="ListExamples"/>

โค้ดในส่วนของ screen name="findExample" เมื่อสมบูรณ์แล้ว จะได้ดังนี้

<screen name="findExample">
        <section>
            <actions>
                <set field="exampleId" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://culinary/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container id="content">
                             <container style="post">
                                   <container style="entry">
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample"/>
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="ListExamples"/>
                                   </container>
                             </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
ส่วนของ actions จะทำการประมวลผลก่อน ถึงจะส่งไปให้ในส่วนของ widgets แสดงผลต่อไป
field="exampleId" global="true" ทำการเซ็ตค่าที่ได้จากตัวแปร exampleId ให้เป็น global

entity-one value-field="resultMap" entity-name="Example" ทำการส่งค่าที่ได้จากการค้นหาใน entity ชื่อ Example มาเก็บไว้ในตัวแปรชนิด map ชื่อ resultMap

get-related relation-name="ExampleItem" list="resultList" value-field="resultMap" ทำการลิสต์ item ที่มีความสัมพันธ์กับ entity ชื่อ Example นี้มาแสดงผลทีละ item

entity ชื่อ Example นี้ จะมี entity ชื่อ ExampleItem ที่มีความสัมพันธ์กันแบบ one to many โค้ดในส่วนของ get-related จะช่วยทำการลิสต์ item ใน ExampleItem มาแสดงผล

ยกตัวอย่างความสัมพันธ์เหล่านี้ เช่น ในการออกรายงานในแต่ละครั้ง การแสดงผลของรายงานจะมีส่วนหัวที่ประกอบไปด้วย ที่อยู่บริษัทหรือวันที่ต่างๆ และส่วนของ item ที่ต้องการโชว์ในรายงาน

ส่วนหัวของรายงานเปรียบได้กับ entity ชื่อ Example ที่มี entity ชื่อ ExampleItem มามีความสัมพันธ์ด้วย เพื่อเรียกใช้ส่วนหัวของรายงาน นั่นหมายความว่า หัวรายงาน 1 หัวรายงาน สามารถแสดง item ใน entity ชื่อ ExampleItem ได้หลายไอเท็มนั่นเอง ซึ่งคำสั่งนี้จะทำการลิสต์ไอเท็มที่ต้องการแสดงภายใต้หัวรายงานออกมาทั้งหมด

เมื่อจบในส่วนของ actions แล้ว จึง include เพื่อเรียกใช้งาน form ชื่อ ListExamples มาแสดงผลต่อจากส่วน FindExample

3. ทำการทดลองค้นหาผ่าน url http://localhost:8080/culinary/control/example จะพบว่า เมื่อกดปุ่ม Search แล้ว ผลลัพธ์ในการค้นหาจะแสดงต่อจาก find form ทางด้านล่าง

การใช้ form widget ใน OFBiz - การสร้าง find form widget

ใน OFBiz สามารถนำ form แสดงผลใน screen ได้ โดย form ที่นำมาแสดง สามารถแบ่งประเภทได้ดังนี้
1. find form เป็นฟอร์มที่ใช้ค้นหา item หรือ content ต่างๆ ใน module
โดย form ชนิดนี้จะมี type เป็น single


2. list form เป็นฟอร์มที่ใช้แสดงรายการ โดยจะลิสต์แสดงรายการออกมาเป็น table
form ชนิดนี้จะมี type เป็น list


3. display and edit เป็นฟอร์มที่ใช้แสดงรายการแก้ไข โดยจะสามารถแก้ไขข้อความใน field ที่อนุญาตให้แก้ไขได้ หากต้องการให้ field ไหนแก้ไขได้ สามารถ เซ็ต type เป็น input หรือ textbox หรือแล้วแต่ชนิดของ field ที่ต้องการแก้ไข แต่หากไม่ต้องการให้สามารถแก้ไขได้ ให้เซ็ต type เป็น display จะเป็นการสั่งให้แสดงผลเท่านั้น แต่ไม่สามารถแก้ไขได้



ขั้นตอนการสร้าง find form widget สามารถทำได้ดังนี้

1. ทำการ define form เข้าไปในไฟล์ *Form.xml ดังนี้
หมายเหตุ *Form.xml คือชื่อของ Component ต่อด้วย Form.xml จะอยู่ในโฟลเดอร์ widget

<form default-entity-name="Example" name="FindExample" target="example" type="single">
<auto-fields-entity default-field-type="find" entity-name="Example">
        <field name="noConditionFind"><hidden value="Y"></hidden>
        <field name="searchButton" title="Search"><submit button-type="button"></submit>
    </field></field></auto-fields-entity></form>

อธิบายโค้ด
form name="FindExample" ตั้งชื่อฟอร์มว่า  FindExample
type="single" target="example" ให้เป็นชนิด single และ route ไปที่ example controller
default-entity-name="Example" ชื่อ entity ที่เรียกใช้ข้อมูลคือ Example

auto-fields-entity entity-name="Example" ทำการเรียกข้อมูลใน entity ชื่อ Example มาแสดงโดยอัติโนมัติทุก field โดยที่ไม่ต้องระบุชื่อฟิลด์
default-field-type="find" ระบุชนิดของ field ใน form นี้ให้เป็น find

field name="searchButton" title="Search"
submit button-type="button"เพิ่มปุ่ม Search ให้ฟอร์มนี้

2. ทำการเรียก form ที่ define ไว้ใน *Form.xml มาแสดงผลใน *Screen.xml
<screen name="findExample">
        <section>
            <widgets>
                <decorator-screen location="component://culinary/widget/CommonScreens.xml" name="CommonDecorator">
                    <decorator-section name="body">
                        <container id="content">
                             <container>
                                   <container>
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample">
                                   </include-form>
                             </container>
                        </container>
                    </container>
                </decorator-section>
            </decorator-screen>
        </widgets>
    </section></screen>
อธิบายโค้ด
include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample" ทำการ include form ชื่อ FindExample ไปแสดงผลที่ screen widget ที่ชื่อ findExample

3. ทำการกำหนด request-map ให้กับไฟล์ controller.xml

<request-map uri="example">
        <security auth="true" https="false">
        <response name="success" type="view" value="example"></response>
    </security>
</request-map>

4.สร้าง view ให้กับ example controller

<view-map name="example" page="component://culinary/widget/CulinaryScreens.xml#findExample" type="screen"></view-map>

5. ทดลองเรียกใช้ url http://localhost:8080/culinary/control/example จะปรากฏ find form ดังนี้

ซึ่งฟอร์มนี้จะแสดงเฉพาะฟอร์มการค้นหา ไม่สามารถแสดงผลการค้นหาได้ เนื่องจากยังไม่กำหนด actions ให้กับ screen
ในบทความต่อไปจะแสดงผลลัพธ์จากการค้นหาที่ต่อเนื่องจากการสร้างฟอร์มในบทความนี้

การดึงข้อมูลจาก Entity มาแสดงผลในหน้าเพจ

OFBiz สามารถเรียกข้อมูลจาก Entity มาแสดงผลในหน้าเวบเพจได้ 2 วิธี คือ
1. ดึงจาก Screen หรือ Widget
2. ดึงจาก Script

ในบทความจะแสดงการดึงค่าจาก Widget ดังนี้
1. เพิ่มแท็ก <action> ลงภายใต้แท็ก <screen><section> ในไฟล์ CulinaryScreens.xml ในโฟลเดอร์ widget
หมายเหตุ: ชื่อไฟล์ CulinaryScreens.xml ตาม component ชื่อ culinary หากทำการสร้าง component ชื่ออื่น ให้ทำการแก้ไขที่ไฟล์ ชื่อคอมโพเน้นท์Screens.xml
ดังนี้

<actions>
                <set field="exampleId" value="10000" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
</actions>

อธิบายโค้ด

<set field="exampleId" global="true" value="10000">
</set>
ทำการเลือก record มาแสดงผล โดยทำการเลือก record ที่มี exampleId = 10000 และทำการเซ็ตให้มีค่าเป็น Global


<entity-one value-field="resultMap" entity-name="Example"></entity-one>
เก็บผลลัพธ์ (record) ที่ได้จากบรรทัดแรกมาเก็บในตัวแปร resultMap

<get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
ดึง item ที่มีความสัมพันธ์กับ exampleId = 10000 มาเก็บไว้ใน list ชื่อ resultList

2. ที่หน้า view ของ home เพิ่มโค้ดดังนี้

<#list resultList as resultItem>
    ${resultItem.description}<br />
</#list>

อธิบายโค้ด
ใช้แท็ก FreeMarker มาช่วยในการแสดงผล โดยทำการ list ค่าของ ExampleItem ทั้งหมดที่อยู่ใน resultList มาแสดงผลทีละไอเทม

3. ทดลองเปิดหน้าเว็บไซต์ดู

วันจันทร์ที่ 7 มิถุนายน พ.ศ. 2553

การสร้างและการเรียกใช้งาน Screen Decorator ใน OFBiz

ในการสร้างหน้าเพจ มักจะมีส่วนของการแสดงผลที่ซ้ำๆ กัน เช่น ส่วนของ menu, header, footer เป็นต้น ซึ่งใน OFBiz จะมีการสร้าง Screen Decorator ไว้สำหรับเป็น template และหากมีการเปลี่ยนแปลงเฉพาะส่วนย่อยๆ จะเปลี่ยนเฉพาะ Screen บางส่วนเท่านั้น ซึ่งในการสร้าง Screen Decorator สามารถสร้างได้ดังนี้

1. ในเทมเพลนมีส่วนที่ซ้ำกันทุกหน้าคือ header และ footer ให้ทำการแยกโค้ดในส่วนของ header และ footer เก็บไว้ในเพจ .ftl เช่น header.ftl และ footer.ftl
2. โค้ดในส่วนที่เหลือจาก header.ftl และ footer.ftl ให้เซฟเก็บไว้เป็นไฟล์ index.ftl
3. เปิดไฟล์ CommonScreens.xml ซึ่งจะอยู่ในโฟลเดอร์ hot-deploy/culinary/widget/CommonScreens.xml
4. ทำการสร้าง Screen สำหรับที่จะใช้เป็น template ภายใต้แท็ก <screens></screens> ดังโค้ดต่อไปนี้

<screen name="CommonDecorator">
        <section>
            <widgets>
                <!-- header section -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/header.ftl"/>
                    </html>
                </platform-specific>
                <decorator-section-include name="body"/>
                <!-- right -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/right.ftl"/>
                    </html>
                </platform-specific>
                <!-- footer section -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/footer.ftl"/>
                    </html>
                </platform-specific>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
 <screen name="CommonDecorator"> ตั้งชื่อ screen นี้ว่า CommonDecorator

<platform-specific>
      <html>
              <html-template location="component://culinary/webapp/culinary/includes/header.ftl"/>
      </html>
</platform-specific>
ดึงไฟล์ header.ftl มาเป็นส่วนหนึ่งของเทมเพลต


<decorator-section-include name="body"/>
เตรียมพื้นที่ไว้รอแสดงส่วนเนื้อหาจากหน้าอื่น

<platform-specific>
    <html>
        <html-template location="component://culinary/webapp/culinary/includes/footer.ftl"/>
    </html>
</platform-specific>
ดึงไฟล์ header.ftl มาเป็นส่วนหนึ่งของเทมเพลต

เมื่อเสร็จขั้นตอนนี้ จะได้ เทมเพลตที่ประกอบไปด้วยส่วน header และ footer ที่ไม่มีการเปลี่ยนแปลงของ screen และมีส่วน body ที่ define ไว้รอสำหรับการนำเอาเนื้อหาที่มีการเปลี่ยนแปลงในแต่ละหน้ามาแสดงผล

5. ในโฟลเดอร์ widget จะมีไฟล์ xml ที่ใช้จัดการกับ screen อีก 3 ไฟล์ ซึ่งจะมี 1 ไฟล์ที่ชื่อเดียวกับชื่อ component เช่น ถ้า component ชื่อ culinary ไฟล์นี้จะชื่อ CulinaryScreens.xml ทำการเปิดไฟล์นี้และเพิ่มโค้ดดังนี้

<screen name="home">
        <section>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://culinary/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <platform-specific>
                            <html>
                                <html-template location="component://culinary/webapp/culinary/home.ftl"/>
                            </html>
                        </platform-specific>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
<decorator-screen location="component://culinary/widget/CommonScreens.xml" name="CommonDecorator">
ตั้งชื่อ screen ว่า CommonDecorator และ url ของ screen นี้ถูกกำหนดลงใน location

<decorator-section name="body">
    <platform-specific>
        <html>
            <html-template location="component://culinary/webapp/culinary/home.ftl"/>
        </html>
    </platform-specific>
</decorator-section>
อธิบายโค้ด
ในส่วน decorator-section ชื่อ body ให้เรียกไฟล์ home.ftl มาแสดงผล

6. ทำการกำหนด controller และ view ในไฟล์ webapp/culinary/WEB-INF/controller.xml ดังนี้

<request-map uri="home">
<security https="false" auth="true"/>
<response name="success" type="view" value="home"/></request-map>
<view-map name="home" type="screen" page="component://culinary/widget/CulinaryScreens.xml#home"/>

7. ทดสอบเรียกหน้า home ขึ้นมาแสดงผล

การติดตั้ง OFBiz โดยใช้ PostgreSQL เป็นฐานข้อมูล

PostgreSQL คือ ระบบจัดการฐานข้อมูลเชิงสัมพันธ์ (Object-Relational DataBase Management System หรือ ORDBMS) มีความสามารถในการทำงานร่วมกับ OFBiz ได้อย่างดี ทั้งนี้ยังเป็นซอฟต์แวร์ฟรีอีกด้วย จึงสามารถนำมาช่วยลดค่าใช้จ่ายในองค์กรได้

จากบทความเรื่องการติดตั้ง OFBiz ได้ใช้ฐานข้อมูล Derby ซึ่งเป็นฐานข้อมูลขนาดเล็กที่มาพร้อม OFBiz มีความสามารถในระดับหนึ่ง แต่ไม่เทียบเท่า PostgreSQL และไม่สามารถรองรับการใช้งานที่มีการเรียกใช้ฐานข้อมูลจำนวนมากได้ จึงได้นำเอา PostgreSQL มาช่วยให้การใช้งาน OFBiz มีประสิทธิภาพมากขึ้น

ขั้นตอนการติดตั้ง PostgreSQL สำหรับ OFBiz ทำได้ดังนี้

1. ติดตั้ง PostgreSQL จาก Synaptic Package Manager
2. ติดตั้ง pgadmin จาก Synaptic Package Manager
3. ทำการตั้งค่า password ให้กับ account ของ PostgreSQL โดยเปิด terminal และเข้าไปที่โฟลเดอร์ /etc/postgresql/8.4/main
4. สั่งแก้ไขไฟล์ชื่อ pg_hba.conf โดยใช้คำสั่ง
    sudo gedit pg_hba.conf
5. เปลี่ยนค่าจาก ident เป็น trust ทั้งหมด และ เปลี่ยนค่าจาก md5 เป็น trust ทั้งหมด
6. สั่งแก้ไขไฟล์ชื่อ postgresql.conf โดยใช้คำสั่ง
sudo gedit postgresql.conf 
7. แก้ไขบรรทัด #listen_addresses = 'localhost' โดยการเอา # ออกและเปลี่ยนจาก localhost เป็น * จะได้โค้ดดังนี้
listen_addresses = '*'   
8. สั่ง start serveice ของ postgresql โดยใช้คำสั่ง
cd /etc/init.d
9. สั่ง restart service โดยใช้คำสั่ง
sudo service postgresql-8.4 restart

เมื่อตั้งค่าเสร็จแล้ว ลงมือทำการสร้าง connection ดังนี้
1. เปิด pgadmin
2. กดปุ่ม add a connection to a server
3. ตั้งค่าดังนี้
    Name = localhost
    Host = localhost
แล้วกด ok
4. ทำการสร้าง login role ให้แก่ database โดยการคลิ้กขวาที่ Login Roles แล้วเลือก New Login Role
5. กรอกรายละเอียด Role name, Password และ Password(again) แล้วกด OK
6. ในการสร้างฐานข้อมูลสำหรับ OFBiz ต้องสร้างทั้งหมด 3 database โดยกำหนดดังนี้
    Database1
        name = ofbiz
        login role = ofbiz
    Database2
        name = ofbizolap
        login role = ofbiz
    Database3
        name = ofbiztenance
        login role = ofbiz
7. ทำการดาวน์โหลด jdbc driver สำหรับ postgresql โดยสามารถดาวน์โหลดได้ที่ http://jdbc.postgresql.org/download.html
เลือกดาวน์โหลดไฟล์ JDBC4 Postgresql Driver, Version 8.4-701 สำหรับ 1.6 JVM ขึ้นไป
8. ทำการ copy ไฟล์ที่ดาวน์โหลดไปไว้ในโฟลเดอร์ framework/entity/lib/jdbc ของโปรเจ็ค
9. ทำการแก้ไขไฟล์ framework/entity/config/entityengine.xml โดยการเพิ่ม datasource ดังนี้
<datasource name="localpostnew"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/org"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>
    
    <datasource name="localpostnewolap"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/orgolap"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>
    
    <datasource name="localpostnewtenant"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/orgtenant"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>

และแก้ไข delegetor ของ delegator name="default" และ delegator name="default-no-eca" ดังนี้

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostnewolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localpostnewtenant"/>
    </delegator>
    <delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostnewolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localpostnewtenant"/>
    </delegator> 

10. พิมพ์คำสั่งใน terminal ดังนี้
./ant clean-all
11. พิมพ์คำสั่งใน terminal ดังนี้
./ant run-install
12. สั่ง start ofbiz ดังนี้
./startofbiz.sh

การใช้ Subversion ในการควบคุม Source Code

ในการสร้างโปรเจ็ค ควรจะทำการควบคุม source code เพื่อป้องกันความผิดพลาดจากการลบไฟล์โดยไม่ได้ตั้งใจ และเพื่อสามารถย้อนกลับไปใช้ซอร์สโค้ดเดิมได้ หากมีข้อผิดพลาดเกิดขึ้นกับ souce code เวอร์ชั่นไหม่

ในบทความจะแสดงวิธีการใช้งาน Subversion (svn) ควบคุม source code บนพื้นที่ฟรีเช่น google code สามารถทำได้ดังนี้

1. เปิดเว็บไซต์กูเกิ้ลโค้ด โดยเข้าไปที่ http://code.google.com
2. เลือก Project Hosting
3. เลือก Project Hosting on Google Code
4. ทำการ sign in เข้าใช้งาน โดยใช้ account ของ google หรือ gmail
5. ทำการสร้างโปรเจ็คโดยการเลือก Create a new project
6. ในหน้า Create Project ให้กำหนดรายละเอียดของโปรเจ็ค โดยกำหนดเพิ่มเติมดังนี้
Version control system: เลือก subversion
Source code license: เลือก Apache License 2.0
Use a separate content license: เลือก Creative Common 3.0 BY
Project labels: ใส่ tag ที่เกี่ยวข้องกับโปรเจ็ค
7. กดปุ่ม Create Project
8. เมื่อสร้างโปรเจ็คแล้ว กดแท็บ Source จะได้คำสั่งในการ checkout code
9. ทำการก็อปปี้คำสั่งไปวางใน terminal และกด enter เพื่อทำการ check out code ลงมาที่เครื่อง
10. เมื่อ check out ลงมาแล้ว หากต้องการดูข้อมูลของโปรเจ็ค ให้พิมพ์ svn info
11. ทดลองทำการเพิ่มไฟล์ลงในโปรเจ็ค เสร็จแล้วพิมพ์ svn st เพื่อดูสถานะ ที่ terminal จะแสดงค่า
? test.txt
หมายความว่า ไฟล์ที่เครื่องคอมพิวเตอร์ไม่ตรงกับไฟล์บน google code
12. หากต้องการทำการนำไฟล์นี้ขึ้นไปบน google code ให้ใช้คำสั่ง
svn add ชื่อไฟล์หรือโฟลเดอร์ เช่น
svn add test.txt
เพื่อทำการเพิ่มไฟล์เข้าไปในระบบ
13. เมื่อทำการ add แล้ว status ของไฟล์จะเป็น A ซึ่งหมายความว่า add ไฟล์นี้เข้าสู่โปรเจ็คแล้ว แต่ยังไม่ได้อัพโหลดขึ้นบน google code
หากต้องการนำโค้ดขึ้นไปบนโฮสต์ให้ใช้คำสั่ง
svn commit -m"ข้อความที่ต้องการอธิบาย" เช่น
svn commit -m"my first commit"
เพื่อทำการ commit file ขึ้นไปบนโฮสต์ แล้วกด enter
10. เมื่อมีการแสดงข้อความร้องขอให้ใส่พาสเวิร์ดบน terminal ให้กลับไปที่หน้า source ของ google code แล้วกดที่ข้อความ
When prompted, enter your generated googlecode.com password กูเกิ้ลโค้ดจะทำการสร้างพาสเวิร์ดให้ และก๊อปปี้พาสเวิร์ดนั้นไปใส่ใน terminal
11. svn จะทำการ commit ไฟล์ขึ้นสู่ google code และจะแสดง Committed revision 2 หมายถึงได้เพิ่มโค้ดเรียบร้อยแล้ว

คำสั่งของ svn ที่ใช้บ่อย จะมีดังนี้
svn checkout หรือ svn co สั่งให้ check out source code จากโฮสต์ลงมาเก็บไว้ในเครื่อง
svn add เมื่อมีการสร้างไฟล์หรือไดเร็คทอรี่ คำสั่งนี้จะเป็นการบอกให้ svn ทราบว่ามีการเพิ่มไฟล์เข้าไปในโปรเจ็ค แต่จะยังไม่ทำการอัพโหลดขึ้นไปยังโฮสต์ จนกว่าจะสั่ง svn commit
svn delete คำสั่งนี้จะเป็นการบอกให้ svn ทราบว่ามีการเพิ่มไฟล์ลบไฟล์ออกจากโปรเจ็ค และจะทำการลบไฟล์บนโฮสต์ทันทีที่สั่ง svn commit
svn status เช็คสถานะของไฟล์และโฟลเดอร์ ว่าอยู่ในสถานะไหน สถานะต่างๆ เช่น
A(Add), M(Commit), G(Merge), U(Update)
svn update หรือ svn up จะทำการ sync ไฟล์และโฟลเดอร์ในเครื่องกับบนโฮสต์ให้ตรงกัน
svn commit เป็นการสั่งนำไฟล์ขึ้นไปเก็บไว้บนโฮสต์

โดยคำสั่งที่จำเป็นของ svn สามารถศึกษาเพิ่มเติมได้ ดังนี้
http://www.linuxfromscratch.org/blfs/edguide/chapter04.html
http://oslc.wordpress.com/2007/01/20/subversion-basic-work-cycle-command-line/

วันศุกร์ที่ 4 มิถุนายน พ.ศ. 2553

การนำเอา FreeMarker Template Engine มาใช้ใน OFBiz

FreeMarker เป็น Template Engine ที่ใช้แนวคิด MVC เพื่อแยกส่วนแสดงผลออกจากส่วน source ของ java สามารถศึกษารายละเอียดเพิ่มเติมได้ที่ http://freemarker.sourceforge.net/

ในบทความจะแสดงตัวอย่างในการนำเอา freemarker มาใช้งานใน OFBiz project

โดยปกติแล้วหน้าเพจมักจะมีส่วนที่ซ้ำซ้อนกันที่ต้องแสดงทุกหน้า อย่างเช่น เมนู, วันที่ ฯลฯ เราสามารถ assigned ค่าให้กับค่าตัวแปรที่มีการแสดงผลซ้ำๆ กัน แล้วเก็บไว้ที่ไฟล์อื่น เพื่อความง่ายในการแก้ไขหากต้องมีการเปลี่ยนค่า ไม่ต้องเปลี่ยนทุกหน้า แต่เปลี่ยนที่ไฟล์ที่ assigned ค่าไว้แค่ไฟล์เดียว

หรืออีกประโยชน์หนึ่ง เพื่อให้หน้าเพจมีการเขียนโค้ดที่สั้นลง เนื่องจากโค้ดที่ซับซ้อนถูกกำหนดไว้ที่ไฟล์อื่น สามารถลดความยากในการอ่านโค้ดในเพจนั้นได้

ทดลองทำตามขั้นตอนดังนี้
1. สร้างไฟล์ .ftl ใหม่ใน webapp ของโปรเจ็ค ชื่อ configtemplate.ftl
2. เพิ่มโค้ดใน configtemplate.ftl ดังนี้









อธิบายโค้ด

<#macro category> สร้าง macro โดยกำหนดชื่อ macro ว่า category

3. ในหน้า testpage.ftl ทำการเรียก macro ชื่อ category ดังนี้
<#import "component://testtest/webapp/testtest/configtemplate.ftl" as myconf>
<@myconf.category />

อธิบายโค้ด
<#import "component://testtest/webapp/testtest/configtemplate.ftl" as myconf> ทำการ import ไฟล์ที่กำหนด macro ไว้ แล้วตั้ง alias ว่า myconf
<@myconf.category /> เรียกใช้ macro ชื่อ category ผ่าน alias myconf

4. ทดสอบเรียกหน้าเพจมาแสดงผล


ทดลองทำการ assigned string ลงในไฟล์ ดังนี้
1. ในหน้า configtemplate.ftl เพิ่มโค้ดดังนี้
<#assign addtext="test add string in template">
2. ในหน้า testpage.ftl ทำการเรียกใช้ตัวแปรที่ assigned ดังนี้
${myconf.addtext}
3. ทดสอบเรียกหน้าเพจมาแสดงผล


FreeMarker ยังสามารถสร้างและแสดง template ได้อีกหลายวิธี ให้ทดลองอ่าน Online Documentation ได้ที่เว็บไซต์ http://freemarker.sourceforge.net/docs/index.html

การเพิ่ม page ใน OFBiz

webapp ของ OFBiz อาศัยหลักการ MVC หรือ Model-View-Controller ในการแสดงผล โดยแยกออปเจคที่เก็บข้อมูล (model) ออปเจคที่แสดงข้อมูล (view) และออปเจคที่ติดต่อกับผู้ใช้ (controller) ออกจากกันอย่างชัดเจน โดย webapp ใน OFBiz จะมีไฟล์ชื่อ controller.xml ในโฟลเดอร์ WEB-INF เป็นตัวกำหนดว่าจะเรียก view ไหนขึ้นมาแสดงผล เมื่อถูก request ผ่านทาง url

ทดลองสร้าง views ขึ้นมาใน webapp ของ component โดยสร้างไฟล์ชนิด ftl ดังนี้
หมายเหตุ ftl เป็นไฟล์ชนิด free marker template engine

1. เลือก File > New > Others > Web > Html page
2. ตั้งชื่อไฟล์ เช่น testpage จะได้ไฟล์ testpage.html
3. ทำการ rename นามสกุลไฟล์เป็น .ftl จะได้ไฟล์ testpage.ftl
4. ในไฟล์ controller.xml ทำการสร้าง request-map ดังนี้

<request-map uri="testpage">
    <security auth="true" https="false">
        <response name="success" type="view" value="testpage"></response>
    </security>
</request-map>

อธิบายโค้ด

<request-map uri="testpage"></request-map>

ทำการเซ็ตค่าว่า ถ้าหาก uri ชื่อ testpage ถูก request ผ่าน webapp มา จะให้ทำอะไรบ้าง



security https="false" กำหนดให้ ไม่สามารถเรียกผ่าน https protocol ได้
auth="true" กำหนดให้ต้องมีการ login ก่อน ถึงจะสามารถเรียกใช้ page นี้ได้


response name="success" เมื่อมีการ success ในการเรียกใช้เพจนี้
type="view" ชนิดของ object ที่จะเรียกให้แสดงผลเมื่อถูก request url นี้เป็นชนิด view
value="testpage" ชื่อของ view ที่จะถูกเรียกมาแสดงผล

5. เมื่อทำการเพิ่ม view map ดังนี้



อธิบายโค้ด
view-map name ="testpage" ชื่อของ view นี้
type="ftl" เป็นชนิด ftl
page="component://testtest/webapp/testtest/testpage.ftl" uri ของ view นี้

6. ทดลองเรียกใช้ page ที่สร้างขึ้น โดยเรียกผ่าน url

https://localhost:8443/testtest/control/testpage

เอกสารอ้างอิง
http://www.narisa.com/forums/index.php?showtopic=1036
http://freemarker.sourceforge.net/

วันพฤหัสบดีที่ 3 มิถุนายน พ.ศ. 2553

การสร้าง Component ใน OFBiz

ในการพัฒนา OFBiz จะเรียกการสร้าง application หรือ module ว่า component โดยแต่ละ component จะเป็นอิสระต่อกัน และแต่ละ component จะมี data model, views, controller เป็นของ component เอง แต่สามารถทำงานร่วมกับ component อื่นได้

component หลักของ OFBiz จะอยู่ใน folder ชื่อ applications ส่วน component ที่ถูกสร้างขึ้นจะถูกสร้างไว้ในโฟลเดอร์ hot-deploy โดยขั้นตอนในการสร้าง component สำหรับ OFBiz มีดังนี้
1. เปิด Terminal แล้วเข้าไปยัง folder ที่มีการรัน OFBiz
2. ทำการเรียก ant ให้สร้าง component โดยใช้คำสั่งดังนี้
./ant create-component
3. ant จะให้ตั้งค่าต่างๆ ของ component รูปแบบดังนี้
- ชื่อ component รูปแบบดังนี้ Component name: (e.g. mycomponent)
- Component resource name รูปแบบดังนี้ Component resource name: (e.g. MyComponent)
- ชื่อ web application รูปแบบดังนี้ Webapp name: (e.g. mycomponent)
- Base permission รูปแบบดังนี้ Base permission: (e.g. MYCOMPONENT)
4. เมื่อกำหนดค่าทั้งหมดแล้ว ant จะให้ confirm สิ่งที่ตั้งค่าไป เมื่อถูกต้องทั้งหมดแล้วกด y เพื่อยืนยัน ant จะเริ่มทำการสร้าง component ให้
5. ทดสอบการสร้าง component โดยลองเรียกผ่านทาง web browser ดังนี้
https://localhost:8443/ชื่อคอมโพเน้นท์/control/main หรือ
http://localhost:8080/ชื่อคอมโพเน้นท์

เมื่อสร้าง component เสร็จแล้ว จะยังไม่สามารถล็อกอินเข้าใช้คอมโพเน้นท์ได้ ให้ทำการแอด data security ให้กับ component ก่อน มีขั้นตอนดังนี้
1. login เข้าไปใน webtools ของ OFBiz ที่ได้ติดตั้งไว้ ตาม url ดังนี้
https://localhost:8443/webtools/control/main หรือ
https://localhost:8080/webtools
2. ค่า default ของการ login เข้าใช้งาน OFBiz ดังนี้
username = admin
password = ofbiz
3. ในการ import data security เข้าไปใน webtools สามารถทำได้หลายวิธี ดังนี้
วิธีที่ 1 import security data xml file
3.1.1 เลือก XML Data Import ใน webtools
3.1.2 ใส่ค่า absolute path ของ security data file ลงในช่อง Absolute Filename or URL: เช่น
/home/toonztudio/Desktop/projects/ofbiz.10.04/hot-deploy/testtest/data/TestTestSecurityData.xml

หมายเหตุ: ไฟล์ security data จะอยู่ในโฟลเดอร์ hot-deploy/ชื่อคอมโพเน้นท์/data/ชื่อ Component resource name ต่อด้วย SecurityData.xml

3.1.3 กดปุ่ม Import file
3.1.4 หากขึ้นข้อความว่าไฟล์ถูกอิมพอร์ตเข้าไปแล้ว และไม่มี error แสดงว่าการนำเข้า security data สำเร็จ ดังนี้
Results:
Got 12 entities to write to the datasource.
วิธีที่ 2 import xml element
3.2.1 เลือก XML Data Import ใน webtools
3.2.2 เปิดไฟล์ SecurityData.xml แล้ว copy element ระหว่าง ลงในช่อง Complete XML document (root tag: entity-engine-xml):
3.2.3 กดปุ่ม import text
3.2.4 หากไม่มี error แสดงว่าสามารถนำเข้าได้ทั้งหมด
Results:
Got 12 entities to write to the datasource.

วิธีที่ 3 XML Data Import Dir
3.3.1 เลือก XML Data Import ใน webtools
3.3.2 ใส่ค่า absolute path ของ data directory ลงในช่อง Absolute directory path: เช่น
/home/toonztudio/Desktop/projects/ofbiz.10.04/hot-deploy/testtest/data

3.3.3 กดปุ่ม import file หากไม่มี error แจ้งว่า fail แสดงว่าการนำเข้าสำเร็จ

เมื่อทำการเพิ่ม data security ให้กับ component นี้แล้ว แอคเคาท์ admin จะสามารถ login เข้าใช้งาน component นี้ได้ ทดสอบได้โดยการ login เข้าไปใน url ดังนี้
https://localhost:8443/ชื่อคอมโพเน้นท์/control/main หรือ
http://localhost:8080/ชื่อคอมโพเน้นท์

เมื่อล็อกอินเข้ามาแล้วจะพบหน้า OFBiz ว่าง ซึ่งต้องทำการเซ็ต controller ของ webapp ใน component ของ OFBiz ให้เรียก views มาแสดงผลได้ ซึ่งจะแสดงในบทความต่อไป

วันพุธที่ 2 มิถุนายน พ.ศ. 2553

Linux, OFBiz and Eclipse Installation

ที่ Orange Gears พัฒนาและทำการปรับแต่ง OFBiz ให้ตรงกับความต้องการของลูกค้า โดยใช้สิ่งแวดล้อมในการพัฒนาคือ
1. Ubuntu Linux
2. Eclipse IDE
3. Subversion
4. Sub Java 1.5+ SDK
5. PostgreSQL
6. Apache OFBiz ERP

Linux Installation for OFBiz Development มีขั้นตอนดังนี้
1. ดาวน์โหลด Ubuntu Linux เวอร์ชั่น 10.04 จากเว็บไซต์ http://www.ubuntu.com/
2. install ubuntu 10.04 และอัพเดตไฟล์ที่จำเป็นของระบบ (Update Manager)
3. install JAVA SDK 1.5+
3.1 หากในระบบมีการลง Open Java ไว้อยู่แล้ว ให้ทำการเซ็ตให้ Sun Java กลายเป็น default jvm ของระบบ สามารถทำได้โดยใช้คำสั่งใน terminal ดังนี้

sudo update-alternatives --config java


Eclipse Installation
การติดตั้ง Eclipse สามารถทำได้ 2 วิธี ดังนี้
1. Download Eclipse IDE for Java and Report Developers (221 MB) เวอร์ชั่น Linux 32bit จากเว็บไซต์ eclipse.org แล้วทำการ extract เพื่อทำการเรียกใช้โปรแกรม
2. ติดตั้งจาก Synaptic Package Manager ของ Ubuntu โดยตรง

เมื่อทำการติดตั้ง Eclipse แล้ว ต้องทำการติดตั้ง Plug-ins เพิ่มเติม โดย Plug-ins ที่ต้องติดตั้งเพิ่ม มีดังนี้
1. Subclipse จากเว็บไซต์ http://subclipse.tigris.org/
2. Groovy จากเว็บไซต์ http://groovy.codehaus.org/
3. JBoss Tools เลือกเฉพาะ plug-ins ชื่อ FreeMarker จากเว็บไซต์ http://www.jboss.org/tools


เอกสารอ้างอิง
http://www.eclipse.org/downloads/
https://help.ubuntu.com/community/Java
http://subclipse.tigris.org/
http://groovy.codehaus.org/
http://www.jboss.org/tools

วันอังคารที่ 1 มิถุนายน พ.ศ. 2553

Apache OFBiz ERP/Framework


ERP
เป็นการวางแผนการจัดการทรัพยากรขององค์กร เพื่อให้สามารถจัดการทรัพยากรของระบบให้มีประสิทธิภาพและเกิดประโยชน์สูงสุดต่อองค์กร

โดยทั่วไปในองค์กรมักจะใช้ซอฟต์แวร์สำเร็จรูปในการจัดการข้อมูลในองค์กร ทำให้เกิดความไม่เป็นอันหนึ่งอันเดียวกัน และข้อมูลไม่เป็นรูปแบบเดียวกัน เมื่อมีความต้องการจะนำเอาข้อมูลมาใช้ ความหลากหลายของซอฟต์แวร์ทำให้เกิดความไม่สะดวกในการเรียกข้อมูล ก่อให้เกิดความล่าช้าในการแข่งขันในธุรกิจยุคปัจจุบัน

ดังนั้นจึงมีแนวคิดที่จะนำเอาการวางแผนการจัดการทรัพยากรขององค์กร หรือ ERP มารวมกับระบบสารสนเทศ เพื่อรวบรวมข้อมูลทั้งหมดในองค์กรให้เป็นระบบเดียวกัน ส่งผลให้ง่ายต่อการเรียกใช้ข้อมูล, การควบคุมข้อมูล และข้อมูลทั้งหมดสามารถเชื่อมโยงกันได้อย่างทันเหตุการณ์ (real time)

OFBiz
เป็น Open Source Software ที่ช่วยให้องค์กรหรือธุรกิจสามารถวางแผนการใช้งานทรัพยากรให้เกิดประโยชน์สูงสุด โดยสามารถเชื่อมต่อกับทุกระบบ หรือเชื่อมต่อระบบสำคัญๆ ในองค์กร ช่วยให้ผู้ที่มีความสามารถเข้าถึงข้อมูลใช้ประโยชน์จากข้อมูลที่เชื่อมโยงกันได้อย่างทันเหตุการณ์ (real time)

OFBiz มาจากคำว่า Open For Business อยู่ภายใต้การดูแลของ Apache Foundation ซึ่งมี Developer จากทั่วโลกมาช่วยกันพัฒนา แล้วแจกจ่ายให้ผู้สนใจนำไปใช้งานและพัฒนาต่อโดยไม่เสียค่าใช้จ่าย แต่อยู่ภายใต้เงื่อนไขของ Open Source Software

OFBiz ประกอบด้วยแอพพลิเคชั่นที่ช่วยในการทำงานหลายด้าน เช่น Customer Relationship Management(CRM), Human Resource Management(HRM), Supply Chain Management(SCM), Purchase Management, Inventory, Sales Management, IT Management, Production Management, Data Analysis/Report เป็นต้น

ปัจจุบันมี Open Source ERP จากหลายบริษัท แต่หลักๆ แล้ว จะแบ่งตาม Framework ที่ใช้เป็นพื้นฐานในการพัฒนาได้ดังนี้

1. Apache OFBiz - ERP ที่นำเอา OFBiz ไปเป็นพื้นฐานในการพัฒนา เช่น Opentabs ERP/CRM, Shared OFBiz, OrangeGears ERP/CRM, Atlassian JIRA, Neogia ERP เป็นต้น
2. Open ERP
3. Compiere - ERP ที่นำเอา OFBiz ไปเป็นพื้นฐานในการพัฒนา เช่น Adempier, Open Bravo, Seree ERP เป็นต้น

องค์ประกอบหลักของ OFBiz
1. Application Component
2. Application Development Framework
3. Application Data Model

โครงสร้างของ OFBiz Framework แบ่งเป็น 3 ส่วน คือ
1. Presentation
2. Business Logic
3. Data

บรรยายสำหรับนักศึกษาฝึกงาน Orange Gears
เมื่อวันที่ 1 มิ.ย. 2553 โดย คุณธนกฤติ วงศ์ยืด

เอกสารอ้างอิง
http://www.slideshare.net/orangegears/apache-ofbiz-erp