Import and Export of Alfresco ACP Files in Share 5.x
Alfresco Content Package (ACP) files provide an efficient way to snapshot part of the Alfresco repository tree and then later recreate that snapshot of the tree in another part of the repository or in a totally different Alfresco repository. It's a quick way to replicate and move the content, metadata and folder structure created in one repository into another one. For relatively low volumes of data, ACP files are also a good way to import data into Alfresco from other systems. ACP files are also a good way to bootstrap data that might be needed as part of an extension or customization included in an Alfresco module.
In the 3.x and 4.x versions of Alfresco, the ability to import and export ACP files was available from the user interface of the Alfresco Explorer client. But starting in version 5.x, the Explorer client is no longer available and, unfortunately, the ability to import and export ACP files is not available from the standard Alfresco Share UI. (Although this is a feature that is available within the Alfresco Records Management Share extension).
An ACP file consists of an XML file and a directory that contains the flat list of files for the exported content. Note that the files exported into the ACP are renamed to avoid any naming conflicts with the original content file names. The XML file represents the complete description of the exported folder hierarchy and the metadata of the folders and documents. References in the XML identify and match metadata with the files stored in the exported folder of content.
Alfresco does provide an easy way to programmatically export and import ACP files. 'Import' and 'Export' are Alfresco repository actions that can be accessed from server side Javascript code. For example, you can easily write a rule in Javascript that can call either the import or export actions.
First, let's look at the Javascript code needed to create a simple export. In this example, the entire contents of the document library for the default Alfresco Share site called Sample: Web Site Design Project is exported to an ACP file called ACPexport.acp. The path to the area being exported from the Alfresco root directory is /companyhome/Sites/swsdp/documentLibrary. The ACP file is written to the top of the repository (companyhome).
Now, as a simple example to import this ACP file, let's create a new site called swsdp2.The target location that the previously exported ACP file will be imported into is the document library of this new site.
After running this script, we get a copy of all of the content that was exported into the ACP file: the folders, documents and metadata that were in the original site.
This Javascript code can be run in the Javascript console, as part of a webscript, or as a rule associated with a folder.
In the 3.x and 4.x versions of Alfresco, the ability to import and export ACP files was available from the user interface of the Alfresco Explorer client. But starting in version 5.x, the Explorer client is no longer available and, unfortunately, the ability to import and export ACP files is not available from the standard Alfresco Share UI. (Although this is a feature that is available within the Alfresco Records Management Share extension).
An ACP file consists of an XML file and a directory that contains the flat list of files for the exported content. Note that the files exported into the ACP are renamed to avoid any naming conflicts with the original content file names. The XML file represents the complete description of the exported folder hierarchy and the metadata of the folders and documents. References in the XML identify and match metadata with the files stored in the exported folder of content.
Alfresco does provide an easy way to programmatically export and import ACP files. 'Import' and 'Export' are Alfresco repository actions that can be accessed from server side Javascript code. For example, you can easily write a rule in Javascript that can call either the import or export actions.
First, let's look at the Javascript code needed to create a simple export. In this example, the entire contents of the document library for the default Alfresco Share site called Sample: Web Site Design Project is exported to an ACP file called ACPexport.acp. The path to the area being exported from the Alfresco root directory is /companyhome/Sites/swsdp/documentLibrary. The ACP file is written to the top of the repository (companyhome).
// Export ACP
var nodeToExport = companyhome.childByNamePath("Sites/swsdp/documentLibrary")
var exportAction= actions.create("export");
exportAction.parameters['store'] = "workspace://SpacesStore";
exportAction.parameters['package-name'] = "ACPexport";
exportAction.parameters['destination'] = companyhome;
exportAction.parameters['include-children'] = true;
exportAction.parameters['include-self'] = false;
exportAction.parameters['encoding'] = "UTF-8";
exportAction.execute(nodeToExport);
Now, as a simple example to import this ACP file, let's create a new site called swsdp2.The target location that the previously exported ACP file will be imported into is the document library of this new site.
// Import ACP
var targetNodeForImport = companyhome.childByNamePath("Sites/swsdp2/documentLibrary");
var ACPFile = companyhome.childByNamePath("ACPexport.acp");
var importAction = actions.create("import");
importAction.parameters.encoding = "UTF-8";
importAction.parameters.destination = targetNodeForImport;
importAction.execute(ACPFile);
After running this script, we get a copy of all of the content that was exported into the ACP file: the folders, documents and metadata that were in the original site.
This Javascript code can be run in the Javascript console, as part of a webscript, or as a rule associated with a folder.
0 Response to "Import and Export of Alfresco ACP Files in Share 5.x"
Posting Komentar