2016年9月1日木曜日

[iDempiere3.1] Alfresco AttachmentProvider Plugin Installation


 iDempiere3.1 has improved a lot from v2.1. Alfresco Attachment Provider Plugin is one of  the improvement, which enable to store attachment file against iDempiere records into Alfresco through CMIS. I was successful to install Alfresco Attachment Provider Plugin by the following steps.

○ Environment:

[iDempiere]
Version: 3.1
Java : openjdk version "1.8.0_102"
         OpenJDK Runtime Environment (build 1.8.0_102-8u102-b14.1-2-b14)
         OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
OS: Jessie(Debian) AMD-64

[Alfresco]
Version: Build 21605 (Alfresco Platform: 5.1.g, Alfresco Share 5.1.f)
Java: java version "1.7.0_111"
        OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-1~deb8u1)
        OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)
OS: Stretch (Debian) AMD-64

2 OSs run on a hypervisor, Citrix  XenServer 6.5.

○Custom Model definition

 Before using this plugin, Custom Model definition must be installed into Alfresco. To install Custom Model definition, XML files must be put into tomcat/shared/classes/alfresco/extension in Alfresco Home directory. But I needed to edit the XML files to make it work.After correcting the XML files like the followings, I just put them into tomcat/shared/classes/alfresco/extension and restart Alfresco.

[iDModel-model-context.xml]  (File name must be *-context.xml, or it cannot be loaded by Spring Framework.)
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 
 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <!-- Registration of new models -->
  <bean id="idempiere.dictionaryBootstrap" 
           parent="dictionaryModelBootstrap" 
           depends-on="dictionaryBootstrap">
      <property name="models">
              <list>
                <value>alfresco/extension/iDModel.xml</value>
            </list>
        </property>
    </bean>
</beans>
[iDModel.xml]
<?xml version="1.0" encoding="UTF-8"?>
<!-- iDempiere Content Model -->
<model name="id:contentmodel"
 xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->
   <description>iDempiere Content Model</description>
   <author>kittiu / a42niem</author>
   <version>1.0</version>

   <!-- Imports are required to allow references 
              to definitions in other models -->
   <imports>
          <!-- Import Alfresco Dictionary Definitions -->
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!-- Import Alfresco Content Domain Model Definitions -->
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!-- Introduction of new namespaces defined by this model -->
   <!-- NOTE: The following namespace my.new.model should be changed 
              to reflect your own namespace -->
   <namespaces>
      <namespace uri="idempiere.model" prefix="id"/>
   </namespaces>

   <types>

      <!-- Definition of new Content Type: 
                                 Standard Operating Procedure -->
      <type name="id:attachment">
         <title>iDempiere Attachment</title>
         <parent>cm:content</parent>
         <properties>
            <property name="id:tablename">
               <title>Table Name</title>
               <type>d:text</type> (corrected d:datetime -> d:text)
               <default></default>
            </property>
            <property name="id:recordid">
               <title>Record ID</title>
               <type>d:text</type>
               <default></default>
            </property>
            <property name="id:checksum">
               <title>Checksum</title>
               <type>d:text</type>
               <default></default>
            </property>
         </properties>
       </type>
    </types>

</model>
 I used OpenCMIS Workbench to confirm that new Custom Model are reflected after restarting Alfresco.

1. Connect to "http://server:port/alfresco/api/-default-/public/cmis/versions/1.0/atom"  by admin.
2.  Open "Types" view.
 

 

○iDempiere Storage Provider configuration

1. Login iDempiere as SuperUser and create a new Storage Provider record.


2. Login as ClientAdmin And set the created Storage Provider as storage provider in Client Info tab.

3.  Try on attach the file into any record in iDempiere. Attache files would be stored in iDempiere defined as Storage Provider.

○Alfresco Rule definition

By configuration above only, attached files were stored into Alfresco successfully, but all files are stored into a folder, it must be inconvinient. Alfresco Rule can resolve this problem by moving the files into separated folders depending on table name and record ID.

1. Download the script file prepared. I modified the file as the following for my purpose.
var tablename = tablename = document.properties["id:tablename"];
var recordid = recordid = document.properties["id:recordid"];
var subfolder1 = "";
var subfolder2 = "";
// check 
if (tablename != null)
{
  subfolder0 = space.childByNamePath('documentLibrary');
  if ( subfolder0 == null)
  {
  // Create first leve0 folder (documentLibrary)
   subfolder0 = space.createFolder('documentLibrary');
  }
  subfolder1 = subfolder0.childByNamePath(tablename);
  if ( subfolder1 == null)
  {
  // Create first level folder (tablename)
   subfolder1 = subfolder0.createFolder(tablename);
  }
  // Move itself to new folder
  document.move(subfolder1);
  // Create second level folder (recordid)
  subfolder2 = subfolder1.childByNamePath(recordid); 
  if ( subfolder2 == null)
  {
     subfolder2 = subfolder1.createFolder(recordid);
  }
  // Move itself to new folder
  document.move(subfolder2);
2. Login as admin in Alfresco and upload the script file into Dictionary/Scripts repository from Browser.


2. Set the script as Rule to the target Folder in Alfresco.


3.  When a new file is attached, Table Name folder and Record ID folder are created by Rule script.


○ Problem:

 I notices that the stored files in Alfresco from iDempiere were not indexed. So, they could not be serched by meta data and full-text search. Custom Model should've had index definition..

 

○ Reference:

1. http://wiki.idempiere.org/en/Plugin:_Alfresco_AttachmentProvider






0 件のコメント:

コメントを投稿