2017年3月23日木曜日

[iDempiere 2.1] WebService Schema Update


 iDempiere 2.1 provide Web Service (WS) interfaces over SOAP and REST. The user can use the WS in order to create, update and view the Records in DB Table.

WebService Request XML is managed by XML Schema strictly. I needed to modify this XML Schema, and I researched how to generate Data-binding Java classes to parse Request XML depending on XML Schema.

○ Environment:

[iDempiere]
    Version: 2.1
 [Eclipse]
     Pleiades 4.5 Mars
  [OS]
     Windows 7 SP1

 iDempiere 2.1 uses xmlbeans-2.5.0 to parse Request XML. The Data-binding Java classes are stored in idempiere-xmlbeans-1.0.jar at @WORKSPACE@\org.idempiere.webservices\WEB-INF\lib. I had to re-create idempiere-xmlbeans-1.0.jar after updating XML schema in order to reflect schema change to iDempiere WebService actually. I could use xmlbeans Ant Task to create Data-binding Java classed from XML Schema.

○ Create a Project for idempiere-xmlbeans

    First of all, I created a new eclipse project for idempiere-xmlbeans like the below.


      1. build.xml - Ant build file to create Xmlbeans Data-binding Java classes. It is mentioned later.
      2. idempiere-schema.xsd - Request XML Schema. I found its original file at @WORKSPACE@\org.idempiere.webservices\WEB-INF\xsd and modified and copied it here.
      3. xmlbeans-2.5.0.jar - xmlbeans jar iDempiere 2.1 is using. I found it at @WORKSPACE@\org.idempiere.webservices\WEB-INF\lib and copied it here.

○ Execution of Ant Task to generate Xmlbeans Data-binding Java classes

   I wrote  in build.xml like the below.

<?xml version="1.0" encoding="UTF-8"?>
<project default="xmlbeans_build" name="build">
<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpath="lib/xmlbeans-2.5.0.jar" />
 <target name="xmlbeans_build">
                <xmlbean schema="idempiere-schema.xsd" destfile="idempiere-xmlbeans-1.0.jar"/>
 </target>
</project>
    Then  I execute Ant build by eclipse Ant Runner. I add xmlbean-2.5.0.jar into classpath for Ant like the below.



   Ant showed console messages like the below. I was successful to create the new  idempiere-xmlbeans-1.0.jar file.

  Buildfile: @WORKSPACE@\idempiere-xmlbeans\build.xml
xmlbeans_build:
  [xmlbean] Time to build schema type system: 2.53 seconds
  [xmlbean] Time to generate code: 0.853 seconds
  [xmlbean] Compiling 90 source files to @
HOMEPATH@\AppData\Local\Temp\xbean1594992734447386704.d\classes
  [xmlbean] warning: [options] bootstrap class path not set in conjunction with -source 1.4
  [xmlbean] 1 warning
  [xmlbean] Time to compile code: 5.379 seconds
  [xmlbean] Building jar:
@WORKSPACE@\idempiere-xmlbeans\idempiere-xmlbeans-1.0.jar
BUILD SUCCESSFUL
Total time: 14 seconds

○ Reference:

1. https://xmlbeans.apache.org/





2017年3月10日金曜日

[iDedempiere 2.1] Web Service


 iDempiere 2.1 provide Web Service (WS) interfaces over SOAP and REST. The user can use the WS in order to create, update and view the Records in DB Table.

ModelADService - It can be used for view Records and  Simple Record edition.
CompositeInterface - It can be used for Multiple Record edition.

○ Environment:

[iDempiere]
    Version: 2.1
 [Eclipse]
     Pleiades 4.5 Mars
  [OS]
     Windows 7 SP1

○ Setting Web Service on iDempiere

 The WS is working on iDempiere if iDempiere is installed already. But, "Web Service Security" Record is need to be created to allow the user to access WS on iDempiere. Web Service Security is managed depending on Client as well as other Record in iDempiere. So, Client Admistrator must create Web Service Security Record with the Client in order to allow members in the Client to access WS.
 If you test WS by Garden Client, you don't have to prepare Web Service Security Record by yourself because these exist already. The examples following use
"CreateBPartner".

○SoapUI

 Adempire and iDempiere have test scripts to test WS in org.adempiere.webservice package. Soap UI is the application to test WS over SOAP and REST, which is introduced in Adempiere book in order to execute these test scripts in Adempiere.
 The latest version of Soap UI can be downloaded here. Test scripts in iDempiere are created by former version, but these can be executed by the latest version as well.

○Test WS over SOAP

 Test WS over SOAP can be done by test scripts. 

1. Import SOAP project from the script in iDempiere (%iDempiere_Home%\org.idempiere.webservices\testScripts\iDempiereWebServices-soapui-project.xml)

      


2. Edit SOAP XML.
 Open XML for createData

And edit the following fields under "_0:ADLoginRequest" to fit your environment if it is needed.
  1. _0:user
  2. _0:pass
  3. _0:ClientID
  4. _0:OrgID
  5. _0:WarehouseID
  6. _0:stage

2. Edit SOAP XML.
3.  Click Submit button to execute the test script.


○Test WS over REST

 iDempiere provides REST interfaces also. the REST provided by iDempiere recieves XML as request, not JSON. The request XML is as same as XML request in SOAP request.
 REST request also can be sent by Soap UI. But, there is no test scripts for REST in iDempiere now. The user need to create project and request record in Soap UI by themselves to execute WS over REST test.

1. Create REST project on Soap UI.
   URL: http://localhost:8080/ADInterface/services/rest/model_adservice/create_data




2.  Create new POST method under new REST project.

3.  Create new Request under POST method.


Set Media Type: application/xml
Set XML following as POST data. edit tags under "_0:ADLoginRequest" tag to fit your environment if it is needed as SOAP test.

<_0:ModelCRUDRequest xmlns:_0="http://idempiere.org/ADInterface/1_0">
 <_0:ModelCRUD>
  <_0:serviceType>CreateBPartner</_0:serviceType>
  <_0:TableName>C_BPartner</_0:TableName>
  <!--<_0:RecordID>0</_0:RecordID>-->
  <!--<_0:Action>Create</_0:Action>-->
  <_0:DataRow>
   <_0:field column="Value">
    <_0:val>GlobalQSS</_0:val>
   </_0:field>
   <_0:field column="Name">
    <_0:val>Quality Systems &amp; Solutions</_0:val>
   </_0:field>
   <_0:field column="TaxID">
    <_0:val>830.085.359-4</_0:val>
   </_0:field>
   <_0:field column="IsVendor">
    <_0:val>Y</_0:val>
   </_0:field>
   <_0:field column="IsCustomer">
    <_0:val>N</_0:val>
   </_0:field>
   <_0:field column="IsTaxExempt">
    <_0:val>N</_0:val>
   </_0:field>
   <_0:field column="Name2">
    <_0:val>QSS Ltda. - http://www.globalqss.com</_0:val>
   </_0:field>
   <_0:field column="C_BP_Group_ID">
    <_0:val>104</_0:val>
   </_0:field>
  </_0:DataRow>
 </_0:ModelCRUD>
 <_0:ADLoginRequest>
  <_0:user>WebService</_0:user>
  <_0:pass>WebService</_0:pass>
  <_0:lang>en_US</_0:lang>
  <_0:ClientID>11</_0:ClientID>
  <_0:RoleID>50004</_0:RoleID>
  <_0:OrgID>11</_0:OrgID>
  <_0:WarehouseID>103</_0:WarehouseID>
  <_0:stage>9</_0:stage>
 </_0:ADLoginRequest>
</_0:ModelCRUDRequest>

4.  Click Submit button to execute the test script.



     Response XML is displayed in the right pane.
   

○ Reference:

1. http://ultra00.hatenablog.com/entry/2013/11/18/114542
2. https://groups.google.com/forum/#!topic/idempiere/82cXxgq_Qh4





2017年1月18日水曜日

[QNAP] Upload to Dropbox by shell script.


 I could upload the files on QNAP NAS to Dropbox by shell script. It is useful to make replica of local backup file in NAS.

○ Environment:

NAS: QNAP TS-531P

○Install Ubuntu LXC on NAS.

 The shell script is executed on Ubuntu LXC. Before creating the shell scrip, Ubuntu LXC should be installed on NAS. 

1. After setting up "Container Station" on NAS, open it.Select Create Container menu.

 2. Click Create button for "Ubuntu LXC".

  3. Set Shared Folder in Advanced Setting.
 

○Get Access Token of Dropbox.

 The Access Token is needed to upload file by shell script. Access Token can be got as the followings. 

  1. Access to https://www.dropbox.com/developers/apps.

  2. Click Create app button.

  3. Choose an API -> Select "Dropbox API" 

      Choose the type of access you need -> Select "Full Dropbox"

      Name your app -> input your App name (ex. QNAP_Uploader)

  4. Click Create app button.

  5. Open App you created, and click Generate button to create a new access token.

      Copy the new access token, which is needed to set up Dropbox-Uploader.


○Install Dropbox-Uploader into Ubuntu LXC on NAS.

 Dropbox-Uploader is  the free shell application to operate Dropbox from shell command line including uploading files. It can work on any Distribution of Linux installed bash and curl.

 Download and execute Dropbox-Uploader.

[root@servername~]# git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
[root@servername~]# cd Dropbox-Uploader/
[root@servername~]# ./dropbox_uploader.sh

 In the first time you execute Dropbox-Uploader, Dropbox-Uploader asks Dropbox access token. Input the access token you created. Next time you execute Dropbox-Uploader, you can operate any command (upload, delete and so on) of it.

 

○Preparing the shell file to upload files into Dropbox.

This shell script works as the followings.

1. The func_upload_files function searches directories and files under {the local root path}/{first arg} recursively.

2. If a files is found, then the files are upload the files into {Dropbox root path}.

  uploadDropbox.sh

#!/bin/sh
DROPBOX_ROOT="Write Dropbox root path to upload files."
ROOT="Write local root path to search the files to upload."
func_upload_files()
{
    BASE_DIR=$ROOT$1/
    DEST_DIR=$DROPBOX_ROOT/$1
    SRC_DIR=`find $BASE_DIR -maxdepth 1 -type d | sort -nr | head -n 1`"/"
    if [ $SRC_DIR != $BASE_DIR ]; then
        /usr/local/Dropbox-Uploader/dropbox_uploader.sh delete $DROPBOX_ROOT$1
        func_search_file $SRC_DIR $DEST_DIR
    fi
}

func_search_file()
{
    for d in `find $1 -maxdepth 1 -type d | sort -nr`; do
        if [ $d != $1 ]; then
            func_search_file $d $2
        fi
    done
    for f in `find $1 -maxdepth 1 -type f | sort -nr`; do
        FILENAME=${f##*$SRC_DIR}
        #echo $DROPBOX_ROOT/$FILENAME
        /usr/local/Dropbox-Uploader/dropbox_uploader.sh upload $f $2/$FILENAME
    done
}
func_upload_files XXXX
func_upload_files YYYY
func_upload_files ZZZZ
...
...
...

○Reference 

1. https://daisukeblog.com/?p=2067